[fractal/clippy-ci: 23/25] Fix crashes when redacting messages
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/clippy-ci: 23/25] Fix crashes when redacting messages
- Date: Fri, 21 Feb 2020 20:12:54 +0000 (UTC)
commit 412a32602bb9bb7a9b82a37a31ea743d22247852
Author: Sonja Heinze <sonjaleaheinze gmail com>
Date: Thu Feb 20 13:44:36 2020 +0100
Fix crashes when redacting messages
Before, when deleting a message, the corresponding widget was removed
from the listbox (field listbox of List), but its corresponding element
was not removed from the VecDeque (field list of List). That lead to having
elements in list whose corresponding widgets were not realized, triggering
a crash when trying to get the relative position of those elements.
This commit fixes that bug.
fractal-gtk/src/widgets/room_history.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index cc27416b..12cbe094 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -28,6 +28,9 @@ use gtk;
use gtk::prelude::*;
struct List {
+ /* With the exception of temporary widgets, only modify the fields list and listbox
+ through the methods add_top(), add_bottom(), and remove_item() to maintain the
+ 1-1 correspondence between them. */
list: VecDeque<Element>,
new_divider_index: Option<usize>,
playing_videos: Vec<(Rc<VideoPlayerWidget>, SignalHandlerId)>,
@@ -66,6 +69,11 @@ impl List {
self.list.push_front(element);
}
+ fn remove_item(&mut self, index: usize, row: >k::ListBoxRow) {
+ self.list.remove(index);
+ self.listbox.remove(row);
+ }
+
fn create_new_message_divider(rows: Rc<RefCell<Self>>) -> widgets::NewMessageDivider {
let rows_weak = Rc::downgrade(&rows);
let remove_divider = move || {
@@ -567,7 +575,7 @@ impl RoomHistory {
let msg_widget = msg.widget.clone()?;
let msg_sender = msg.sender.clone();
msg.msg.redacted = true;
- rows.listbox.remove(msg_widget.get_listbox_row());
+ rows.remove_item(i, msg_widget.get_listbox_row());
// If the redacted message was a header message let's set
// the header on the next non-redacted message instead.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]