Browse Source

sidebar: Allow to mark a room as unread

fractal-12
Kévin Commaille 10 months ago
parent
commit
655676de7e
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 33
      src/session/model/room/mod.rs
  2. 5
      src/session/view/sidebar/mod.ui
  3. 16
      src/session/view/sidebar/row.rs

33
src/session/model/room/mod.rs

@ -178,6 +178,9 @@ mod imp {
/// If it is not known, it will return `0`.
#[property(get)]
latest_activity: Cell<u64>,
/// Whether this room is marked as unread.
#[property(get)]
is_marked_unread: Cell<bool>,
/// Whether all messages of this room are read.
#[property(get)]
is_read: Cell<bool>,
@ -1160,6 +1163,19 @@ mod imp {
self.obj().notify_latest_activity();
}
/// Update whether this room is marked as unread.
async fn update_is_marked_unread(&self) {
let is_marked_unread = self.matrix_room().is_marked_unread();
if self.is_marked_unread.get() == is_marked_unread {
return;
}
self.is_marked_unread.set(is_marked_unread);
self.handle_read_change_trigger().await;
self.obj().notify_is_marked_unread();
}
/// Set whether all messages of this room are read.
fn set_is_read(&self, is_read: bool) {
if self.is_read.get() == is_read {
@ -1174,7 +1190,9 @@ mod imp {
async fn handle_read_change_trigger(&self) {
let timeline = self.live_timeline();
if let Some(has_unread) = timeline.has_unread_messages().await {
if self.is_marked_unread.get() {
self.set_is_read(false);
} else if let Some(has_unread) = timeline.has_unread_messages().await {
self.set_is_read(!has_unread);
}
@ -1458,6 +1476,7 @@ mod imp {
self.update_topic();
self.update_category().await;
self.update_is_direct().await;
self.update_is_marked_unread().await;
self.update_tombstone();
self.set_joined_members_count(room_info.joined_members_count());
self.update_is_encrypted().await;
@ -1781,6 +1800,8 @@ impl Room {
}
/// Send the given receipt.
///
/// This will also unmark the room as unread.
pub(crate) async fn send_receipt(
&self,
receipt_type: ApiReceiptType,
@ -1813,6 +1834,16 @@ impl Room {
}
}
/// Mark the room as unread.
pub(crate) async fn mark_as_unread(&self) {
let matrix_room = self.matrix_room().clone();
let handle = spawn_tokio!(async move { matrix_room.set_unread_flag(true).await });
if let Err(error) = handle.await.expect("task was not aborted") {
error!("Could not mark room as unread: {error}");
}
}
/// Send a typing notification for this room, with the given typing state.
pub(crate) fn send_typing_notification(&self, is_typing: bool) {
let matrix_room = self.matrix_room();

5
src/session/view/sidebar/mod.ui

@ -45,6 +45,11 @@
<attribute name="action">room-row.mark-as-read</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Mark as Unread</attribute>
<attribute name="action">room-row.mark-as-unread</attribute>
<attribute name="hidden-when">action-missing</attribute>
</item>
</section>
<section>
<item>

16
src/session/view/sidebar/row.rs

@ -414,7 +414,21 @@ mod imp {
))
.build()]);
if !room.is_read() {
if room.is_read() {
action_group.add_action_entries([gio::ActionEntry::builder(
"mark-as-unread",
)
.activate(clone!(
#[weak]
room,
move |_, _, _| {
spawn!(async move {
room.mark_as_unread().await;
});
}
))
.build()]);
} else {
action_group.add_action_entries([gio::ActionEntry::builder(
"mark-as-read",
)

Loading…
Cancel
Save