[fractal] fractal-gtk: Wire up message replacements
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] fractal-gtk: Wire up message replacements
- Date: Fri, 3 Jul 2020 06:53:46 +0000 (UTC)
commit 3f46aa69c69f4e37aa399a78bf7a80641d606c91
Author: Juraj Fiala <jurf riseup net>
Date: Mon Jun 29 20:24:41 2020 +0200
fractal-gtk: Wire up message replacements
fractal-gtk/src/appop/message.rs | 15 ++++++++++-----
fractal-gtk/src/widgets/room_history.rs | 25 ++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 387fd9cb..e3946cfd 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -375,6 +375,16 @@ impl AppOp {
let login_data = self.login_data.clone()?;
let uid = login_data.uid;
for msg in msgs.iter() {
+ if !msg.redacted && self.active_room.as_ref().map_or(false, |x| x == &msg.room) {
+ self.add_room_message(&msg);
+ msg_in_active = true;
+ }
+
+ if msg.replace != None {
+ /* No need to notify (and confuse the user) about edits. */
+ continue;
+ }
+
let should_notify = msg.sender != uid
&& (msg.body.contains(&login_data.username.clone()?)
|| self.rooms.get(&msg.room).map_or(false, |r| r.direct));
@@ -390,11 +400,6 @@ impl AppOp {
}
}
- if !msg.redacted && self.active_room.as_ref().map_or(false, |x| x == &msg.room) {
- self.add_room_message(&msg);
- msg_in_active = true;
- }
-
self.roomlist.moveup(msg.room.clone());
self.roomlist.set_bold(msg.room.clone(), true);
}
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 5c10d253..b318dd71 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -264,6 +264,7 @@ pub struct RoomHistory {
server_url: Url,
source_id: Rc<RefCell<Option<source::SourceId>>>,
queue: Rc<RefCell<VecDeque<MessageContent>>>,
+ edit_buffer: Rc<RefCell<VecDeque<MessageContent>>>,
}
impl RoomHistory {
@@ -290,6 +291,7 @@ impl RoomHistory {
server_url: op.login_data.clone()?.server_url,
source_id: Rc::new(RefCell::new(None)),
queue: Rc::new(RefCell::new(VecDeque::new())),
+ edit_buffer: Rc::new(RefCell::new(VecDeque::new())),
};
rh.connect_video_auto_play();
@@ -444,6 +446,7 @@ impl RoomHistory {
user_info_cache: Arc<Mutex<CacheMap<UserId, (String, String)>>>,
) -> Option<()> {
let queue = self.queue.clone();
+ let edit_buffer = self.edit_buffer.clone();
let rows = self.rows.clone();
/* TO-DO: we could set the listbox height the 52 * length of messages, to decrease jumps of the
@@ -453,12 +456,28 @@ impl RoomHistory {
if self.source_id.borrow().is_some() {
/* We don't need a new loop, just keeping the old one */
} else {
- /* Lacy load initial messages */
+ /* Lazy load initial messages */
let source_id = self.source_id.clone();
let server_url = self.server_url.clone();
*self.source_id.borrow_mut() = Some(gtk::idle_add(move || {
let mut data = queue.borrow_mut();
+ let mut edits = edit_buffer.borrow_mut();
if let Some(mut item) = data.pop_front() {
+ /* Since we are reading bottom-to-top, we will encounter edit events sooner than
+ * the original messages. */
+ if item.msg.replace.is_some() {
+ if !edits
+ .iter()
+ .any(|edit| item.msg.replace == edit.msg.replace)
+ {
+ edits.push_back(item);
+ }
+ return Continue(true);
+ }
+ if let Some(pos) = edits.iter().position(|edit| item.id == edit.msg.replace) {
+ item = edits.remove(pos).unwrap();
+ }
+
let last = data.front();
let mut prev_day_divider = None;
let mut day_divider = None;
@@ -535,6 +554,10 @@ impl RoomHistory {
user_info_cache: Arc<Mutex<CacheMap<UserId, (String, String)>>>,
mut item: MessageContent,
) -> Option<()> {
+ if item.msg.replace.is_some() {
+ self.replace_message(thread_pool, user_info_cache, item);
+ return None;
+ }
let mut rows = self.rows.borrow_mut();
let mut day_divider = None;
let has_header = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]