From a7c9b58eb807213596035b3101b8aa6692f87629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Thu, 21 Dec 2017 08:20:43 +0100 Subject: [PATCH] Clear tmp messages when abandoning room There was a crash when you send a message and before the tmp message is removed you change the room. When the real message arrive, we were trying to remove the tmp message, but it was not there anymore so it crash. This commit fixes this problem. --- fractal-gtk/src/app.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fractal-gtk/src/app.rs b/fractal-gtk/src/app.rs index 0cdefc9d..af2be3ad 100644 --- a/fractal-gtk/src/app.rs +++ b/fractal-gtk/src/app.rs @@ -159,6 +159,7 @@ impl AppOp { if let AppState::Chat = self.state { self.room_panel(RoomPanel::NoRoom); self.active_room = None; + self.clear_tmp_msgs(); } } @@ -537,6 +538,7 @@ impl AppOp { self.set_state(AppState::Chat); self.room_panel(RoomPanel::NoRoom); self.active_room = None; + self.clear_tmp_msgs(); } self.cache_rooms(); @@ -576,6 +578,7 @@ impl AppOp { pub fn set_active_room(&mut self, room: &Room) { self.active_room = Some(room.id.clone()); + self.clear_tmp_msgs(); self.autoscroll = true; self.remove_messages(); @@ -809,6 +812,16 @@ impl AppOp { }; } + pub fn clear_tmp_msgs(&mut self) { + let messages = self.gtk_builder + .get_object::("message_list") + .expect("Can't find message_list in ui file."); + for t in self.tmp_msgs.iter() { + messages.remove(&t.widget); + } + self.tmp_msgs.clear(); + } + pub fn remove_tmp_room_message(&mut self, msg: &Message) { let messages = self.gtk_builder .get_object::("message_list") @@ -1155,6 +1168,7 @@ impl AppOp { self.backend.send(BKCommand::LeaveRoom(r.clone())).unwrap(); self.rooms.remove(&r); self.active_room = None; + self.clear_tmp_msgs(); self.room_panel(RoomPanel::NoRoom); let store: gtk::TreeStore = self.gtk_builder