[fractal/af/redact.next: 5/5] fractal-gtk: room_history: Set header for new messages



commit 214c00374173afba889953fb1557a09e72003c36
Author: Alistair Francis <alistair alistair23 me>
Date:   Mon Aug 26 21:29:05 2019 -0700

    fractal-gtk: room_history: Set header for new messages
    
    If a user redacts the first message in a group they will cause the
    header to be deleted. This makes it impossible to tell who sent the rest
    of the messages in the group.
    
    Set the header as true for the next message if this is the case.
    
    Signed-off-by: Alistair Francis <alistair alistair23 me>

 fractal-gtk/src/widgets/message.rs      |  2 +-
 fractal-gtk/src/widgets/room_history.rs | 27 +++++++++++++++++++++++++--
 fractal-matrix-api/src/backend/sync.rs  | 10 ++++------
 3 files changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index b1428316..be412909 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -41,7 +41,7 @@ pub struct MessageBox {
     gesture: gtk::GestureLongPress,
     row: gtk::ListBoxRow,
     image: Option<gtk::DrawingArea>,
-    header: bool,
+    pub header: bool,
 }
 
 impl MessageBox {
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 4fcee008..d92b1c4f 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -269,9 +269,13 @@ impl RoomHistory {
 
     pub fn remove_message(&mut self, item: MessageContent) -> Option<()> {
         let mut rows = self.rows.borrow_mut();
+        let mut i: usize = 0;
 
-        let ref mut message = rows.list.iter_mut().find(|e| match e {
-            Element::Message(ref itermessage) => itermessage.id == item.id,
+        let ref mut message = rows.list.iter_mut().by_ref().find(|e| match e {
+            Element::Message(ref itermessage) => {
+                i = i + 1;
+                itermessage.id == item.id
+            }
             _ => false,
         })?;
 
@@ -280,6 +284,25 @@ impl RoomHistory {
                 let msg_widget = msg.widget.clone()?;
                 msg.msg.redacted = true;
                 rows.listbox.remove(msg_widget.get_listbox_row()?);
+
+                if msg_widget.header {
+                    /* If the redacted message was a header message let's set
+                     * the header on the next message instead.
+                     * */
+                    let n = i + 1;
+                    let ref mut message_next = rows.list.iter_mut().nth(n)?;
+                    match message_next {
+                        Element::Message(ref mut msg_next) => {
+                            msg_next.widget = create_row(
+                                msg_next.clone(),
+                                true,
+                                self.backend.clone(),
+                                self.server_url.clone(),
+                            );
+                        }
+                        _ => {}
+                    }
+                }
             }
             _ => {}
         }
diff --git a/fractal-matrix-api/src/backend/sync.rs b/fractal-matrix-api/src/backend/sync.rs
index 5e547aa7..32564381 100644
--- a/fractal-matrix-api/src/backend/sync.rs
+++ b/fractal-matrix-api/src/backend/sync.rs
@@ -230,12 +230,10 @@ pub fn sync(
                                     // This event is managed in the room list
                                 }
                                 "m.room.redaction" => {
-                                    let _ = tx.send(BKResponse::RemoveMessage(
-                                        Ok((
-                                            ev.room.clone(),
-                                            ev.redacts,
-                                        ))
-                                    ));
+                                    let _ = tx.send(BKResponse::RemoveMessage(Ok((
+                                        ev.room.clone(),
+                                        ev.redacts,
+                                    ))));
                                 }
                                 _ => {
                                     error!("EVENT NOT MANAGED: {:?}", ev);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]