[fractal/af/redact.next: 3/3] fractal-gtk: room_history: Set header for new messages
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/af/redact.next: 3/3] fractal-gtk: room_history: Set header for new messages
- Date: Sat, 23 Nov 2019 14:19:12 +0000 (UTC)
commit 8b5f622872274dbe9a07aabab1ab645cc1c6e9ec
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 +++++++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 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(),
+ );
+ }
+ _ => {}
+ }
+ }
}
_ => {}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]