Commit 7afd68c6b2
Unregistered key
Layout: unified · split
docs/iamb.1 +2
| @@ -65,6 +65,8 @@ View a list of joined spaces. | ||
| 65 | 65 | View a list of unread rooms. |
| 66 | 66 | .It Sy ":unreads clear" |
| 67 | 67 | Mark all rooms as read. |
| 68 | .It Sy ":mentions" | |
| 69 | View a list of rooms with mentions of the current user. | |
| 68 | 70 | .It Sy ":welcome" |
| 69 | 71 | View the startup Welcome window. |
| 70 | 72 | .It Sy ":forget" |
docs/iamb.5 +1 −1
| @@ -223,7 +223,7 @@ Defines whether or not reactions should be shown. | ||
| 223 | 223 | .It Sy reaction_shortcode_display |
| 224 | 224 | Defines whether or not reactions should be shown as their respective shortcode. |
| 225 | 225 | .It Sy read_receipt_send |
| 226 | Defines whether or not read confirmations are sent. | |
| 226 | Defines whether or not public read confirmations are sent. | |
| 227 | 227 | .It Sy read_receipt_display |
| 228 | 228 | Defines whether or not read confirmations are displayed. |
| 229 | 229 | .It Sy request_timeout |
src/base.rs +66 −63
| @@ -869,13 +869,19 @@ impl EventLocation { | ||
| 869 | 869 | |
| 870 | 870 | #[derive(Clone, Debug, Default, Eq, PartialEq)] |
| 871 | 871 | pub 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 | 875 | pub(crate) latest: Option<MessageTimeStamp>, |
| 874 | 876 | } |
| 875 | 877 | |
| 876 | 878 | impl UnreadInfo { |
| 877 | 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 | 887 | pub fn latest(&self) -> Option<&MessageTimeStamp> { |
| @@ -1271,52 +1277,18 @@ impl RoomInfo { | ||
| 1271 | 1277 | } |
| 1272 | 1278 | |
| 1273 | 1279 | /// Indicates whether this room has unread messages. |
| 1274 | pub fn unreads(&self, room: &MatrixRoom, settings: &ApplicationSettings) -> UnreadInfo { | |
| 1275 | let marked_unread = room.is_marked_unread(); | |
| 1276 | ||
| 1277 | let last_message = self.messages.last_key_value(); | |
| 1278 | ||
| 1279 | let last_receipt = self | |
| 1280 | .user_receipts | |
| 1281 | .get(&ReceiptThread::Main) | |
| 1282 | .and_then(|receipts| receipts.get(&settings.profile.user_id)); | |
| 1283 | let last_receipt = last_receipt.as_ref().and_then(|event_id| { | |
| 1284 | match &self.keys.get(*event_id)? { | |
| 1285 | EventLocation::Message(_, key) | | |
| 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 }, | |
| 1280 | pub fn unreads(&self, room: &matrix_sdk::Room) -> UnreadInfo { | |
| 1281 | let last_message = self | |
| 1282 | .messages | |
| 1283 | .iter() | |
| 1284 | .rev() | |
| 1285 | .find(|(_, msg)| !matches!(&msg.event, MessageEvent::State(..))); | |
| 1286 | ||
| 1287 | UnreadInfo { | |
| 1288 | unread_messages: room.num_unread_messages(), | |
| 1289 | unread_notifications: room.num_unread_notifications(), | |
| 1290 | unread_mentions: room.num_unread_mentions(), | |
| 1291 | latest: last_message.map(|((ts, _), _)| ts.to_owned()), | |
| 1320 | 1292 | } |
| 1321 | 1293 | } |
| 1322 | 1294 | |
| @@ -1432,27 +1404,42 @@ impl RoomInfo { | ||
| 1432 | 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) { | |
| 1436 | let Some(((_, event_id), _)) = self.messages.last_key_value() else { | |
| 1407 | pub fn fully_read(&mut self, user_id: OwnedUserId, thread: ReceiptThread) { | |
| 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 | 1413 | return; |
| 1438 | 1414 | }; |
| 1439 | 1415 | |
| 1440 | self.set_receipt(ReceiptThread::Main, user_id.to_owned(), event_id.clone()); | |
| 1441 | ||
| 1442 | let newest = self | |
| 1443 | .threads | |
| 1416 | let event_id = messages | |
| 1444 | 1417 | .iter() |
| 1445 | .filter_map(|(thread_id, messages)| { | |
| 1446 | let thread = ReceiptThread::Thread(thread_id.to_owned()); | |
| 1447 | ||
| 1448 | messages | |
| 1449 | .last_key_value() | |
| 1450 | .map(|((_, event_id), _)| (thread, event_id.to_owned())) | |
| 1418 | .filter(|(_, msg)| msg.sender != user_id) | |
| 1419 | .filter(|(_, msg)| { | |
| 1420 | matches!( | |
| 1421 | msg.event, | |
| 1422 | MessageEvent::EncryptedOriginal(..) | | |
| 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() { | |
| 1455 | self.set_receipt(thread, user_id.to_owned(), event_id.clone()); | |
| 1441 | for thread in threads { | |
| 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 | 1833 | /// The `:unreads` window. |
| 1847 | 1834 | UnreadList, |
| 1835 | ||
| 1836 | /// The `:mentions` window. | |
| 1837 | MentionsList, | |
| 1848 | 1838 | } |
| 1849 | 1839 | |
| 1850 | 1840 | impl Display for IambId { |
| @@ -1866,6 +1856,7 @@ impl Display for IambId { | ||
| 1866 | 1856 | IambId::Welcome => f.write_str("iamb://welcome"), |
| 1867 | 1857 | IambId::ChatList => f.write_str("iamb://chats"), |
| 1868 | 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 | 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 | 2005 | Some(s) => Err(E::custom(format!("{s:?} is not a valid window"))), |
| 2008 | 2006 | None => Err(E::custom("Invalid iamb window URL")), |
| 2009 | 2007 | } |
| @@ -2074,6 +2072,9 @@ pub enum IambBufferId { | ||
| 2074 | 2072 | |
| 2075 | 2073 | /// The `:unreads` window. |
| 2076 | 2074 | UnreadList, |
| 2075 | ||
| 2076 | /// The `:mentions` window. | |
| 2077 | MentionsList, | |
| 2077 | 2078 | } |
| 2078 | 2079 | |
| 2079 | 2080 | impl IambBufferId { |
| @@ -2090,6 +2091,7 @@ impl IambBufferId { | ||
| 2090 | 2091 | IambBufferId::Welcome => IambId::Welcome, |
| 2091 | 2092 | IambBufferId::ChatList => IambId::ChatList, |
| 2092 | 2093 | IambBufferId::UnreadList => IambId::UnreadList, |
| 2094 | IambBufferId::MentionsList => IambId::MentionsList, | |
| 2093 | 2095 | }; |
| 2094 | 2096 | |
| 2095 | 2097 | Some(id) |
| @@ -2134,6 +2136,7 @@ impl Completer<IambInfo> for IambCompleter { | ||
| 2134 | 2136 | IambBufferId::Welcome => vec![], |
| 2135 | 2137 | IambBufferId::ChatList => vec![], |
| 2136 | 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 | |
| 357 | fn 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 | ||
| 357 | 368 | fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 358 | 369 | if !desc.arg.text.is_empty() { |
| 359 | 370 | return Result::Err(CommandError::InvalidArgument); |
| @@ -810,6 +821,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 810 | 821 | aliases: vec![], |
| 811 | 822 | f: iamb_unreads, |
| 812 | 823 | }); |
| 824 | cmds.add_command(ProgramCommand { | |
| 825 | name: "mentions".into(), | |
| 826 | aliases: vec![], | |
| 827 | f: iamb_mentions, | |
| 828 | }); | |
| 813 | 829 | cmds.add_command(ProgramCommand { |
| 814 | 830 | name: "unreact".into(), |
| 815 | 831 | aliases: vec![], |
src/main.rs +1 −1
| @@ -569,7 +569,7 @@ impl Application { | ||
| 569 | 569 | |
| 570 | 570 | for room_id in store.application.sync_info.chats() { |
| 571 | 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 | 125 | Text::from(selected_span(s, selected)) |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | fn name_and_labels(name: &str, unread: bool, style: Style) -> (Span<'_>, Vec<Vec<Span<'_>>>) { | |
| 129 | let name_style = if unread { | |
| 128 | fn name_and_labels<'a>( | |
| 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 | 135 | style.add_modifier(StyleModifier::BOLD) |
| 131 | 136 | } else { |
| 132 | 137 | style |
| 133 | 138 | }; |
| 134 | 139 | |
| 135 | 140 | let name = Span::styled(name, name_style); |
| 136 | let labels = if unread { | |
| 137 | vec![vec![Span::styled("Unread", style)]] | |
| 138 | } else { | |
| 139 | vec![] | |
| 140 | }; | |
| 141 | ||
| 142 | let mut labels = vec![]; | |
| 143 | ||
| 144 | if unread.unread_mentions > 0 { | |
| 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 | 150 | (name, labels) |
| 143 | 151 | } |
| @@ -330,6 +338,7 @@ macro_rules! delegate { | ||
| 330 | 338 | IambWindow::Welcome($id) => $e, |
| 331 | 339 | IambWindow::ChatList($id) => $e, |
| 332 | 340 | IambWindow::UnreadList($id) => $e, |
| 341 | IambWindow::MentionsList($id) => $e, | |
| 333 | 342 | } |
| 334 | 343 | }; |
| 335 | 344 | } |
| @@ -344,6 +353,7 @@ pub enum IambWindow { | ||
| 344 | 353 | Welcome(WelcomeState), |
| 345 | 354 | ChatList(ChatListState), |
| 346 | 355 | UnreadList(UnreadListState), |
| 356 | MentionsList(MentionsListState), | |
| 347 | 357 | } |
| 348 | 358 | |
| 349 | 359 | impl IambWindow { |
| @@ -427,6 +437,7 @@ pub type MemberListState = ListState<MemberItem, IambInfo>; | ||
| 427 | 437 | pub type RoomListState = ListState<RoomItem, IambInfo>; |
| 428 | 438 | pub type ChatListState = ListState<GenericChatItem, IambInfo>; |
| 429 | 439 | pub type UnreadListState = ListState<GenericChatItem, IambInfo>; |
| 440 | pub type MentionsListState = ListState<GenericChatItem, IambInfo>; | |
| 430 | 441 | pub type SpaceListState = ListState<SpaceItem, IambInfo>; |
| 431 | 442 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
| 432 | 443 | |
| @@ -660,6 +671,40 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 660 | 671 | .focus(focused) |
| 661 | 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 | 708 | IambWindow::SpaceList(state) => { |
| 664 | 709 | let mut items = store |
| 665 | 710 | .application |
| @@ -713,6 +758,7 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 713 | 758 | IambWindow::Welcome(w) => w.dup(store).into(), |
| 714 | 759 | IambWindow::ChatList(w) => w.dup(store).into(), |
| 715 | 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 | 800 | IambWindow::Welcome(_) => IambId::Welcome, |
| 755 | 801 | IambWindow::ChatList(_) => IambId::ChatList, |
| 756 | 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 | 813 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), |
| 767 | 814 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), |
| 768 | 815 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), |
| 816 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions"), | |
| 769 | 817 | |
| 770 | 818 | IambWindow::Room(w) => { |
| 771 | 819 | let title = store.application.get_room_title(w.id()); |
| @@ -794,6 +842,7 @@ impl Window<IambInfo> for IambWindow { | ||
| 794 | 842 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), |
| 795 | 843 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), |
| 796 | 844 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), |
| 845 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions"), | |
| 797 | 846 | |
| 798 | 847 | IambWindow::Room(w) => w.get_title(store), |
| 799 | 848 | IambWindow::MemberList(state, room_id, _) => { |
| @@ -860,6 +909,11 @@ impl Window<IambInfo> for IambWindow { | ||
| 860 | 909 | |
| 861 | 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 | 965 | let info = store.application.rooms.get_or_default(room_id.to_owned()); |
| 912 | 966 | let name = info.name.clone().unwrap_or_default(); |
| 913 | 967 | let alias = room.canonical_alias(); |
| 914 | let unread = info.unreads(room, &store.application.settings); | |
| 968 | let unread = info.unreads(room); | |
| 915 | 969 | info.tags.clone_from(&room_info.deref().1); |
| 916 | 970 | |
| 917 | 971 | if let Some(alias) = &alias { |
| @@ -930,6 +984,11 @@ impl GenericChatItem { | ||
| 930 | 984 | fn tags(&self) -> &Option<Tags> { |
| 931 | 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 | |
| 935 | 994 | impl RoomLikeItem for GenericChatItem { |
| @@ -979,9 +1038,8 @@ impl ListItem<IambInfo> for GenericChatItem { | ||
| 979 | 1038 | _: &ViewportContext<ListCursor>, |
| 980 | 1039 | _: &mut ProgramStore, |
| 981 | 1040 | ) -> Text<'_> { |
| 982 | let unread = self.unread.is_unread(); | |
| 983 | 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 | 1043 | let mut spans = vec![name]; |
| 986 | 1044 | |
| 987 | 1045 | labels.push(if self.is_dm { |
| @@ -1030,7 +1088,7 @@ impl RoomItem { | ||
| 1030 | 1088 | let info = store.application.rooms.get_or_default(room_id.to_owned()); |
| 1031 | 1089 | let name = info.name.clone().unwrap_or_default(); |
| 1032 | 1090 | let alias = room.canonical_alias(); |
| 1033 | let unread = info.unreads(room, &store.application.settings); | |
| 1091 | let unread = info.unreads(room); | |
| 1034 | 1092 | info.tags.clone_from(&room_info.deref().1); |
| 1035 | 1093 | |
| 1036 | 1094 | if let Some(alias) = &alias { |
| @@ -1098,9 +1156,8 @@ impl ListItem<IambInfo> for RoomItem { | ||
| 1098 | 1156 | _: &ViewportContext<ListCursor>, |
| 1099 | 1157 | _: &mut ProgramStore, |
| 1100 | 1158 | ) -> Text<'_> { |
| 1101 | let unread = self.unread.is_unread(); | |
| 1102 | 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 | 1161 | let mut spans = vec![name]; |
| 1105 | 1162 | |
| 1106 | 1163 | if let Some(tags) = &self.tags() { |
| @@ -1138,12 +1195,13 @@ pub struct DirectItem { | ||
| 1138 | 1195 | |
| 1139 | 1196 | impl DirectItem { |
| 1140 | 1197 | fn new(room_info: MatrixRoomInfo, store: &mut ProgramStore) -> Self { |
| 1198 | let room = &room_info.deref().0; | |
| 1141 | 1199 | let room_id = room_info.0.room_id().to_owned(); |
| 1142 | 1200 | let alias = room_info.0.canonical_alias(); |
| 1143 | 1201 | |
| 1144 | 1202 | let info = store.application.rooms.get_or_default(room_id); |
| 1145 | 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 | 1205 | info.tags.clone_from(&room_info.deref().1); |
| 1148 | 1206 | |
| 1149 | 1207 | DirectItem { room_info, name, alias, unread } |
| @@ -1207,9 +1265,8 @@ impl ListItem<IambInfo> for DirectItem { | ||
| 1207 | 1265 | _: &ViewportContext<ListCursor>, |
| 1208 | 1266 | _: &mut ProgramStore, |
| 1209 | 1267 | ) -> Text<'_> { |
| 1210 | let unread = self.unread.is_unread(); | |
| 1211 | 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 | 1270 | let mut spans = vec![name]; |
| 1214 | 1271 | |
| 1215 | 1272 | if let Some(tags) = &self.tags() { |
| @@ -1757,7 +1814,12 @@ mod tests { | ||
| 1757 | 1814 | tags: vec![], |
| 1758 | 1815 | alias: None, |
| 1759 | 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 | 1823 | invite: false, |
| 1762 | 1824 | }; |
| 1763 | 1825 | |
| @@ -1767,8 +1829,10 @@ mod tests { | ||
| 1767 | 1829 | alias: None, |
| 1768 | 1830 | name: "Room 2", |
| 1769 | 1831 | unread: UnreadInfo { |
| 1770 | unread: false, | |
| 1771 | 1832 | latest: Some(MessageTimeStamp::OriginServer(40u32.into())), |
| 1833 | unread_messages: 0, | |
| 1834 | unread_notifications: 0, | |
| 1835 | unread_mentions: 0, | |
| 1772 | 1836 | }, |
| 1773 | 1837 | invite: false, |
| 1774 | 1838 | }; |
| @@ -1779,8 +1843,10 @@ mod tests { | ||
| 1779 | 1843 | alias: None, |
| 1780 | 1844 | name: "Room 3", |
| 1781 | 1845 | unread: UnreadInfo { |
| 1782 | unread: false, | |
| 1783 | 1846 | latest: Some(MessageTimeStamp::OriginServer(20u32.into())), |
| 1847 | unread_messages: 0, | |
| 1848 | unread_notifications: 0, | |
| 1849 | unread_mentions: 0, | |
| 1784 | 1850 | }, |
| 1785 | 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 && | |
| 1459 | settings.tunables.read_receipt_send && | |
| 1460 | state.cursor.timestamp.is_none() | |
| 1461 | { | |
| 1458 | if self.room_focused && state.cursor.timestamp.is_none() { | |
| 1462 | 1459 | // If the cursor is at the last message, then update the read marker. |
| 1463 | if let Some((k, _)) = thread.last_key_value() { | |
| 1464 | info.set_receipt(thread.1.clone(), settings.profile.user_id.clone(), k.1.clone()); | |
| 1465 | } | |
| 1460 | info.fully_read(settings.profile.user_id.clone(), thread.1.clone()); | |
| 1466 | 1461 | } |
| 1467 | 1462 | |
| 1468 | 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 | |
| 463 | 463 | async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { |
| 464 | use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType; | |
| 465 | ||
| 464 | 466 | let mut interval = tokio::time::interval(Duration::from_secs(2)); |
| 465 | 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 | 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 | 500 | drop(locked); |
| 493 | 501 | |
| 494 | 502 | for (room_id, thread, new_receipt) in updates { |
| 495 | use matrix_sdk::ruma::api::client::receipt::create_receipt::v3::ReceiptType; | |
| 496 | ||
| 497 | 503 | let Some(room) = client.get_room(&room_id) else { |
| 498 | 504 | continue; |
| 499 | 505 | }; |
| @@ -505,7 +511,7 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { | ||
| 505 | 511 | } |
| 506 | 512 | |
| 507 | 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 | 515 | .await |
| 510 | 516 | { |
| 511 | 517 | Ok(()) => { |
| @@ -721,7 +727,11 @@ pub async fn create_client(settings: &ApplicationSettings) -> Client { | ||
| 721 | 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 | 737 | #[derive(Clone)] |