Commit 28fcfe9d02

28fcfe9d0243d09412b55cb8c331cc911b9a008d

parent: bdd8bf8e9b

Unregistered key

vaw <git@nlih.de> · 2026-10-04 02:10 UTC
committer: <noreply@github.com>

Show unread count in room list (#677)

Layout: unified · split

docs/iamb.5 +30 −4
@@ -567,7 +567,7 @@ How to sort the
567567.Sy :rooms
568568window.
569569Defaults to
570.Sy ["favorite",\ "invite",\ "lowpriority",\ "unread",\ "joined",\ "space",\ "dm",\ "name"] .
570.Sy ["favorite",\ "invite",\ "lowpriority",\ "mentions",\ "notifications",\ "joined",\ "space",\ "dm",\ "recent",\ "name"] .
571571.It Sy chats
572572How to sort the
573573.Sy :chats
@@ -617,18 +617,24 @@ Put invites before other rooms.
617617Put joined rooms before unjoined rooms.
618618.It Sy lowpriority
619619Put lowpriority rooms after other rooms.
620.It Sy mentions
621Put rooms with unread mentions before other rooms.
620622.It Sy name
621623Sort rooms by alphabetically ascending room name.
624.It Sy notifications
625Put rooms with unread notifications before other rooms.
622626.It Sy recent
623627Sort rooms by most recent message timestamp.
624628.It Sy server
625629Sort rooms by alphabetically ascending server name from the room alias.
626630This will fall back to the server from the room identifier if there is
627631no canonical alias for the room.
632.It Sy unread
633Put rooms with unread messages before other rooms.
634.It Sy recent
635Sort rooms by most recent message timestamp.
628636.It Sy space
629637Put spaces before other rooms.
630.It Sy unread
631Put unread rooms before other rooms.
632638.El
633639The available values for sorting space members are the same as for sorting rooms with the addition:
634640.Bl -tag -width Ds
@@ -934,8 +940,28 @@ UI elements you can set within this subsection are:
934940Configure the default style for text in room lists.
935941.It Sy labels
936942Configure the style for the labels following room names in lists.
943.It Sy notification
944Configure how rooms with unread notifications are displayed.
945.Bl -tag -width Ds
946.It Sy number
947Configure the style of the number showing how many unread notifications a room has.
948.It Sy name
949Configure the style for rooms with unread notifications.
950.It Sy labels
951Configure the style for the labels of rooms with unread notifications.
952.El
953.It Sy mention
954Configure how rooms with unread mentions are displayed.
955Accepts the same values as
956.Sy notification .
937957.It Sy unread
938Configure the style for unread room names in lists.
958Configure how rooms with unread muted messages are displayed.
959Accepts the same values as
960.Sy notification .
961.It Sy marked_unread .
962Configure how rooms that are manually marked as unread are displayed.
963Accepts the same values as
964.Sy notification .
939965.El
940966.El
941967.Ss Example 1: Make code blocks a lighter gray background and state events red
src/base.rs +22
@@ -247,6 +247,12 @@ pub enum SortFieldRoom {
247247 /// Sort rooms by whether they have unread messages.
248248 Unread,
249249
250 /// Sort rooms by whether they have unread notifications.
251 Notifications,
252
253 /// Sort rooms by whether they have unread mentions.
254 Mentions,
255
250256 /// Sort rooms by the timestamps of their most recent messages.
251257 Recent,
252258
@@ -331,6 +337,8 @@ impl Visitor<'_> for SortRoomVisitor {
331337 "lowpriority" => SortFieldRoom::LowPriority,
332338 "recent" => SortFieldRoom::Recent,
333339 "unread" => SortFieldRoom::Unread,
340 "notifications" => SortFieldRoom::Notifications,
341 "mentions" => SortFieldRoom::Mentions,
334342 "name" => SortFieldRoom::Name,
335343 "alias" => SortFieldRoom::Alias,
336344 "dm" => SortFieldRoom::Direct,
@@ -1111,11 +1119,25 @@ impl UnreadInfo {
11111119 self.unread_mentions > 0
11121120 }
11131121
1122 pub fn has_notification(&self) -> bool {
1123 self.unread_notifications > 0
1124 }
1125
11141126 pub fn latest(&self) -> Option<&MessageTimeStamp> {
11151127 self.latest.as_ref()
11161128 }
11171129}
11181130
1131impl std::ops::AddAssign<Self> for UnreadInfo {
1132 fn add_assign(&mut self, rhs: Self) {
1133 self.unread_mark |= rhs.unread_mark;
1134 self.unread_messages += rhs.unread_messages;
1135 self.unread_notifications += rhs.unread_notifications;
1136 self.unread_mentions += rhs.unread_mentions;
1137 self.latest = self.latest.max(rhs.latest);
1138 }
1139}
1140
11191141/// The [`OwnedUserId`]s for users with the given displayname in [`DisplayNameStore`].
11201142#[derive(Default)]
11211143struct DisplayNameUsers {
src/config/mod.rs +7 −6
@@ -50,14 +50,16 @@ const DEFAULT_MEMBERS_SORT: [SortColumn<SortFieldUser>; 4] = [
5050 SortColumn(SortFieldUser::UserId, SortOrder::Ascending),
5151];
5252
53const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 8] = [
53const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 10] = [
5454 SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending),
5555 SortColumn(SortFieldRoom::Invite, SortOrder::Ascending),
5656 SortColumn(SortFieldRoom::LowPriority, SortOrder::Ascending),
57 SortColumn(SortFieldRoom::Unread, SortOrder::Ascending),
57 SortColumn(SortFieldRoom::Mentions, SortOrder::Ascending),
58 SortColumn(SortFieldRoom::Notifications, SortOrder::Ascending),
5859 SortColumn(SortFieldRoom::Joined, SortOrder::Ascending),
5960 SortColumn(SortFieldRoom::Space, SortOrder::Ascending),
6061 SortColumn(SortFieldRoom::Direct, SortOrder::Ascending),
62 SortColumn(SortFieldRoom::Recent, SortOrder::Ascending),
6163 SortColumn(SortFieldRoom::Name, SortOrder::Ascending),
6264];
6365
@@ -1676,10 +1678,9 @@ mod tests {
16761678
16771679 #[test]
16781680 fn test_parse_default_rooms_sort() {
1679 let sort: Vec<SortColumn<SortFieldRoom>> = serde_json::from_str(
1680 r#"["favorite","invite","lowpriority","unread","joined","space","dm","name"]"#,
1681 )
1682 .unwrap();
1681 let sort: Vec<SortColumn<SortFieldRoom>> =
1682 serde_json::from_str(r#"["favorite","invite","lowpriority","mentions","notifications","joined","space","dm","recent","name"]"#)
1683 .unwrap();
16831684 assert_eq!(sort.as_slice(), &DEFAULT_ROOM_SORT[..]);
16841685 }
16851686
src/config/theme.rs +85 −6
@@ -64,7 +64,25 @@ pub fn default_theme() -> Theme {
6464 ..Default::default()
6565 },
6666 rooms: ThemeRooms {
67 unread: Stylable::with_modifiers(StyleModifier::BOLD),
67 unread: ThemeRoomsUnreads {
68 number: Stylable::fg(Color::Gray),
69 ..Default::default()
70 },
71 notification: ThemeRoomsUnreads {
72 name: Stylable::with_modifiers(StyleModifier::BOLD),
73 number: Stylable::fg(Color::Yellow),
74 ..Default::default()
75 },
76 mention: ThemeRoomsUnreads {
77 name: Stylable::with_modifiers(StyleModifier::BOLD),
78 number: Stylable::fg(Color::Red),
79 ..Default::default()
80 },
81 marked_unread: ThemeRoomsUnreads {
82 name: Stylable::with_modifiers(StyleModifier::BOLD),
83 number: Stylable::fg(Color::Green),
84 ..Default::default()
85 },
6886 ..Default::default()
6987 },
7088 users: ThemeUsers {
@@ -529,9 +547,17 @@ struct ThemeRooms {
529547 #[serde(default)]
530548 labels: Stylable,
531549
532 // XXX: use different colors for "mention", "notification", "muted room"
533550 #[serde(default)]
534 unread: Stylable,
551 unread: ThemeRoomsUnreads,
552
553 #[serde(default)]
554 notification: ThemeRoomsUnreads,
555
556 #[serde(default)]
557 mention: ThemeRoomsUnreads,
558
559 #[serde(default)]
560 marked_unread: ThemeRoomsUnreads,
535561}
536562
537563impl ThemeRooms {
@@ -540,15 +566,28 @@ impl ThemeRooms {
540566 default: self.default.merge(other.default),
541567 labels: self.labels.merge(other.labels),
542568 unread: self.unread.merge(other.unread),
569 notification: self.notification.merge(other.notification),
570 mention: self.mention.merge(other.mention),
571 marked_unread: self.marked_unread.merge(other.marked_unread),
543572 }
544573 }
545574
546575 fn values(self, base: Style) -> ThemeRoomsValues {
547576 let default = base.patch(self.default);
548577 let labels = default.patch(self.labels);
549 let unread = default.patch(self.unread);
578 let unread = self.unread.values(default, labels);
579 let notification = self.notification.values(default, labels);
580 let mention = self.mention.values(default, labels);
581 let marked_unread = self.marked_unread.values(default, labels);
550582
551 ThemeRoomsValues { default, labels, unread }
583 ThemeRoomsValues {
584 default,
585 labels,
586 unread,
587 notification,
588 mention,
589 marked_unread,
590 }
552591 }
553592}
554593
@@ -556,7 +595,47 @@ impl ThemeRooms {
556595pub struct ThemeRoomsValues {
557596 pub default: Style,
558597 pub labels: Style,
559 pub unread: Style,
598 pub unread: ThemeRoomsUnreadsValues,
599 pub notification: ThemeRoomsUnreadsValues,
600 pub mention: ThemeRoomsUnreadsValues,
601 pub marked_unread: ThemeRoomsUnreadsValues,
602}
603
604#[derive(Clone, Debug, Default, Deserialize)]
605struct ThemeRoomsUnreads {
606 #[serde(default)]
607 name: Stylable,
608
609 #[serde(default)]
610 number: Stylable,
611
612 #[serde(default)]
613 labels: Stylable,
614}
615
616impl ThemeRoomsUnreads {
617 fn merge(self, other: Self) -> Self {
618 Self {
619 name: self.name.merge(other.name),
620 number: self.number.merge(other.number),
621 labels: self.labels.merge(other.labels),
622 }
623 }
624
625 fn values(self, base: Style, labels_base: Style) -> ThemeRoomsUnreadsValues {
626 let name = base.patch(self.name);
627 let number = base.patch(self.number);
628 let labels = labels_base.patch(self.labels);
629
630 ThemeRoomsUnreadsValues { name, number, labels }
631 }
632}
633
634#[derive(Clone, Debug, Default)]
635pub struct ThemeRoomsUnreadsValues {
636 pub name: Style,
637 pub number: Style,
638 pub labels: Style,
560639}
561640
562641#[derive(Clone, Debug, Default, Deserialize)]
src/windows/mod.rs +122 −33
@@ -28,8 +28,10 @@ use crate::base::{
2828 SortFieldSpace,
2929 SortFieldUser,
3030 SortOrder,
31 SpaceInfo,
3132 UnreadInfo,
3233};
34use crate::config::theme::ThemeRoomsValues;
3335use crate::prelude::*;
3436use crate::resolve_mxid;
3537use crate::windows::room::{RoomState, room_command};
@@ -52,6 +54,32 @@ pub fn selected_style(selected: bool, style: Style) -> Style {
5254 }
5355}
5456
57/// Returns the number span with width 4 and the style for name and tags.
58fn unreads_and_style(
59 unread: &UnreadInfo,
60 theme: &ThemeRoomsValues,
61) -> (Span<'static>, Style, Style) {
62 let (value, style) = if unread.unread_mentions > 0 {
63 (unread.unread_mentions + unread.unread_notifications, &theme.mention)
64 } else if unread.unread_notifications > 0 {
65 (unread.unread_notifications, &theme.notification)
66 } else if unread.unread_messages > 0 {
67 (unread.unread_messages, &theme.unread)
68 } else {
69 return (Span::styled(" ", theme.default), theme.default, theme.labels);
70 };
71
72 if unread.unread_mark {
73 let style = &theme.marked_unread;
74
75 (Span::styled(" U ", style.number), style.name, style.labels)
76 } else if value > 99 {
77 (Span::styled("99+ ", style.number), style.name, style.labels)
78 } else {
79 (Span::styled(format!(" {:2} ", value), style.number), style.name, style.labels)
80 }
81}
82
5583fn heroes_to_name(heroes: &[RoomHeroWithProfile]) -> String {
5684 let mut text = String::new();
5785 let mut first = true;
@@ -205,6 +233,14 @@ fn room_cmp<T: RoomLikeItem>(
205233 // Sort true (unread) before false (read)
206234 b.is_unread().cmp(&a.is_unread())
207235 },
236 SortFieldRoom::Notifications => {
237 // Sort true (unread) before false (read)
238 b.has_notification().cmp(&a.has_notification())
239 },
240 SortFieldRoom::Mentions => {
241 // Sort true (unread) before false (read)
242 b.has_mention().cmp(&a.has_mention())
243 },
208244 SortFieldRoom::Recent => {
209245 // sort larger timestamps towards the top.
210246 some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a))
@@ -339,6 +375,8 @@ impl SortedSection for SortFieldRoom {
339375 ListSectionHeader::LowPriority
340376 },
341377 SortFieldRoom::Space if room.room_type().is_space() => ListSectionHeader::Spaces,
378 SortFieldRoom::Mentions if room.has_mention() => ListSectionHeader::UnreadMentions,
379 SortFieldRoom::Notifications if room.has_notification() => ListSectionHeader::Unreads,
342380 SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads,
343381 _ => return None,
344382 };
@@ -385,6 +423,7 @@ pub enum ListSectionHeader {
385423 NotJoined,
386424 Rooms,
387425 Spaces,
426 UnreadMentions,
388427 Unreads,
389428 Users,
390429}
@@ -425,6 +464,7 @@ impl From<ListSectionHeader> for Line<'static> {
425464 ListSectionHeader::Rooms => Line::raw("Rooms").bold(),
426465 ListSectionHeader::Spaces => Line::raw("Spaces").bold(),
427466 ListSectionHeader::Unreads => Line::raw("Unreads").bold(),
467 ListSectionHeader::UnreadMentions => Line::raw("Unread Mentions").bold(),
428468 ListSectionHeader::Users => Line::raw("Users").bold(),
429469 }
430470 }
@@ -435,11 +475,12 @@ trait RoomLikeItem {
435475 fn room_type(&self) -> &RoomType;
436476 fn has_tag(&self, tag: TagName) -> bool;
437477 fn is_unread(&self) -> bool;
478 fn has_notification(&self) -> bool;
479 fn has_mention(&self) -> bool;
438480 fn recent_ts(&self) -> Option<&MessageTimeStamp>;
439481 fn alias(&self) -> Option<&RoomAliasId>;
440482 fn name(&self) -> &str;
441483 fn membership(&self) -> MatrixRoomState;
442 fn has_mention(&self) -> bool;
443484}
444485
445486#[inline]
@@ -698,8 +739,10 @@ impl WindowOps<IambInfo> for IambWindow {
698739 sync_info,
699740 verifications,
700741 worker,
742 spaces,
701743 ..
702744 } = &mut store.application;
745 let client = &worker.client;
703746
704747 let default_list_style = settings.theme.default;
705748 let default_rooms_style = settings.theme.rooms.default;
@@ -711,8 +754,13 @@ impl WindowOps<IambInfo> for IambWindow {
711754 .dms
712755 .iter()
713756 .map(|room| {
714 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
715 .show_room_type(false)
757 GenericRoomItem::new(
758 room,
759 rooms.get_or_default(room.room_id().to_owned()),
760 client,
761 spaces,
762 )
763 .show_room_type(false)
716764 })
717765 .collect::<Vec<_>>();
718766 let fields = &settings.tunables.sort.dms;
@@ -789,8 +837,13 @@ impl WindowOps<IambInfo> for IambWindow {
789837 .rooms
790838 .iter()
791839 .map(|room| {
792 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
793 .show_room_type(false)
840 GenericRoomItem::new(
841 room,
842 rooms.get_or_default(room.room_id().to_owned()),
843 client,
844 spaces,
845 )
846 .show_room_type(false)
794847 })
795848 .collect::<Vec<_>>();
796849 let fields = &settings.tunables.sort.rooms;
@@ -813,7 +866,12 @@ impl WindowOps<IambInfo> for IambWindow {
813866 .iter()
814867 .chain(sync_info.dms.iter())
815868 .map(|room| {
816 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
869 GenericRoomItem::new(
870 room,
871 rooms.get_or_default(room.room_id().to_owned()),
872 client,
873 spaces,
874 )
817875 })
818876 .collect::<Vec<_>>();
819877
@@ -837,7 +895,12 @@ impl WindowOps<IambInfo> for IambWindow {
837895 .iter()
838896 .chain(sync_info.dms.iter())
839897 .map(|room| {
840 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
898 GenericRoomItem::new(
899 room,
900 rooms.get_or_default(room.room_id().to_owned()),
901 client,
902 spaces,
903 )
841904 })
842905 .filter(RoomLikeItem::is_unread)
843906 .collect::<Vec<_>>();
@@ -862,7 +925,12 @@ impl WindowOps<IambInfo> for IambWindow {
862925 .iter()
863926 .chain(sync_info.dms.iter())
864927 .map(|room| {
865 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
928 GenericRoomItem::new(
929 room,
930 rooms.get_or_default(room.room_id().to_owned()),
931 client,
932 spaces,
933 )
866934 })
867935 .filter(RoomLikeItem::has_mention)
868936 .collect::<Vec<_>>();
@@ -887,7 +955,12 @@ impl WindowOps<IambInfo> for IambWindow {
887955 .iter()
888956 .chain(sync_info.dms.iter())
889957 .map(|room| {
890 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
958 GenericRoomItem::new(
959 room,
960 rooms.get_or_default(room.room_id().to_owned()),
961 client,
962 spaces,
963 )
891964 })
892965 .filter(|item| item.membership() == MatrixRoomState::Invited)
893966 .collect::<Vec<_>>();
@@ -911,8 +984,13 @@ impl WindowOps<IambInfo> for IambWindow {
911984 .spaces
912985 .iter()
913986 .map(|room| {
914 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned()))
915 .show_room_type(false)
987 GenericRoomItem::new(
988 room,
989 rooms.get_or_default(room.room_id().to_owned()),
990 client,
991 spaces,
992 )
993 .show_room_type(false)
916994 })
917995 .collect::<Vec<_>>();
918996
@@ -1269,14 +1347,29 @@ pub struct GenericRoomItem {
12691347}
12701348
12711349impl GenericRoomItem {
1272 pub fn new(room: &MatrixRoom, info: &RoomInfo) -> Self {
1350 pub fn new(
1351 room: &MatrixRoom,
1352 info: &RoomInfo,
1353 client: &Client,
1354 spaces: &HashMap<OwnedRoomId, SpaceInfo>,
1355 ) -> Self {
12731356 let room_id = room.room_id().to_owned();
12741357
12751358 let name = info.name.clone().unwrap_or_default();
12761359 let alias = room.canonical_alias();
1277 let unread = info.unreads(room);
1360 let mut unread = info.unreads(room);
12781361 let tags = info.tags.clone();
12791362
1363 if room.is_space() &&
1364 let Some(space_info) = spaces.get(&room_id)
1365 {
1366 for child in space_info.children.keys() {
1367 if let Some(child) = client.get_room(child) {
1368 unread += info.unreads(&child);
1369 }
1370 }
1371 }
1372
12801373 let room_type = if room.is_space() {
12811374 RoomType::Space
12821375 } else if room.is_dm() {
@@ -1375,12 +1468,10 @@ impl RoomLikeItem for GenericRoomItem {
13751468 }
13761469
13771470 fn is_unread(&self) -> bool {
1378 // XXX: check space children for space
13791471 self.unread.is_unread()
13801472 }
13811473
13821474 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1383 // XXX: check space children for space
13841475 self.unread.latest()
13851476 }
13861477
@@ -1397,9 +1488,12 @@ impl RoomLikeItem for GenericRoomItem {
13971488 }
13981489
13991490 fn has_mention(&self) -> bool {
1400 // XXX: check space children for space
14011491 self.unread.has_mention()
14021492 }
1493
1494 fn has_notification(&self) -> bool {
1495 self.unread.has_notification()
1496 }
14031497}
14041498
14051499impl Display for GenericRoomItem {
@@ -1419,22 +1513,13 @@ impl ListItem<IambInfo> for GenericRoomItem {
14191513 ) -> Text<'_> {
14201514 let theme = &store.application.settings.theme;
14211515
1422 let name_style = if self.unread.is_unread() {
1423 theme.rooms.unread
1424 } else {
1425 theme.rooms.default
1426 };
1427
1516 let (unreads, name_style, tags_style) = unreads_and_style(&self.unread, &theme.rooms);
14281517 let name_style = selected_style(selected, name_style);
1429 let tags_style = selected_style(selected, theme.rooms.labels);
1518 let tags_style = selected_style(selected, tags_style);
1519
14301520 let (name, mut labels) =
14311521 name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style);
1432
1433 let mut spans = if self.section.is_some() {
1434 vec![Span::raw(" "), name]
1435 } else {
1436 vec![name]
1437 };
1522 let mut spans = vec![unreads, name];
14381523
14391524 if let Some(label) = self.room_type.text() {
14401525 labels.push(vec![Span::styled(label, tags_style)]);
@@ -1768,15 +1853,19 @@ mod tests {
17681853 }
17691854
17701855 fn is_unread(&self) -> bool {
1771 self.unread.is_unread()
1856 self.unread.unread_messages > 0
17721857 }
17731858
1774 fn membership(&self) -> MatrixRoomState {
1775 self.membership
1859 fn has_notification(&self) -> bool {
1860 self.unread.unread_notifications > 0
17761861 }
17771862
17781863 fn has_mention(&self) -> bool {
1779 false
1864 self.unread.unread_mentions > 0
1865 }
1866
1867 fn membership(&self) -> MatrixRoomState {
1868 self.membership
17801869 }
17811870 }
17821871
src/windows/room/space.rs +10 −2
@@ -201,14 +201,22 @@ impl StatefulWidget for Space<'_> {
201201 } = &mut self.store.application;
202202 let default_rooms_style = settings.theme.rooms.default;
203203
204 let info = spaces.entry(state.room_id.clone()).or_default();
204 if !spaces.contains_key(&state.room_id) {
205 spaces.insert(state.room_id.clone(), Default::default());
206 }
207 let info = spaces.get(&state.room_id).unwrap();
205208
206209 let mut items = info
207210 .children
208211 .keys()
209212 .map(|id| {
210213 if let Some(room) = worker.client.get_room(id) {
211 GenericRoomItem::new(&room, rooms.get_or_default(id.to_owned()))
214 GenericRoomItem::new(
215 &room,
216 rooms.get_or_default(id.to_owned()),
217 &worker.client,
218 spaces,
219 )
212220 } else {
213221 GenericRoomItem::new_unknown(id.to_owned(), room_previews, need_load)
214222 }
src/worker.rs +1
@@ -1272,6 +1272,7 @@ async fn create_client_inner(
12721272 None,
12731273 )
12741274 .request_config(req_config)
1275 .with_threading_support(matrix_sdk::ThreadingSupport::Enabled { with_subscriptions: false })
12751276 .with_encryption_settings(DEFAULT_ENCRYPTION_SETTINGS);
12761277
12771278 let builder = if let Some(url) = homeserver {