Commit 7afd68c6b2

7afd68c6b2dcfcb47e79a4b767beefc1242bb2a9

parent: 061a16b03c

Unregistered key

vaw <git@nlih.de> · 2026-08-15 04:43 UTC
committer: <noreply@github.com>

Add `:mentions` window and hopefully finally fix unreads (#579)

Layout: unified · split

docs/iamb.1 +2
@@ -65,6 +65,8 @@ View a list of joined spaces.
65View a list of unread rooms. 65View a list of unread rooms.
66.It Sy ":unreads clear" 66.It Sy ":unreads clear"
67Mark all rooms as read. 67Mark all rooms as read.
68.It Sy ":mentions"
69View a list of rooms with mentions of the current user.
68.It Sy ":welcome" 70.It Sy ":welcome"
69View the startup Welcome window. 71View the startup Welcome window.
70.It Sy ":forget" 72.It Sy ":forget"
docs/iamb.5 +1 −1
@@ -223,7 +223,7 @@ Defines whether or not reactions should be shown.
223.It Sy reaction_shortcode_display 223.It Sy reaction_shortcode_display
224Defines whether or not reactions should be shown as their respective shortcode. 224Defines whether or not reactions should be shown as their respective shortcode.
225.It Sy read_receipt_send 225.It Sy read_receipt_send
226Defines whether or not read confirmations are sent. 226Defines whether or not public read confirmations are sent.
227.It Sy read_receipt_display 227.It Sy read_receipt_display
228Defines whether or not read confirmations are displayed. 228Defines whether or not read confirmations are displayed.
229.It Sy request_timeout 229.It Sy request_timeout
src/base.rs +66 −63
@@ -869,13 +869,19 @@ impl EventLocation {
869 869
870#[derive(Clone, Debug, Default, Eq, PartialEq)] 870#[derive(Clone, Debug, Default, Eq, PartialEq)]
871pub struct UnreadInfo { 871pub struct UnreadInfo {
872 pub(crate) unread: bool, 872 pub(crate) unread_messages: u64,
873 pub(crate) unread_notifications: u64,
874 pub(crate) unread_mentions: u64,
873 pub(crate) latest: Option<MessageTimeStamp>, 875 pub(crate) latest: Option<MessageTimeStamp>,
874} 876}
875 877
876impl UnreadInfo { 878impl UnreadInfo {
877 pub fn is_unread(&self) -> bool { 879 pub fn is_unread(&self) -> bool {
878 self.unread 880 self.unread_notifications > 0 || self.unread_mentions > 0
881 }
882
883 pub fn has_mention(&self) -> bool {
884 self.unread_mentions > 0
879 } 885 }
880 886
881 pub fn latest(&self) -> Option<&MessageTimeStamp> { 887 pub fn latest(&self) -> Option<&MessageTimeStamp> {
@@ -1271,52 +1277,18 @@ impl RoomInfo {
1271 } 1277 }
1272 1278
1273 /// Indicates whether this room has unread messages. 1279 /// Indicates whether this room has unread messages.
1274 pub fn unreads(&self, room: &MatrixRoom, settings: &ApplicationSettings) -> UnreadInfo { 1280 pub fn unreads(&self, room: &matrix_sdk::Room) -> UnreadInfo {
1275 let marked_unread = room.is_marked_unread(); 1281 let last_message = self
1276 1282 .messages
1277 let last_message = self.messages.last_key_value(); 1283 .iter()
1278 1284 .rev()
1279 let last_receipt = self 1285 .find(|(_, msg)| !matches!(&msg.event, MessageEvent::State(..)));
1280 .user_receipts 1286
1281 .get(&ReceiptThread::Main) 1287 UnreadInfo {
1282 .and_then(|receipts| receipts.get(&settings.profile.user_id)); 1288 unread_messages: room.num_unread_messages(),
1283 let last_receipt = last_receipt.as_ref().and_then(|event_id| { 1289 unread_notifications: room.num_unread_notifications(),
1284 match &self.keys.get(*event_id)? { 1290 unread_mentions: room.num_unread_mentions(),
1285 EventLocation::Message(_, key) | 1291 latest: last_message.map(|((ts, _), _)| ts.to_owned()),
1286 EventLocation::State(key) |
1287 EventLocation::Sticker(key) => Some(key),
1288 EventLocation::Reaction(_) => None,
1289 }
1290 });
1291
1292 let last_unthreaded = self
1293 .user_receipts
1294 .get(&ReceiptThread::Unthreaded)
1295 .and_then(|receipts| receipts.get(&settings.profile.user_id));
1296 let last_unthreaded = last_unthreaded.as_ref().and_then(|event_id| {
1297 match &self.keys.get(*event_id)? {
1298 EventLocation::Message(_, key) |
1299 EventLocation::State(key) |
1300 EventLocation::Sticker(key) => Some(key),
1301 EventLocation::Reaction(_) => None,
1302 }
1303 });
1304
1305 let last_receipt = std::cmp::max(last_receipt, last_unthreaded);
1306
1307 match (last_message, last_receipt) {
1308 (Some(((ts, _), _)), Some((read_ts, _))) => {
1309 UnreadInfo {
1310 unread: marked_unread | (ts > read_ts),
1311 latest: Some(*ts),
1312 }
1313 },
1314 (Some(((ts, _), _)), None) => {
1315 // If we've never loaded/generated a room's receipt (example,
1316 // a newly joined but never viewed room), show it as unread.
1317 UnreadInfo { unread: true, latest: Some(*ts) }
1318 },
1319 (None, _) => UnreadInfo { unread: marked_unread, latest: None },
1320 } 1292 }
1321 } 1293 }
1322 1294
@@ -1432,27 +1404,42 @@ impl RoomInfo {
1432 self.user_receipts.entry(thread).or_default().insert(user_id, event_id); 1404 self.user_receipts.entry(thread).or_default().insert(user_id, event_id);
1433 } 1405 }
1434 1406
1435 pub fn fully_read(&mut self, user_id: &UserId) { 1407 pub fn fully_read(&mut self, user_id: OwnedUserId, thread: ReceiptThread) {
1436 let Some(((_, event_id), _)) = self.messages.last_key_value() else { 1408 let Some(messages) = (match &thread {
1409 ReceiptThread::Main => self.get_thread(None),
1410 ReceiptThread::Thread(root) => self.get_thread(Some(root)),
1411 _ => None,
1412 }) else {
1437 return; 1413 return;
1438 }; 1414 };
1439 1415
1440 self.set_receipt(ReceiptThread::Main, user_id.to_owned(), event_id.clone()); 1416 let event_id = messages
1441
1442 let newest = self
1443 .threads
1444 .iter() 1417 .iter()
1445 .filter_map(|(thread_id, messages)| { 1418 .filter(|(_, msg)| msg.sender != user_id)
1446 let thread = ReceiptThread::Thread(thread_id.to_owned()); 1419 .filter(|(_, msg)| {
1447 1420 matches!(
1448 messages 1421 msg.event,
1449 .last_key_value() 1422 MessageEvent::EncryptedOriginal(..) |
1450 .map(|((_, event_id), _)| (thread, event_id.to_owned())) 1423 MessageEvent::EncryptedRedacted(..) |
1424 MessageEvent::Original(..) |
1425 MessageEvent::Redacted(..)
1426 )
1451 }) 1427 })
1452 .collect::<Vec<_>>(); 1428 .map(|(_, msg)| msg.event.event_id().to_owned())
1429 .next_back();
1430
1431 if let Some(event_id) = event_id {
1432 self.set_receipt(thread, user_id, event_id);
1433 }
1434 }
1435
1436 pub fn fully_read_all(&mut self, user_id: &UserId) {
1437 self.fully_read(user_id.to_owned(), ReceiptThread::Main);
1438
1439 let threads: Vec<_> = self.threads.keys().map(|root| root.to_owned()).collect();
1453 1440
1454 for (thread, event_id) in newest.into_iter() { 1441 for thread in threads {
1455 self.set_receipt(thread, user_id.to_owned(), event_id.clone()); 1442 self.fully_read(user_id.to_owned(), ReceiptThread::Thread(thread));
1456 } 1443 }
1457 } 1444 }
1458 1445
@@ -1845,6 +1832,9 @@ pub enum IambId {
1845 1832
1846 /// The `:unreads` window. 1833 /// The `:unreads` window.
1847 UnreadList, 1834 UnreadList,
1835
1836 /// The `:mentions` window.
1837 MentionsList,
1848} 1838}
1849 1839
1850impl Display for IambId { 1840impl Display for IambId {
@@ -1866,6 +1856,7 @@ impl Display for IambId {
1866 IambId::Welcome => f.write_str("iamb://welcome"), 1856 IambId::Welcome => f.write_str("iamb://welcome"),
1867 IambId::ChatList => f.write_str("iamb://chats"), 1857 IambId::ChatList => f.write_str("iamb://chats"),
1868 IambId::UnreadList => f.write_str("iamb://unreads"), 1858 IambId::UnreadList => f.write_str("iamb://unreads"),
1859 IambId::MentionsList => f.write_str("iamb://mentions"),
1869 } 1860 }
1870 } 1861 }
1871} 1862}
@@ -2004,6 +1995,13 @@ impl Visitor<'_> for IambIdVisitor {
2004 1995
2005 Ok(IambId::UnreadList) 1996 Ok(IambId::UnreadList)
2006 }, 1997 },
1998 Some("mentions") => {
1999 if url.path() != "" {
2000 return Err(E::custom("iamb://mentions takes no path"));
2001 }
2002
2003 Ok(IambId::MentionsList)
2004 },
2007 Some(s) => Err(E::custom(format!("{s:?} is not a valid window"))), 2005 Some(s) => Err(E::custom(format!("{s:?} is not a valid window"))),
2008 None => Err(E::custom("Invalid iamb window URL")), 2006 None => Err(E::custom("Invalid iamb window URL")),
2009 } 2007 }
@@ -2074,6 +2072,9 @@ pub enum IambBufferId {
2074 2072
2075 /// The `:unreads` window. 2073 /// The `:unreads` window.
2076 UnreadList, 2074 UnreadList,
2075
2076 /// The `:mentions` window.
2077 MentionsList,
2077} 2078}
2078 2079
2079impl IambBufferId { 2080impl IambBufferId {
@@ -2090,6 +2091,7 @@ impl IambBufferId {
2090 IambBufferId::Welcome => IambId::Welcome, 2091 IambBufferId::Welcome => IambId::Welcome,
2091 IambBufferId::ChatList => IambId::ChatList, 2092 IambBufferId::ChatList => IambId::ChatList,
2092 IambBufferId::UnreadList => IambId::UnreadList, 2093 IambBufferId::UnreadList => IambId::UnreadList,
2094 IambBufferId::MentionsList => IambId::MentionsList,
2093 }; 2095 };
2094 2096
2095 Some(id) 2097 Some(id)
@@ -2134,6 +2136,7 @@ impl Completer<IambInfo> for IambCompleter {
2134 IambBufferId::Welcome => vec![], 2136 IambBufferId::Welcome => vec![],
2135 IambBufferId::ChatList => vec![], 2137 IambBufferId::ChatList => vec![],
2136 IambBufferId::UnreadList => vec![], 2138 IambBufferId::UnreadList => vec![],
2139 IambBufferId::MentionsList => vec![],
2137 } 2140 }
2138 } 2141 }
2139} 2142}
src/commands.rs +16
@@ -354,6 +354,17 @@ fn iamb_unreads(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
354 } 354 }
355} 355}
356 356
357fn iamb_mentions(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
358 if !desc.arg.text.is_empty() {
359 return Result::Err(CommandError::InvalidArgument);
360 }
361
362 let open = ctx.switch(OpenTarget::Application(IambId::MentionsList));
363 let step = CommandStep::Continue(open, ctx.context.clone());
364
365 return Ok(step);
366}
367
357fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 368fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
358 if !desc.arg.text.is_empty() { 369 if !desc.arg.text.is_empty() {
359 return Result::Err(CommandError::InvalidArgument); 370 return Result::Err(CommandError::InvalidArgument);
@@ -810,6 +821,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
810 aliases: vec![], 821 aliases: vec![],
811 f: iamb_unreads, 822 f: iamb_unreads,
812 }); 823 });
824 cmds.add_command(ProgramCommand {
825 name: "mentions".into(),
826 aliases: vec![],
827 f: iamb_mentions,
828 });
813 cmds.add_command(ProgramCommand { 829 cmds.add_command(ProgramCommand {
814 name: "unreact".into(), 830 name: "unreact".into(),
815 aliases: vec![], 831 aliases: vec![],
src/main.rs +1 −1
@@ -569,7 +569,7 @@ impl Application {
569 569
570 for room_id in store.application.sync_info.chats() { 570 for room_id in store.application.sync_info.chats() {
571 if let Some(room) = store.application.rooms.get_mut(room_id) { 571 if let Some(room) = store.application.rooms.get_mut(room_id) {
572 room.fully_read(user_id); 572 room.fully_read_all(user_id);
573 } 573 }
574 } 574 }
575 575
src/windows/mod.rs +85 −19
@@ -125,19 +125,27 @@ fn selected_text(s: &str, selected: bool) -> Text<'_> {
125 Text::from(selected_span(s, selected)) 125 Text::from(selected_span(s, selected))
126} 126}
127 127
128fn name_and_labels(name: &str, unread: bool, style: Style) -> (Span<'_>, Vec<Vec<Span<'_>>>) { 128fn name_and_labels<'a>(
129 let name_style = if unread { 129 name: &'a str,
130 unread: &UnreadInfo,
131 style: Style,
132) -> (Span<'a>, Vec<Vec<Span<'static>>>) {
133 // TODO: use different colors for "mention", "notification", "muted room"
134 let name_style = if unread.is_unread() {
130 style.add_modifier(StyleModifier::BOLD) 135 style.add_modifier(StyleModifier::BOLD)
131 } else { 136 } else {
132 style 137 style
133 }; 138 };
134 139
135 let name = Span::styled(name, name_style); 140 let name = Span::styled(name, name_style);
136 let labels = if unread { 141
137 vec![vec![Span::styled("Unread", style)]] 142 let mut labels = vec![];
138 } else { 143
139 vec![] 144 if unread.unread_mentions > 0 {
140 }; 145 labels.push(vec![Span::styled("Unread Mention", style)]);
146 } else if unread.unread_notifications > 0 || unread.unread_messages > 0 {
147 labels.push(vec![Span::styled("Unread", style)]);
148 }
141 149
142 (name, labels) 150 (name, labels)
143} 151}
@@ -330,6 +338,7 @@ macro_rules! delegate {
330 IambWindow::Welcome($id) => $e, 338 IambWindow::Welcome($id) => $e,
331 IambWindow::ChatList($id) => $e, 339 IambWindow::ChatList($id) => $e,
332 IambWindow::UnreadList($id) => $e, 340 IambWindow::UnreadList($id) => $e,
341 IambWindow::MentionsList($id) => $e,
333 } 342 }
334 }; 343 };
335} 344}
@@ -344,6 +353,7 @@ pub enum IambWindow {
344 Welcome(WelcomeState), 353 Welcome(WelcomeState),
345 ChatList(ChatListState), 354 ChatList(ChatListState),
346 UnreadList(UnreadListState), 355 UnreadList(UnreadListState),
356 MentionsList(MentionsListState),
347} 357}
348 358
349impl IambWindow { 359impl IambWindow {
@@ -427,6 +437,7 @@ pub type MemberListState = ListState<MemberItem, IambInfo>;
427pub type RoomListState = ListState<RoomItem, IambInfo>; 437pub type RoomListState = ListState<RoomItem, IambInfo>;
428pub type ChatListState = ListState<GenericChatItem, IambInfo>; 438pub type ChatListState = ListState<GenericChatItem, IambInfo>;
429pub type UnreadListState = ListState<GenericChatItem, IambInfo>; 439pub type UnreadListState = ListState<GenericChatItem, IambInfo>;
440pub type MentionsListState = ListState<GenericChatItem, IambInfo>;
430pub type SpaceListState = ListState<SpaceItem, IambInfo>; 441pub type SpaceListState = ListState<SpaceItem, IambInfo>;
431pub type VerifyListState = ListState<VerifyItem, IambInfo>; 442pub type VerifyListState = ListState<VerifyItem, IambInfo>;
432 443
@@ -660,6 +671,40 @@ impl WindowOps<IambInfo> for IambWindow {
660 .focus(focused) 671 .focus(focused)
661 .render(area, buf, state); 672 .render(area, buf, state);
662 }, 673 },
674 IambWindow::MentionsList(state) => {
675 let mut items = store
676 .application
677 .sync_info
678 .rooms
679 .clone()
680 .into_iter()
681 .map(|room_info| GenericChatItem::new(room_info, store, false))
682 .filter(GenericChatItem::has_mention)
683 .collect::<Vec<_>>();
684
685 let dms = store
686 .application
687 .sync_info
688 .dms
689 .clone()
690 .into_iter()
691 .map(|room_info| GenericChatItem::new(room_info, store, true))
692 .filter(GenericChatItem::has_mention);
693
694 items.extend(dms);
695
696 let fields = &store.application.settings.tunables.sort.chats;
697 let collator = &mut store.application.collator;
698 items.sort_by(|a, b| room_fields_cmp(a, b, fields, collator));
699
700 state.set(items);
701
702 List::new(store)
703 .empty_message("You do not have any unread mentions yet")
704 .empty_alignment(Alignment::Center)
705 .focus(focused)
706 .render(area, buf, state);
707 },
663 IambWindow::SpaceList(state) => { 708 IambWindow::SpaceList(state) => {
664 let mut items = store 709 let mut items = store
665 .application 710 .application
@@ -713,6 +758,7 @@ impl WindowOps<IambInfo> for IambWindow {
713 IambWindow::Welcome(w) => w.dup(store).into(), 758 IambWindow::Welcome(w) => w.dup(store).into(),
714 IambWindow::ChatList(w) => w.dup(store).into(), 759 IambWindow::ChatList(w) => w.dup(store).into(),
715 IambWindow::UnreadList(w) => w.dup(store).into(), 760 IambWindow::UnreadList(w) => w.dup(store).into(),
761 IambWindow::MentionsList(w) => w.dup(store).into(),
716 } 762 }
717 } 763 }
718 764
@@ -754,6 +800,7 @@ impl Window<IambInfo> for IambWindow {
754 IambWindow::Welcome(_) => IambId::Welcome, 800 IambWindow::Welcome(_) => IambId::Welcome,
755 IambWindow::ChatList(_) => IambId::ChatList, 801 IambWindow::ChatList(_) => IambId::ChatList,
756 IambWindow::UnreadList(_) => IambId::UnreadList, 802 IambWindow::UnreadList(_) => IambId::UnreadList,
803 IambWindow::MentionsList(_) => IambId::MentionsList,
757 } 804 }
758 } 805 }
759 806
@@ -766,6 +813,7 @@ impl Window<IambInfo> for IambWindow {
766 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), 813 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"),
767 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), 814 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"),
768 IambWindow::UnreadList(_) => bold_spans("Unread Messages"), 815 IambWindow::UnreadList(_) => bold_spans("Unread Messages"),
816 IambWindow::MentionsList(_) => bold_spans("Unread Mentions"),
769 817
770 IambWindow::Room(w) => { 818 IambWindow::Room(w) => {
771 let title = store.application.get_room_title(w.id()); 819 let title = store.application.get_room_title(w.id());
@@ -794,6 +842,7 @@ impl Window<IambInfo> for IambWindow {
794 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), 842 IambWindow::Welcome(_) => bold_spans("Welcome to iamb"),
795 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), 843 IambWindow::ChatList(_) => bold_spans("DMs & Rooms"),
796 IambWindow::UnreadList(_) => bold_spans("Unread Messages"), 844 IambWindow::UnreadList(_) => bold_spans("Unread Messages"),
845 IambWindow::MentionsList(_) => bold_spans("Unread Mentions"),
797 846
798 IambWindow::Room(w) => w.get_title(store), 847 IambWindow::Room(w) => w.get_title(store),
799 IambWindow::MemberList(state, room_id, _) => { 848 IambWindow::MemberList(state, room_id, _) => {
@@ -860,6 +909,11 @@ impl Window<IambInfo> for IambWindow {
860 909
861 Ok(IambWindow::UnreadList(list)) 910 Ok(IambWindow::UnreadList(list))
862 }, 911 },
912 IambId::MentionsList => {
913 let list = MentionsListState::new(IambBufferId::MentionsList, vec![]);
914
915 Ok(IambWindow::MentionsList(list))
916 },
863 } 917 }
864 } 918 }
865 919
@@ -911,7 +965,7 @@ impl GenericChatItem {
911 let info = store.application.rooms.get_or_default(room_id.to_owned()); 965 let info = store.application.rooms.get_or_default(room_id.to_owned());
912 let name = info.name.clone().unwrap_or_default(); 966 let name = info.name.clone().unwrap_or_default();
913 let alias = room.canonical_alias(); 967 let alias = room.canonical_alias();
914 let unread = info.unreads(room, &store.application.settings); 968 let unread = info.unreads(room);
915 info.tags.clone_from(&room_info.deref().1); 969 info.tags.clone_from(&room_info.deref().1);
916 970
917 if let Some(alias) = &alias { 971 if let Some(alias) = &alias {
@@ -930,6 +984,11 @@ impl GenericChatItem {
930 fn tags(&self) -> &Option<Tags> { 984 fn tags(&self) -> &Option<Tags> {
931 &self.room_info.deref().1 985 &self.room_info.deref().1
932 } 986 }
987
988 #[inline]
989 fn has_mention(&self) -> bool {
990 self.unread.has_mention()
991 }
933} 992}
934 993
935impl RoomLikeItem for GenericChatItem { 994impl RoomLikeItem for GenericChatItem {
@@ -979,9 +1038,8 @@ impl ListItem<IambInfo> for GenericChatItem {
979 _: &ViewportContext<ListCursor>, 1038 _: &ViewportContext<ListCursor>,
980 _: &mut ProgramStore, 1039 _: &mut ProgramStore,
981 ) -> Text<'_> { 1040 ) -> Text<'_> {
982 let unread = self.unread.is_unread();
983 let style = selected_style(selected); 1041 let style = selected_style(selected);
984 let (name, mut labels) = name_and_labels(&self.name, unread, style); 1042 let (name, mut labels) = name_and_labels(&self.name, &self.unread, style);
985 let mut spans = vec![name]; 1043 let mut spans = vec![name];
986 1044
987 labels.push(if self.is_dm { 1045 labels.push(if self.is_dm {
@@ -1030,7 +1088,7 @@ impl RoomItem {
1030 let info = store.application.rooms.get_or_default(room_id.to_owned()); 1088 let info = store.application.rooms.get_or_default(room_id.to_owned());
1031 let name = info.name.clone().unwrap_or_default(); 1089 let name = info.name.clone().unwrap_or_default();
1032 let alias = room.canonical_alias(); 1090 let alias = room.canonical_alias();
1033 let unread = info.unreads(room, &store.application.settings); 1091 let unread = info.unreads(room);
1034 info.tags.clone_from(&room_info.deref().1); 1092 info.tags.clone_from(&room_info.deref().1);
1035 1093
1036 if let Some(alias) = &alias { 1094 if let Some(alias) = &alias {
@@ -1098,9 +1156,8 @@ impl ListItem<IambInfo> for RoomItem {
1098 _: &ViewportContext<ListCursor>, 1156 _: &ViewportContext<ListCursor>,
1099 _: &mut ProgramStore, 1157 _: &mut ProgramStore,
1100 ) -> Text<'_> { 1158 ) -> Text<'_> {
1101 let unread = self.unread.is_unread();
1102 let style = selected_style(selected); 1159 let style = selected_style(selected);
1103 let (name, mut labels) = name_and_labels(&self.name, unread, style); 1160 let (name, mut labels) = name_and_labels(&self.name, &self.unread, style);
1104 let mut spans = vec![name]; 1161 let mut spans = vec![name];
1105 1162
1106 if let Some(tags) = &self.tags() { 1163 if let Some(tags) = &self.tags() {
@@ -1138,12 +1195,13 @@ pub struct DirectItem {
1138 1195
1139impl DirectItem { 1196impl DirectItem {
1140 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self { 1197 fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self {
1198 let room = &room_info.deref().0;
1141 let room_id = room_info.0.room_id().to_owned(); 1199 let room_id = room_info.0.room_id().to_owned();
1142 let alias = room_info.0.canonical_alias(); 1200 let alias = room_info.0.canonical_alias();
1143 1201
1144 let info = store.application.rooms.get_or_default(room_id); 1202 let info = store.application.rooms.get_or_default(room_id);
1145 let name = info.name.clone().unwrap_or_default(); 1203 let name = info.name.clone().unwrap_or_default();
1146 let unread = info.unreads(&room_info.0, &store.application.settings); 1204 let unread = info.unreads(room);
1147 info.tags.clone_from(&room_info.deref().1); 1205 info.tags.clone_from(&room_info.deref().1);
1148 1206
1149 DirectItem { room_info, name, alias, unread } 1207 DirectItem { room_info, name, alias, unread }
@@ -1207,9 +1265,8 @@ impl ListItem<IambInfo> for DirectItem {
1207 _: &ViewportContext<ListCursor>, 1265 _: &ViewportContext<ListCursor>,
1208 _: &mut ProgramStore, 1266 _: &mut ProgramStore,
1209 ) -> Text<'_> { 1267 ) -> Text<'_> {
1210 let unread = self.unread.is_unread();
1211 let style = selected_style(selected); 1268 let style = selected_style(selected);
1212 let (name, mut labels) = name_and_labels(&self.name, unread, style); 1269 let (name, mut labels) = name_and_labels(&self.name, &self.unread, style);
1213 let mut spans = vec![name]; 1270 let mut spans = vec![name];
1214 1271
1215 if let Some(tags) = &self.tags() { 1272 if let Some(tags) = &self.tags() {
@@ -1757,7 +1814,12 @@ mod tests {
1757 tags: vec![], 1814 tags: vec![],
1758 alias: None, 1815 alias: None,
1759 name: "Room 1", 1816 name: "Room 1",
1760 unread: UnreadInfo { unread: false, latest: None }, 1817 unread: UnreadInfo {
1818 latest: None,
1819 unread_messages: 0,
1820 unread_notifications: 0,
1821 unread_mentions: 0,
1822 },
1761 invite: false, 1823 invite: false,
1762 }; 1824 };
1763 1825
@@ -1767,8 +1829,10 @@ mod tests {
1767 alias: None, 1829 alias: None,
1768 name: "Room 2", 1830 name: "Room 2",
1769 unread: UnreadInfo { 1831 unread: UnreadInfo {
1770 unread: false,
1771 latest: Some(MessageTimeStamp::OriginServer(40u32.into())), 1832 latest: Some(MessageTimeStamp::OriginServer(40u32.into())),
1833 unread_messages: 0,
1834 unread_notifications: 0,
1835 unread_mentions: 0,
1772 }, 1836 },
1773 invite: false, 1837 invite: false,
1774 }; 1838 };
@@ -1779,8 +1843,10 @@ mod tests {
1779 alias: None, 1843 alias: None,
1780 name: "Room 3", 1844 name: "Room 3",
1781 unread: UnreadInfo { 1845 unread: UnreadInfo {
1782 unread: false,
1783 latest: Some(MessageTimeStamp::OriginServer(20u32.into())), 1846 latest: Some(MessageTimeStamp::OriginServer(20u32.into())),
1847 unread_messages: 0,
1848 unread_notifications: 0,
1849 unread_mentions: 0,
1784 }, 1850 },
1785 invite: false, 1851 invite: false,
1786 }; 1852 };
src/windows/room/scrollback.rs +2 −7
@@ -1455,14 +1455,9 @@ impl StatefulWidget for Scrollback<'_> {
1455 } 1455 }
1456 } 1456 }
1457 1457
1458 if self.room_focused && 1458 if self.room_focused && state.cursor.timestamp.is_none() {
1459 settings.tunables.read_receipt_send &&
1460 state.cursor.timestamp.is_none()
1461 {
1462 // If the cursor is at the last message, then update the read marker. 1459 // If the cursor is at the last message, then update the read marker.
1463 if let Some((k, _)) = thread.last_key_value() { 1460 info.fully_read(settings.profile.user_id.clone(), thread.1.clone());
1464 info.set_receipt(thread.1.clone(), settings.profile.user_id.clone(), k.1.clone());
1465 }
1466 } 1461 }
1467 1462
1468 // Check whether we should load older messages for this room. 1463 // Check whether we should load older messages for this room.
src/worker.rs +14 −4
@@ -461,6 +461,8 @@ async fn refresh_rooms_forever(client: &Client, store: &AsyncProgramStore) {
461} 461}
462 462
463async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { 463async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
464 use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType;
465
464 let mut interval = tokio::time::interval(Duration::from_secs(2)); 466 let mut interval = tokio::time::interval(Duration::from_secs(2));
465 let mut sent: HashMap<OwnedRoomId, HashMap<ReceiptThread, OwnedEventId>> = Default::default(); 467 let mut sent: HashMap<OwnedRoomId, HashMap<ReceiptThread, OwnedEventId>> = Default::default();
466 468
@@ -489,11 +491,15 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
489 491
490 updates.extend(changed); 492 updates.extend(changed);
491 } 493 }
494
495 let receipt_type = if locked.application.settings.tunables.read_receipt_send {
496 ReceiptType::Read
497 } else {
498 ReceiptType::ReadPrivate
499 };
492 drop(locked); 500 drop(locked);
493 501
494 for (room_id, thread, new_receipt) in updates { 502 for (room_id, thread, new_receipt) in updates {
495 use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType;
496
497 let Some(room) = client.get_room(&room_id) else { 503 let Some(room) = client.get_room(&room_id) else {
498 continue; 504 continue;
499 }; 505 };
@@ -505,7 +511,7 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
505 } 511 }
506 512
507 match room 513 match room
508 .send_single_receipt(ReceiptType::Read, thread.to_owned(), new_receipt.clone()) 514 .send_single_receipt(receipt_type.clone(), thread.to_owned(), new_receipt.clone())
509 .await 515 .await
510 { 516 {
511 Ok(()) => { 517 Ok(()) => {
@@ -721,7 +727,11 @@ pub async fn create_client(settings: &ApplicationSettings) -> Client {
721 res => res, 727 res => res,
722 }; 728 };
723 729
724 res.expect("Failed to instantiate client") 730 let client = res.expect("Failed to instantiate client");
731
732 client.event_cache().subscribe().expect("Failed to start event cache");
733
734 client
725} 735}
726 736
727#[derive(Clone)] 737#[derive(Clone)]