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. |
| 151 | 151 | Mark the currently focused room as a direct message. |
| 152 | 152 | .It Sy ":room dm unset" |
| 153 | 153 | Mark the currently focused room as a normal room. |
| 154 | .It Sy ":room unread set" |
| 155 | Mark the currently focused room as unread. |
| 156 | .It Sy ":room unread unset" |
| 157 | Mark the currently focused room as read. |
| 158 | .It Sy ":room unread clear" |
| 159 | Alias for |
| 160 | .Sy :room unread unset . |
| 154 | 161 | .It Sy ":room notify set [level]" |
| 155 | 162 | Set a notification level for the currently focused room. |
| 156 | 163 | Valid levels are |
src/base.rs
+11 −3
| @@ -467,6 +467,9 @@ pub enum RoomAction { |
| 467 | 467 | |
| 468 | 468 | /// List the values in a list room property. |
| 469 | 469 | Show(RoomField), |
| 470 | |
| 471 | /// Mark the room as read/unread. |
| 472 | SetUnread(bool), |
| 470 | 473 | } |
| 471 | 474 | |
| 472 | 475 | /// An action that sends a message to a room. |
| @@ -1277,7 +1280,9 @@ impl RoomInfo { |
| 1277 | 1280 | } |
| 1278 | 1281 | |
| 1279 | 1282 | /// 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 | |
| 1281 | 1286 | let last_message = self.messages.last_key_value(); |
| 1282 | 1287 | |
| 1283 | 1288 | let last_receipt = self |
| @@ -1310,14 +1315,17 @@ impl RoomInfo { |
| 1310 | 1315 | |
| 1311 | 1316 | match (last_message, last_receipt) { |
| 1312 | 1317 | (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 | } |
| 1314 | 1322 | }, |
| 1315 | 1323 | (Some(((ts, _), _)), None) => { |
| 1316 | 1324 | // If we've never loaded/generated a room's receipt (example, |
| 1317 | 1325 | // a newly joined but never viewed room), show it as unread. |
| 1318 | 1326 | UnreadInfo { unread: true, latest: Some(*ts) } |
| 1319 | 1327 | }, |
| 1320 | | (None, _) => UnreadInfo::default(), |
| 1328 | (None, _) => UnreadInfo { unread: marked_unread, latest: None }, |
| 1321 | 1329 | } |
| 1322 | 1330 | } |
| 1323 | 1331 | |
src/commands.rs
+6
| @@ -562,6 +562,12 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 562 | 562 | ("id", "show", None) => RoomAction::Show(RoomField::Id).into(), |
| 563 | 563 | ("id", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| 564 | 564 | |
| 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 | |
| 565 | 571 | _ => return Result::Err(CommandError::InvalidArgument), |
| 566 | 572 | }; |
| 567 | 573 | |
src/windows/mod.rs
+3 −3
| @@ -911,7 +911,7 @@ impl GenericChatItem { |
| 911 | 911 | let info = store.application.rooms.get_or_default(room_id.to_owned()); |
| 912 | 912 | let name = info.name.clone().unwrap_or_default(); |
| 913 | 913 | let alias = room.canonical_alias(); |
| 914 | | let unread = info.unreads(&store.application.settings); |
| 914 | let unread = info.unreads(room, &store.application.settings); |
| 915 | 915 | info.tags.clone_from(&room_info.deref().1); |
| 916 | 916 | |
| 917 | 917 | if let Some(alias) = &alias { |
| @@ -1030,7 +1030,7 @@ impl RoomItem { |
| 1030 | 1030 | let info = store.application.rooms.get_or_default(room_id.to_owned()); |
| 1031 | 1031 | let name = info.name.clone().unwrap_or_default(); |
| 1032 | 1032 | let alias = room.canonical_alias(); |
| 1033 | | let unread = info.unreads(&store.application.settings); |
| 1033 | let unread = info.unreads(room, &store.application.settings); |
| 1034 | 1034 | info.tags.clone_from(&room_info.deref().1); |
| 1035 | 1035 | |
| 1036 | 1036 | if let Some(alias) = &alias { |
| @@ -1143,7 +1143,7 @@ impl DirectItem { |
| 1143 | 1143 | |
| 1144 | 1144 | let info = store.application.rooms.get_or_default(room_id); |
| 1145 | 1145 | 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); |
| 1147 | 1147 | info.tags.clone_from(&room_info.deref().1); |
| 1148 | 1148 | |
| 1149 | 1149 | DirectItem { room_info, name, alias, unread } |
src/windows/room/mod.rs
+23
| @@ -218,6 +218,29 @@ pub async fn room_command( |
| 218 | 218 | |
| 219 | 219 | Ok(vec![]) |
| 220 | 220 | }, |
| 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 | }, |
| 221 | 244 | RoomAction::Set(field, value) => { |
| 222 | 245 | let room = store |
| 223 | 246 | .application |
src/worker.rs
+6
| @@ -511,6 +511,12 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { |
| 511 | 511 | continue; |
| 512 | 512 | }; |
| 513 | 513 | |
| 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 | |
| 514 | 520 | match room |
| 515 | 521 | .send_single_receipt(ReceiptType::Read, thread.to_owned(), new_receipt.clone()) |
| 516 | 522 | .await |