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
567.Sy :rooms 567.Sy :rooms
568window. 568window.
569Defaults to 569Defaults to
570.Sy ["favorite",\ "invite",\ "lowpriority",\ "unread",\ "joined",\ "space",\ "dm",\ "name"] . 570.Sy ["favorite",\ "invite",\ "lowpriority",\ "mentions",\ "notifications",\ "joined",\ "space",\ "dm",\ "recent",\ "name"] .
571.It Sy chats 571.It Sy chats
572How to sort the 572How to sort the
573.Sy :chats 573.Sy :chats
@@ -617,18 +617,24 @@ Put invites before other rooms.
617Put joined rooms before unjoined rooms. 617Put joined rooms before unjoined rooms.
618.It Sy lowpriority 618.It Sy lowpriority
619Put lowpriority rooms after other rooms. 619Put lowpriority rooms after other rooms.
620.It Sy mentions
621Put rooms with unread mentions before other rooms.
620.It Sy name 622.It Sy name
621Sort rooms by alphabetically ascending room name. 623Sort rooms by alphabetically ascending room name.
624.It Sy notifications
625Put rooms with unread notifications before other rooms.
622.It Sy recent 626.It Sy recent
623Sort rooms by most recent message timestamp. 627Sort rooms by most recent message timestamp.
624.It Sy server 628.It Sy server
625Sort rooms by alphabetically ascending server name from the room alias. 629Sort rooms by alphabetically ascending server name from the room alias.
626This will fall back to the server from the room identifier if there is 630This will fall back to the server from the room identifier if there is
627no canonical alias for the room. 631no 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.
628.It Sy space 636.It Sy space
629Put spaces before other rooms. 637Put spaces before other rooms.
630.It Sy unread
631Put unread rooms before other rooms.
632.El 638.El
633The available values for sorting space members are the same as for sorting rooms with the addition: 639The available values for sorting space members are the same as for sorting rooms with the addition:
634.Bl -tag -width Ds 640.Bl -tag -width Ds
@@ -934,8 +940,28 @@ UI elements you can set within this subsection are:
934Configure the default style for text in room lists. 940Configure the default style for text in room lists.
935.It Sy labels 941.It Sy labels
936Configure the style for the labels following room names in lists. 942Configure 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 .
937.It Sy unread 957.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 .
939.El 965.El
940.El 966.El
941.Ss Example 1: Make code blocks a lighter gray background and state events red 967.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 {
247 /// Sort rooms by whether they have unread messages. 247 /// Sort rooms by whether they have unread messages.
248 Unread, 248 Unread,
249 249
250 /// Sort rooms by whether they have unread notifications.
251 Notifications,
252
253 /// Sort rooms by whether they have unread mentions.
254 Mentions,
255
250 /// Sort rooms by the timestamps of their most recent messages. 256 /// Sort rooms by the timestamps of their most recent messages.
251 Recent, 257 Recent,
252 258
@@ -331,6 +337,8 @@ impl Visitor<'_> for SortRoomVisitor {
331 "lowpriority" => SortFieldRoom::LowPriority, 337 "lowpriority" => SortFieldRoom::LowPriority,
332 "recent" => SortFieldRoom::Recent, 338 "recent" => SortFieldRoom::Recent,
333 "unread" => SortFieldRoom::Unread, 339 "unread" => SortFieldRoom::Unread,
340 "notifications" => SortFieldRoom::Notifications,
341 "mentions" => SortFieldRoom::Mentions,
334 "name" => SortFieldRoom::Name, 342 "name" => SortFieldRoom::Name,
335 "alias" => SortFieldRoom::Alias, 343 "alias" => SortFieldRoom::Alias,
336 "dm" => SortFieldRoom::Direct, 344 "dm" => SortFieldRoom::Direct,
@@ -1111,11 +1119,25 @@ impl UnreadInfo {
1111 self.unread_mentions > 0 1119 self.unread_mentions > 0
1112 } 1120 }
1113 1121
1122 pub fn has_notification(&self) -> bool {
1123 self.unread_notifications > 0
1124 }
1125
1114 pub fn latest(&self) -> Option<&MessageTimeStamp> { 1126 pub fn latest(&self) -> Option<&MessageTimeStamp> {
1115 self.latest.as_ref() 1127 self.latest.as_ref()
1116 } 1128 }
1117} 1129}
1118 1130
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
1119/// The [`OwnedUserId`]s for users with the given displayname in [`DisplayNameStore`]. 1141/// The [`OwnedUserId`]s for users with the given displayname in [`DisplayNameStore`].
1120#[derive(Default)] 1142#[derive(Default)]
1121struct DisplayNameUsers { 1143struct DisplayNameUsers {
src/config/mod.rs +7 −6
@@ -50,14 +50,16 @@ const DEFAULT_MEMBERS_SORT: [SortColumn<SortFieldUser>; 4] = [
50 SortColumn(SortFieldUser::UserId, SortOrder::Ascending), 50 SortColumn(SortFieldUser::UserId, SortOrder::Ascending),
51]; 51];
52 52
53const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 8] = [ 53const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 10] = [
54 SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending), 54 SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending),
55 SortColumn(SortFieldRoom::Invite, SortOrder::Ascending), 55 SortColumn(SortFieldRoom::Invite, SortOrder::Ascending),
56 SortColumn(SortFieldRoom::LowPriority, SortOrder::Ascending), 56 SortColumn(SortFieldRoom::LowPriority, SortOrder::Ascending),
57 SortColumn(SortFieldRoom::Unread, SortOrder::Ascending), 57 SortColumn(SortFieldRoom::Mentions, SortOrder::Ascending),
58 SortColumn(SortFieldRoom::Notifications, SortOrder::Ascending),
58 SortColumn(SortFieldRoom::Joined, SortOrder::Ascending), 59 SortColumn(SortFieldRoom::Joined, SortOrder::Ascending),
59 SortColumn(SortFieldRoom::Space, SortOrder::Ascending), 60 SortColumn(SortFieldRoom::Space, SortOrder::Ascending),
60 SortColumn(SortFieldRoom::Direct, SortOrder::Ascending), 61 SortColumn(SortFieldRoom::Direct, SortOrder::Ascending),
62 SortColumn(SortFieldRoom::Recent, SortOrder::Ascending),
61 SortColumn(SortFieldRoom::Name, SortOrder::Ascending), 63 SortColumn(SortFieldRoom::Name, SortOrder::Ascending),
62]; 64];
63 65
@@ -1676,10 +1678,9 @@ mod tests {
1676 1678
1677 #[test] 1679 #[test]
1678 fn test_parse_default_rooms_sort() { 1680 fn test_parse_default_rooms_sort() {
1679 let sort: Vec<SortColumn<SortFieldRoom>> = serde_json::from_str( 1681 let sort: Vec<SortColumn<SortFieldRoom>> =
1680 r#"["favorite","invite","lowpriority","unread","joined","space","dm","name"]"#, 1682 serde_json::from_str(r#"["favorite","invite","lowpriority","mentions","notifications","joined","space","dm","recent","name"]"#)
1681 ) 1683 .unwrap();
1682 .unwrap();
1683 assert_eq!(sort.as_slice(), &DEFAULT_ROOM_SORT[..]); 1684 assert_eq!(sort.as_slice(), &DEFAULT_ROOM_SORT[..]);
1684 } 1685 }
1685 1686
src/config/theme.rs +85 −6
@@ -64,7 +64,25 @@ pub fn default_theme() -> Theme {
64 ..Default::default() 64 ..Default::default()
65 }, 65 },
66 rooms: ThemeRooms { 66 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 },
68 ..Default::default() 86 ..Default::default()
69 }, 87 },
70 users: ThemeUsers { 88 users: ThemeUsers {
@@ -529,9 +547,17 @@ struct ThemeRooms {
529 #[serde(default)] 547 #[serde(default)]
530 labels: Stylable, 548 labels: Stylable,
531 549
532 // XXX: use different colors for "mention", "notification", "muted room"
533 #[serde(default)] 550 #[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,
535} 561}
536 562
537impl ThemeRooms { 563impl ThemeRooms {
@@ -540,15 +566,28 @@ impl ThemeRooms {
540 default: self.default.merge(other.default), 566 default: self.default.merge(other.default),
541 labels: self.labels.merge(other.labels), 567 labels: self.labels.merge(other.labels),
542 unread: self.unread.merge(other.unread), 568 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),
543 } 572 }
544 } 573 }
545 574
546 fn values(self, base: Style) -> ThemeRoomsValues { 575 fn values(self, base: Style) -> ThemeRoomsValues {
547 let default = base.patch(self.default); 576 let default = base.patch(self.default);
548 let labels = default.patch(self.labels); 577 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);
550 582
551 ThemeRoomsValues { default, labels, unread } 583 ThemeRoomsValues {
584 default,
585 labels,
586 unread,
587 notification,
588 mention,
589 marked_unread,
590 }
552 } 591 }
553} 592}
554 593
@@ -556,7 +595,47 @@ impl ThemeRooms {
556pub struct ThemeRoomsValues { 595pub struct ThemeRoomsValues {
557 pub default: Style, 596 pub default: Style,
558 pub labels: Style, 597 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,
560} 639}
561 640
562#[derive(Clone, Debug, Default, Deserialize)] 641#[derive(Clone, Debug, Default, Deserialize)]
src/windows/mod.rs +122 −33
@@ -28,8 +28,10 @@ use crate::base::{
28 SortFieldSpace, 28 SortFieldSpace,
29 SortFieldUser, 29 SortFieldUser,
30 SortOrder, 30 SortOrder,
31 SpaceInfo,
31 UnreadInfo, 32 UnreadInfo,
32}; 33};
34use crate::config::theme::ThemeRoomsValues;
33use crate::prelude::*; 35use crate::prelude::*;
34use crate::resolve_mxid; 36use crate::resolve_mxid;
35use crate::windows::room::{RoomState, room_command}; 37use crate::windows::room::{RoomState, room_command};
@@ -52,6 +54,32 @@ pub fn selected_style(selected: bool, style: Style) -> Style {
52 } 54 }
53} 55}
54 56
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
55fn heroes_to_name(heroes: &[RoomHeroWithProfile]) -> String { 83fn heroes_to_name(heroes: &[RoomHeroWithProfile]) -> String {
56 let mut text = String::new(); 84 let mut text = String::new();
57 let mut first = true; 85 let mut first = true;
@@ -205,6 +233,14 @@ fn room_cmp<T: RoomLikeItem>(
205 // Sort true (unread) before false (read) 233 // Sort true (unread) before false (read)
206 b.is_unread().cmp(&a.is_unread()) 234 b.is_unread().cmp(&a.is_unread())
207 }, 235 },
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 },
208 SortFieldRoom::Recent => { 244 SortFieldRoom::Recent => {
209 // sort larger timestamps towards the top. 245 // sort larger timestamps towards the top.
210 some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a)) 246 some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a))
@@ -339,6 +375,8 @@ impl SortedSection for SortFieldRoom {
339 ListSectionHeader::LowPriority 375 ListSectionHeader::LowPriority
340 }, 376 },
341 SortFieldRoom::Space if room.room_type().is_space() => ListSectionHeader::Spaces, 377 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,
342 SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads, 380 SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads,
343 _ => return None, 381 _ => return None,
344 }; 382 };
@@ -385,6 +423,7 @@ pub enum ListSectionHeader {
385 NotJoined, 423 NotJoined,
386 Rooms, 424 Rooms,
387 Spaces, 425 Spaces,
426 UnreadMentions,
388 Unreads, 427 Unreads,
389 Users, 428 Users,
390} 429}
@@ -425,6 +464,7 @@ impl From<ListSectionHeader> for Line<'static> {
425 ListSectionHeader::Rooms => Line::raw("Rooms").bold(), 464 ListSectionHeader::Rooms => Line::raw("Rooms").bold(),
426 ListSectionHeader::Spaces => Line::raw("Spaces").bold(), 465 ListSectionHeader::Spaces => Line::raw("Spaces").bold(),
427 ListSectionHeader::Unreads => Line::raw("Unreads").bold(), 466 ListSectionHeader::Unreads => Line::raw("Unreads").bold(),
467 ListSectionHeader::UnreadMentions => Line::raw("Unread Mentions").bold(),
428 ListSectionHeader::Users => Line::raw("Users").bold(), 468 ListSectionHeader::Users => Line::raw("Users").bold(),
429 } 469 }
430 } 470 }
@@ -435,11 +475,12 @@ trait RoomLikeItem {
435 fn room_type(&self) -> &RoomType; 475 fn room_type(&self) -> &RoomType;
436 fn has_tag(&self, tag: TagName) -> bool; 476 fn has_tag(&self, tag: TagName) -> bool;
437 fn is_unread(&self) -> bool; 477 fn is_unread(&self) -> bool;
478 fn has_notification(&self) -> bool;
479 fn has_mention(&self) -> bool;
438 fn recent_ts(&self) -> Option<&MessageTimeStamp>; 480 fn recent_ts(&self) -> Option<&MessageTimeStamp>;
439 fn alias(&self) -> Option<&RoomAliasId>; 481 fn alias(&self) -> Option<&RoomAliasId>;
440 fn name(&self) -> &str; 482 fn name(&self) -> &str;
441 fn membership(&self) -> MatrixRoomState; 483 fn membership(&self) -> MatrixRoomState;
442 fn has_mention(&self) -> bool;
443} 484}
444 485
445#[inline] 486#[inline]
@@ -698,8 +739,10 @@ impl WindowOps<IambInfo> for IambWindow {
698 sync_info, 739 sync_info,
699 verifications, 740 verifications,
700 worker, 741 worker,
742 spaces,
701 .. 743 ..
702 } = &mut store.application; 744 } = &mut store.application;
745 let client = &worker.client;
703 746
704 let default_list_style = settings.theme.default; 747 let default_list_style = settings.theme.default;
705 let default_rooms_style = settings.theme.rooms.default; 748 let default_rooms_style = settings.theme.rooms.default;
@@ -711,8 +754,13 @@ impl WindowOps<IambInfo> for IambWindow {
711 .dms 754 .dms
712 .iter() 755 .iter()
713 .map(|room| { 756 .map(|room| {
714 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) 757 GenericRoomItem::new(
715 .show_room_type(false) 758 room,
759 rooms.get_or_default(room.room_id().to_owned()),
760 client,
761 spaces,
762 )
763 .show_room_type(false)
716 }) 764 })
717 .collect::<Vec<_>>(); 765 .collect::<Vec<_>>();
718 let fields = &settings.tunables.sort.dms; 766 let fields = &settings.tunables.sort.dms;
@@ -789,8 +837,13 @@ impl WindowOps<IambInfo> for IambWindow {
789 .rooms 837 .rooms
790 .iter() 838 .iter()
791 .map(|room| { 839 .map(|room| {
792 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) 840 GenericRoomItem::new(
793 .show_room_type(false) 841 room,
842 rooms.get_or_default(room.room_id().to_owned()),
843 client,
844 spaces,
845 )
846 .show_room_type(false)
794 }) 847 })
795 .collect::<Vec<_>>(); 848 .collect::<Vec<_>>();
796 let fields = &settings.tunables.sort.rooms; 849 let fields = &settings.tunables.sort.rooms;
@@ -813,7 +866,12 @@ impl WindowOps<IambInfo> for IambWindow {
813 .iter() 866 .iter()
814 .chain(sync_info.dms.iter()) 867 .chain(sync_info.dms.iter())
815 .map(|room| { 868 .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 )
817 }) 875 })
818 .collect::<Vec<_>>(); 876 .collect::<Vec<_>>();
819 877
@@ -837,7 +895,12 @@ impl WindowOps<IambInfo> for IambWindow {
837 .iter() 895 .iter()
838 .chain(sync_info.dms.iter()) 896 .chain(sync_info.dms.iter())
839 .map(|room| { 897 .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 )
841 }) 904 })
842 .filter(RoomLikeItem::is_unread) 905 .filter(RoomLikeItem::is_unread)
843 .collect::<Vec<_>>(); 906 .collect::<Vec<_>>();
@@ -862,7 +925,12 @@ impl WindowOps<IambInfo> for IambWindow {
862 .iter() 925 .iter()
863 .chain(sync_info.dms.iter()) 926 .chain(sync_info.dms.iter())
864 .map(|room| { 927 .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 )
866 }) 934 })
867 .filter(RoomLikeItem::has_mention) 935 .filter(RoomLikeItem::has_mention)
868 .collect::<Vec<_>>(); 936 .collect::<Vec<_>>();
@@ -887,7 +955,12 @@ impl WindowOps<IambInfo> for IambWindow {
887 .iter() 955 .iter()
888 .chain(sync_info.dms.iter()) 956 .chain(sync_info.dms.iter())
889 .map(|room| { 957 .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 )
891 }) 964 })
892 .filter(|item| item.membership() == MatrixRoomState::Invited) 965 .filter(|item| item.membership() == MatrixRoomState::Invited)
893 .collect::<Vec<_>>(); 966 .collect::<Vec<_>>();
@@ -911,8 +984,13 @@ impl WindowOps<IambInfo> for IambWindow {
911 .spaces 984 .spaces
912 .iter() 985 .iter()
913 .map(|room| { 986 .map(|room| {
914 GenericRoomItem::new(room, rooms.get_or_default(room.room_id().to_owned())) 987 GenericRoomItem::new(
915 .show_room_type(false) 988 room,
989 rooms.get_or_default(room.room_id().to_owned()),
990 client,
991 spaces,
992 )
993 .show_room_type(false)
916 }) 994 })
917 .collect::<Vec<_>>(); 995 .collect::<Vec<_>>();
918 996
@@ -1269,14 +1347,29 @@ pub struct GenericRoomItem {
1269} 1347}
1270 1348
1271impl GenericRoomItem { 1349impl 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 {
1273 let room_id = room.room_id().to_owned(); 1356 let room_id = room.room_id().to_owned();
1274 1357
1275 let name = info.name.clone().unwrap_or_default(); 1358 let name = info.name.clone().unwrap_or_default();
1276 let alias = room.canonical_alias(); 1359 let alias = room.canonical_alias();
1277 let unread = info.unreads(room); 1360 let mut unread = info.unreads(room);
1278 let tags = info.tags.clone(); 1361 let tags = info.tags.clone();
1279 1362
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
1280 let room_type = if room.is_space() { 1373 let room_type = if room.is_space() {
1281 RoomType::Space 1374 RoomType::Space
1282 } else if room.is_dm() { 1375 } else if room.is_dm() {
@@ -1375,12 +1468,10 @@ impl RoomLikeItem for GenericRoomItem {
1375 } 1468 }
1376 1469
1377 fn is_unread(&self) -> bool { 1470 fn is_unread(&self) -> bool {
1378 // XXX: check space children for space
1379 self.unread.is_unread() 1471 self.unread.is_unread()
1380 } 1472 }
1381 1473
1382 fn recent_ts(&self) -> Option<&MessageTimeStamp> { 1474 fn recent_ts(&self) -> Option<&MessageTimeStamp> {
1383 // XXX: check space children for space
1384 self.unread.latest() 1475 self.unread.latest()
1385 } 1476 }
1386 1477
@@ -1397,9 +1488,12 @@ impl RoomLikeItem for GenericRoomItem {
1397 } 1488 }
1398 1489
1399 fn has_mention(&self) -> bool { 1490 fn has_mention(&self) -> bool {
1400 // XXX: check space children for space
1401 self.unread.has_mention() 1491 self.unread.has_mention()
1402 } 1492 }
1493
1494 fn has_notification(&self) -> bool {
1495 self.unread.has_notification()
1496 }
1403} 1497}
1404 1498
1405impl Display for GenericRoomItem { 1499impl Display for GenericRoomItem {
@@ -1419,22 +1513,13 @@ impl ListItem<IambInfo> for GenericRoomItem {
1419 ) -> Text<'_> { 1513 ) -> Text<'_> {
1420 let theme = &store.application.settings.theme; 1514 let theme = &store.application.settings.theme;
1421 1515
1422 let name_style = if self.unread.is_unread() { 1516 let (unreads, name_style, tags_style) = unreads_and_style(&self.unread, &theme.rooms);
1423 theme.rooms.unread
1424 } else {
1425 theme.rooms.default
1426 };
1427
1428 let name_style = selected_style(selected, name_style); 1517 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
1430 let (name, mut labels) = 1520 let (name, mut labels) =
1431 name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style); 1521 name_and_labels(&self.name, &self.unread, self.membership, name_style, tags_style);
1432 1522 let mut spans = vec![unreads, name];
1433 let mut spans = if self.section.is_some() {
1434 vec![Span::raw(" "), name]
1435 } else {
1436 vec![name]
1437 };
1438 1523
1439 if let Some(label) = self.room_type.text() { 1524 if let Some(label) = self.room_type.text() {
1440 labels.push(vec![Span::styled(label, tags_style)]); 1525 labels.push(vec![Span::styled(label, tags_style)]);
@@ -1768,15 +1853,19 @@ mod tests {
1768 } 1853 }
1769 1854
1770 fn is_unread(&self) -> bool { 1855 fn is_unread(&self) -> bool {
1771 self.unread.is_unread() 1856 self.unread.unread_messages > 0
1772 } 1857 }
1773 1858
1774 fn membership(&self) -> MatrixRoomState { 1859 fn has_notification(&self) -> bool {
1775 self.membership 1860 self.unread.unread_notifications > 0
1776 } 1861 }
1777 1862
1778 fn has_mention(&self) -> bool { 1863 fn has_mention(&self) -> bool {
1779 false 1864 self.unread.unread_mentions > 0
1865 }
1866
1867 fn membership(&self) -> MatrixRoomState {
1868 self.membership
1780 } 1869 }
1781 } 1870 }
1782 1871
src/windows/room/space.rs +10 −2
@@ -201,14 +201,22 @@ impl StatefulWidget for Space<'_> {
201 } = &mut self.store.application; 201 } = &mut self.store.application;
202 let default_rooms_style = settings.theme.rooms.default; 202 let default_rooms_style = settings.theme.rooms.default;
203 203
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();
205 208
206 let mut items = info 209 let mut items = info
207 .children 210 .children
208 .keys() 211 .keys()
209 .map(|id| { 212 .map(|id| {
210 if let Some(room) = worker.client.get_room(id) { 213 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 )
212 } else { 220 } else {
213 GenericRoomItem::new_unknown(id.to_owned(), room_previews, need_load) 221 GenericRoomItem::new_unknown(id.to_owned(), room_previews, need_load)
214 } 222 }
src/worker.rs +1
@@ -1272,6 +1272,7 @@ async fn create_client_inner(
1272 None, 1272 None,
1273 ) 1273 )
1274 .request_config(req_config) 1274 .request_config(req_config)
1275 .with_threading_support(matrix_sdk::ThreadingSupport::Enabled { with_subscriptions: false })
1275 .with_encryption_settings(DEFAULT_ENCRYPTION_SETTINGS); 1276 .with_encryption_settings(DEFAULT_ENCRYPTION_SETTINGS);
1276 1277
1277 let builder = if let Some(url) = homeserver { 1278 let builder = if let Some(url) = homeserver {