Commit 0edb871466

0edb8714661686cc7d58759ec5407447b3162548

parent: 966c5ed6e9

Unregistered key

vaw <git@nlih.de> · 2026-07-29 22:27 UTC
committer: <noreply@github.com>

Support manually marking rooms as unread (#603)

Layout: unified · split

docs/iamb.1 +7
@@ -151,6 +151,13 @@ Unset the name of the currently focused room.
151151Mark the currently focused room as a direct message.
152152.It Sy ":room dm unset"
153153Mark the currently focused room as a normal room.
154.It Sy ":room unread set"
155Mark the currently focused room as unread.
156.It Sy ":room unread unset"
157Mark the currently focused room as read.
158.It Sy ":room unread clear"
159Alias for
160.Sy :room unread unset .
154161.It Sy ":room notify set [level]"
155162Set a notification level for the currently focused room.
156163Valid levels are
src/base.rs +11 −3
@@ -467,6 +467,9 @@ pub enum RoomAction {
467467
468468 /// List the values in a list room property.
469469 Show(RoomField),
470
471 /// Mark the room as read/unread.
472 SetUnread(bool),
470473}
471474
472475/// An action that sends a message to a room.
@@ -1277,7 +1280,9 @@ impl RoomInfo {
12771280 }
12781281
12791282 /// Indicates whether this room has unread messages.
1280 pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo {
1283 pub fn unreads(&self, room: &MatrixRoom, settings: &ApplicationSettings) -> UnreadInfo {
1284 let marked_unread = room.is_marked_unread();
1285
12811286 let last_message = self.messages.last_key_value();
12821287
12831288 let last_receipt = self
@@ -1310,14 +1315,17 @@ impl RoomInfo {
13101315
13111316 match (last_message, last_receipt) {
13121317 (Some(((ts, _), _)), Some((read_ts, _))) => {
1313 UnreadInfo { unread: ts > read_ts, latest: Some(*ts) }
1318 UnreadInfo {
1319 unread: marked_unread | (ts > read_ts),
1320 latest: Some(*ts),
1321 }
13141322 },
13151323 (Some(((ts, _), _)), None) => {
13161324 // If we've never loaded/generated a room's receipt (example,
13171325 // a newly joined but never viewed room), show it as unread.
13181326 UnreadInfo { unread: true, latest: Some(*ts) }
13191327 },
1320 (None, _) => UnreadInfo::default(),
1328 (None, _) => UnreadInfo { unread: marked_unread, latest: None },
13211329 }
13221330 }
13231331
src/commands.rs +6
@@ -562,6 +562,12 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
562562 ("id", "show", None) => RoomAction::Show(RoomField::Id).into(),
563563 ("id", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
564564
565 // :room unread set
566 ("unread", "set", None) => RoomAction::SetUnread(true).into(),
567
568 // :room unread [unset|clear]
569 ("unread", "unset" | "clear", None) => RoomAction::SetUnread(false).into(),
570
565571 _ => return Result::Err(CommandError::InvalidArgument),
566572 };
567573
src/windows/mod.rs +3 −3
@@ -911,7 +911,7 @@ impl GenericChatItem {
911911 let info = store.application.rooms.get_or_default(room_id.to_owned());
912912 let name = info.name.clone().unwrap_or_default();
913913 let alias = room.canonical_alias();
914 let unread = info.unreads(&store.application.settings);
914 let unread = info.unreads(room, &store.application.settings);
915915 info.tags.clone_from(&room_info.deref().1);
916916
917917 if let Some(alias) = &alias {
@@ -1030,7 +1030,7 @@ impl RoomItem {
10301030 let info = store.application.rooms.get_or_default(room_id.to_owned());
10311031 let name = info.name.clone().unwrap_or_default();
10321032 let alias = room.canonical_alias();
1033 let unread = info.unreads(&store.application.settings);
1033 let unread = info.unreads(room, &store.application.settings);
10341034 info.tags.clone_from(&room_info.deref().1);
10351035
10361036 if let Some(alias) = &alias {
@@ -1143,7 +1143,7 @@ impl DirectItem {
11431143
11441144 let info = store.application.rooms.get_or_default(room_id);
11451145 let name = info.name.clone().unwrap_or_default();
1146 let unread = info.unreads(&store.application.settings);
1146 let unread = info.unreads(&room_info.0, &store.application.settings);
11471147 info.tags.clone_from(&room_info.deref().1);
11481148
11491149 DirectItem { room_info, name, alias, unread }
src/windows/room/mod.rs +23
@@ -218,6 +218,29 @@ pub async fn room_command(
218218
219219 Ok(vec![])
220220 },
221 RoomAction::SetUnread(is_unread) => {
222 let room = store
223 .application
224 .get_joined_room(id)
225 .ok_or(UIError::Application(IambError::NotJoined))?;
226
227 room.set_unread_flag(is_unread).await.map_err(IambError::from)?;
228
229 if !is_unread {
230 let user_id = store.application.settings.profile.user_id.clone();
231 let info = store.application.get_room_info(id.to_owned());
232 let messages = info.get_thread(None).expect("room main timeline doesn't exit");
233 if let Some(((_, event_id), _)) = messages.last_key_value() {
234 info.set_receipt(
235 matrix_sdk::ruma::events::receipt::ReceiptThread::Main,
236 user_id,
237 event_id.to_owned(),
238 );
239 }
240 }
241
242 Ok(vec![])
243 },
221244 RoomAction::Set(field, value) => {
222245 let room = store
223246 .application
src/worker.rs +6
@@ -511,6 +511,12 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
511511 continue;
512512 };
513513
514 if ReceiptThread::Main == thread || ReceiptThread::Unthreaded == thread {
515 if let Err(err) = room.set_unread_flag(false).await {
516 tracing::warn!(?room_id, "Failed to clear unread flag: {err}");
517 }
518 }
519
514520 match room
515521 .send_single_receipt(ReceiptType::Read, thread.to_owned(), new_receipt.clone())
516522 .await