[fractal/af/redact.next: 2/5] fractal-gtk: appop: Allow removing a message



commit aae47a5b4edef47585bc1da04eb4c8eb3cb904f9
Author: Alistair Francis <alistair alistair23 me>
Date:   Sun Aug 25 20:33:58 2019 -0700

    fractal-gtk: appop: Allow removing a message
    
    Signed-off-by: Alistair Francis <alistair alistair23 me>

 fractal-gtk/src/appop/message.rs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 119a8af2..21d641b1 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -54,6 +54,15 @@ impl AppOp {
         None
     }
 
+    pub fn remove_room_message(&mut self, msg: &Message) -> Option<()> {
+        if let Some(ui_msg) = self.create_new_room_message(msg) {
+            if let Some(ref mut history) = self.history {
+                history.remove_message(ui_msg);
+            }
+        }
+        None
+    }
+
     pub fn add_tmp_room_message(&mut self, msg: Message) -> Option<()> {
         let messages = self.history.as_ref()?.get_listbox();
         if let Some(ui_msg) = self.create_new_room_message(&msg) {
@@ -406,6 +415,20 @@ impl AppOp {
         }
     }
 
+    pub fn remove_message(&mut self, room: String, id: String) -> Option<()> {
+        let message = self.get_message_by_id(&room, &id);
+
+        if let Some(msg) = message {
+            self.remove_room_message(&msg);
+            if let Some(ref mut room) = self.rooms.get_mut(&msg.room) {
+                if let Some(ref mut message) = room.messages.iter_mut().find(|e| e.id == msg.id) {
+                    message.redacted = true;
+                }
+            }
+        }
+        None
+    }
+
     /* parese a backend Message into a Message for the UI */
     pub fn create_new_room_message(&self, msg: &Message) -> Option<MessageContent> {
         let mut highlights = vec![];


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