Commit 28fcfe9d02
Unregistered key
Layout: unified · split
docs/iamb.5 +30 −4
| @@ -567,7 +567,7 @@ How to sort the | ||
| 567 | 567 | .Sy :rooms |
| 568 | 568 | window. |
| 569 | 569 | Defaults to |
| 570 | .Sy ["favorite",\ "invite",\ "lowpriority",\ "unread",\ "joined",\ "space",\ "dm",\ "name"] . | |
| 570 | .Sy ["favorite",\ "invite",\ "lowpriority",\ "mentions",\ "notifications",\ "joined",\ "space",\ "dm",\ "recent",\ "name"] . | |
| 571 | 571 | .It Sy chats |
| 572 | 572 | How to sort the |
| 573 | 573 | .Sy :chats |
| @@ -617,18 +617,24 @@ Put invites before other rooms. | ||
| 617 | 617 | Put joined rooms before unjoined rooms. |
| 618 | 618 | .It Sy lowpriority |
| 619 | 619 | Put lowpriority rooms after other rooms. |
| 620 | .It Sy mentions | |
| 621 | Put rooms with unread mentions before other rooms. | |
| 620 | 622 | .It Sy name |
| 621 | 623 | Sort rooms by alphabetically ascending room name. |
| 624 | .It Sy notifications | |
| 625 | Put rooms with unread notifications before other rooms. | |
| 622 | 626 | .It Sy recent |
| 623 | 627 | Sort rooms by most recent message timestamp. |
| 624 | 628 | .It Sy server |
| 625 | 629 | Sort rooms by alphabetically ascending server name from the room alias. |
| 626 | 630 | This will fall back to the server from the room identifier if there is |
| 627 | 631 | no canonical alias for the room. |
| 632 | .It Sy unread | |
| 633 | Put rooms with unread messages before other rooms. | |
| 634 | .It Sy recent | |
| 635 | Sort rooms by most recent message timestamp. | |
| 628 | 636 | .It Sy space |
| 629 | 637 | Put spaces before other rooms. |
| 630 | .It Sy unread | |
| 631 | Put unread rooms before other rooms. | |
| 632 | 638 | .El |
| 633 | 639 | The available values for sorting space members are the same as for sorting rooms with the addition: |
| 634 | 640 | .Bl -tag -width Ds |
| @@ -934,8 +940,28 @@ UI elements you can set within this subsection are: | ||
| 934 | 940 | Configure the default style for text in room lists. |
| 935 | 941 | .It Sy labels |
| 936 | 942 | Configure the style for the labels following room names in lists. |
| 943 | .It Sy notification | |
| 944 | Configure how rooms with unread notifications are displayed. | |
| 945 | .Bl -tag -width Ds | |
| 946 | .It Sy number | |
| 947 | Configure the style of the number showing how many unread notifications a room has. | |
| 948 | .It Sy name | |
| 949 | Configure the style for rooms with unread notifications. | |
| 950 | .It Sy labels | |
| 951 | Configure the style for the labels of rooms with unread notifications. | |
| 952 | .El | |
| 953 | .It Sy mention | |
| 954 | Configure how rooms with unread mentions are displayed. | |
| 955 | Accepts the same values as | |
| 956 | .Sy notification . | |
| 937 | 957 | .It Sy unread |
| 938 | Configure the style for unread room names in lists. | |
| 958 | Configure how rooms with unread muted messages are displayed. | |
| 959 | Accepts the same values as | |
| 960 | .Sy notification . | |
| 961 | .It Sy marked_unread . | |
| 962 | Configure how rooms that are manually marked as unread are displayed. | |
| 963 | Accepts the same values as | |
| 964 | .Sy notification . | |
| 939 | 965 | .El |
| 940 | 966 | .El |
| 941 | 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 | 247 | /// Sort rooms by whether they have unread messages. |
| 248 | 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 | 256 | /// Sort rooms by the timestamps of their most recent messages. |
| 251 | 257 | Recent, |
| 252 | 258 | |
| @@ -331,6 +337,8 @@ impl Visitor<'_> for SortRoomVisitor { | ||
| 331 | 337 | "lowpriority" => SortFieldRoom::LowPriority, |
| 332 | 338 | "recent" => SortFieldRoom::Recent, |
| 333 | 339 | "unread" => SortFieldRoom::Unread, |
| 340 | "notifications" => SortFieldRoom::Notifications, | |
| 341 | "mentions" => SortFieldRoom::Mentions, | |
| 334 | 342 | "name" => SortFieldRoom::Name, |
| 335 | 343 | "alias" => SortFieldRoom::Alias, |
| 336 | 344 | "dm" => SortFieldRoom::Direct, |
| @@ -1111,11 +1119,25 @@ impl UnreadInfo { | ||
| 1111 | 1119 | self.unread_mentions > 0 |
| 1112 | 1120 | } |
| 1113 | 1121 | |
| 1122 | pub fn has_notification(&self) -> bool { | |
| 1123 | self.unread_notifications > 0 | |
| 1124 | } | |
| 1125 | ||
| 1114 | 1126 | pub fn latest(&self) -> Option<&MessageTimeStamp> { |
| 1115 | 1127 | self.latest.as_ref() |
| 1116 | 1128 | } |
| 1117 | 1129 | } |
| 1118 | 1130 | |
| 1131 | impl 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 | 1141 | /// The [`OwnedUserId`]s for users with the given displayname in [`DisplayNameStore`]. |
| 1120 | 1142 | #[derive(Default)] |
| 1121 | 1143 | struct DisplayNameUsers { |
src/config/mod.rs +7 −6
| @@ -50,14 +50,16 @@ const DEFAULT_MEMBERS_SORT: [SortColumn<SortFieldUser>; 4] = [ | ||
| 50 | 50 | SortColumn(SortFieldUser::UserId, SortOrder::Ascending), |
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 8] = [ | |
| 53 | const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 10] = [ | |
| 54 | 54 | SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending), |
| 55 | 55 | SortColumn(SortFieldRoom::Invite, SortOrder::Ascending), |
| 56 | 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 | 59 | SortColumn(SortFieldRoom::Joined, SortOrder::Ascending), |
| 59 | 60 | SortColumn(SortFieldRoom::Space, SortOrder::Ascending), |
| 60 | 61 | SortColumn(SortFieldRoom::Direct, SortOrder::Ascending), |
| 62 | SortColumn(SortFieldRoom::Recent, SortOrder::Ascending), | |
| 61 | 63 | SortColumn(SortFieldRoom::Name, SortOrder::Ascending), |
| 62 | 64 | ]; |
| 63 | 65 | |
| @@ -1676,10 +1678,9 @@ mod tests { | ||
| 1676 | 1678 | |
| 1677 | 1679 | #[test] |
| 1678 | 1680 | 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(); | |
| 1683 | 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 | 64 | ..Default::default() |
| 65 | 65 | }, |
| 66 | 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 | 86 | ..Default::default() |
| 69 | 87 | }, |
| 70 | 88 | users: ThemeUsers { |
| @@ -529,9 +547,17 @@ struct ThemeRooms { | ||
| 529 | 547 | #[serde(default)] |
| 530 | 548 | labels: Stylable, |
| 531 | 549 | |
| 532 | // XXX: use different colors for "mention", "notification", "muted room" | |
| 533 | 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 | |
| 537 | 563 | impl ThemeRooms { |
| @@ -540,15 +566,28 @@ impl ThemeRooms { | ||
| 540 | 566 | default: self.default.merge(other.default), |
| 541 | 567 | labels: self.labels.merge(other.labels), |
| 542 | 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 | 575 | fn values(self, base: Style) -> ThemeRoomsValues { |
| 547 | 576 | let default = base.patch(self.default); |
| 548 | 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 { | ||
| 556 | 595 | pub struct ThemeRoomsValues { |
| 557 | 596 | pub default: Style, |
| 558 | 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)] | |
| 605 | struct ThemeRoomsUnreads { | |
| 606 | #[serde(default)] | |
| 607 | name: Stylable, | |
| 608 | ||
| 609 | #[serde(default)] | |
| 610 | number: Stylable, | |
| 611 | ||
| 612 | #[serde(default)] | |
| 613 | labels: Stylable, | |
| 614 | } | |
| 615 | ||
| 616 | impl 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)] | |
| 635 | pub struct ThemeRoomsUnreadsValues { | |
| 636 | pub name: Style, | |
| 637 | pub number: Style, | |
| 638 | pub labels: Style, | |
| 560 | 639 | } |
| 561 | 640 | |
| 562 | 641 | #[derive(Clone, Debug, Default, Deserialize)] |
src/windows/mod.rs +122 −33
| @@ -28,8 +28,10 @@ use crate::base::{ | ||
| 28 | 28 | SortFieldSpace, |
| 29 | 29 | SortFieldUser, |
| 30 | 30 | SortOrder, |
| 31 | SpaceInfo, | |
| 31 | 32 | UnreadInfo, |
| 32 | 33 | }; |
| 34 | use crate::config::theme::ThemeRoomsValues; | |
| 33 | 35 | use crate::prelude::*; |
| 34 | 36 | use crate::resolve_mxid; |
| 35 | 37 | use 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. | |
| 58 | fn 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 | ||
| 55 | 83 | fn heroes_to_name(heroes: &[RoomHeroWithProfile]) -> String { |
| 56 | 84 | let mut text = String::new(); |
| 57 | 85 | let mut first = true; |
| @@ -205,6 +233,14 @@ fn room_cmp<T: RoomLikeItem>( | ||
| 205 | 233 | // Sort true (unread) before false (read) |
| 206 | 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 | 244 | SortFieldRoom::Recent => { |
| 209 | 245 | // sort larger timestamps towards the top. |
| 210 | 246 | some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a)) |
| @@ -339,6 +375,8 @@ impl SortedSection for SortFieldRoom { | ||
| 339 | 375 | ListSectionHeader::LowPriority |
| 340 | 376 | }, |
| 341 | 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 | 380 | SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads, |
| 343 | 381 | _ => return None, |
| 344 | 382 | }; |
| @@ -385,6 +423,7 @@ pub enum ListSectionHeader { | ||
| 385 | 423 | NotJoined, |
| 386 | 424 | Rooms, |
| 387 | 425 | Spaces, |
| 426 | UnreadMentions, | |
| 388 | 427 | Unreads, |
| 389 | 428 | Users, |
| 390 | 429 | } |
| @@ -425,6 +464,7 @@ impl From<ListSectionHeader> for Line<'static> { | ||
| 425 | 464 | ListSectionHeader::Rooms => Line::raw("Rooms").bold(), |
| 426 | 465 | ListSectionHeader::Spaces => Line::raw("Spaces").bold(), |
| 427 | 466 | ListSectionHeader::Unreads => Line::raw("Unreads").bold(), |
| 467 | ListSectionHeader::UnreadMentions => Line::raw("Unread Mentions").bold(), | |
| 428 | 468 | ListSectionHeader::Users => Line::raw("Users").bold(), |
| 429 | 469 | } |
| 430 | 470 | } |
| @@ -435,11 +475,12 @@ trait RoomLikeItem { | ||
| 435 | 475 | fn room_type(&self) -> &RoomType; |
| 436 | 476 | fn has_tag(&self, tag: TagName) -> bool; |
| 437 | 477 | fn is_unread(&self) -> bool; |
| 478 | fn has_notification(&self) -> bool; | |
| 479 | fn has_mention(&self) -> bool; | |
| 438 | 480 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
| 439 | 481 | fn alias(&self) -> Option<&RoomAliasId>; |
| 440 | 482 | fn name(&self) -> &str; |
| 441 | 483 | fn membership(&self) -> MatrixRoomState; |
| 442 | fn has_mention(&self) -> bool; | |
| 443 | 484 | } |
| 444 | 485 | |
| 445 | 486 | #[inline] |
| @@ -698,8 +739,10 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 698 | 739 | sync_info, |
| 699 | 740 | verifications, |
| 700 | 741 | worker, |
| 742 | spaces, | |
| 701 | 743 | .. |
| 702 | 744 | } = &mut store.application; |
| 745 | let client = &worker.client; | |
| 703 | 746 | |
| 704 | 747 | let default_list_style = settings.theme.default; |
| 705 | 748 | let default_rooms_style = settings.theme.rooms.default; |
| @@ -711,8 +754,13 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 711 | 754 | .dms |
| 712 | 755 | .iter() |
| 713 | 756 | .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) | |
| 716 | 764 | }) |
| 717 | 765 | .collect::<Vec<_>>(); |
| 718 | 766 | let fields = &settings.tunables.sort.dms; |
| @@ -789,8 +837,13 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 789 | 837 | .rooms |
| 790 | 838 | .iter() |
| 791 | 839 | .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) | |
| 794 | 847 | }) |
| 795 | 848 | .collect::<Vec<_>>(); |
| 796 | 849 | let fields = &settings.tunables.sort.rooms; |
| @@ -813,7 +866,12 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 813 | 866 | .iter() |
| 814 | 867 | .chain(sync_info.dms.iter()) |
| 815 | 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 | 876 | .collect::<Vec<_>>(); |
| 819 | 877 | |
| @@ -837,7 +895,12 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 837 | 895 | .iter() |
| 838 | 896 | .chain(sync_info.dms.iter()) |
| 839 | 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 | 905 | .filter(RoomLikeItem::is_unread) |
| 843 | 906 | .collect::<Vec<_>>(); |
| @@ -862,7 +925,12 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 862 | 925 | .iter() |
| 863 | 926 | .chain(sync_info.dms.iter()) |
| 864 | 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 | 935 | .filter(RoomLikeItem::has_mention) |
| 868 | 936 | .collect::<Vec<_>>(); |
| @@ -887,7 +955,12 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 887 | 955 | .iter() |
| 888 | 956 | .chain(sync_info.dms.iter()) |
| 889 | 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 | 965 | .filter(|item| item.membership() == MatrixRoomState::Invited) |
| 893 | 966 | .collect::<Vec<_>>(); |
| @@ -911,8 +984,13 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 911 | 984 | .spaces |
| 912 | 985 | .iter() |
| 913 | 986 | .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) | |
| 916 | 994 | }) |
| 917 | 995 | .collect::<Vec<_>>(); |
| 918 | 996 | |
| @@ -1269,14 +1347,29 @@ pub struct GenericRoomItem { | ||
| 1269 | 1347 | } |
| 1270 | 1348 | |
| 1271 | 1349 | impl 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 | 1356 | let room_id = room.room_id().to_owned(); |
| 1274 | 1357 | |
| 1275 | 1358 | let name = info.name.clone().unwrap_or_default(); |
| 1276 | 1359 | let alias = room.canonical_alias(); |
| 1277 | let unread = info.unreads(room); | |
| 1360 | let mut unread = info.unreads(room); | |
| 1278 | 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 | 1373 | let room_type = if room.is_space() { |
| 1281 | 1374 | RoomType::Space |
| 1282 | 1375 | } else if room.is_dm() { |
| @@ -1375,12 +1468,10 @@ impl RoomLikeItem for GenericRoomItem { | ||
| 1375 | 1468 | } |
| 1376 | 1469 | |
| 1377 | 1470 | fn is_unread(&self) -> bool { |
| 1378 | // XXX: check space children for space | |
| 1379 | 1471 | self.unread.is_unread() |
| 1380 | 1472 | } |
| 1381 | 1473 | |
| 1382 | 1474 | fn recent_ts(&self) -> Option<&MessageTimeStamp> { |
| 1383 | // XXX: check space children for space | |
| 1384 | 1475 | self.unread.latest() |
| 1385 | 1476 | } |
| 1386 | 1477 | |
| @@ -1397,9 +1488,12 @@ impl RoomLikeItem for GenericRoomItem { | ||
| 1397 | 1488 | } |
| 1398 | 1489 | |
| 1399 | 1490 | fn has_mention(&self) -> bool { |
| 1400 | // XXX: check space children for space | |
| 1401 | 1491 | self.unread.has_mention() |
| 1402 | 1492 | } |
| 1493 | ||
| 1494 | fn has_notification(&self) -> bool { | |
| 1495 | self.unread.has_notification() | |
| 1496 | } | |
| 1403 | 1497 | } |
| 1404 | 1498 | |
| 1405 | 1499 | impl Display for GenericRoomItem { |
| @@ -1419,22 +1513,13 @@ impl ListItem<IambInfo> for GenericRoomItem { | ||
| 1419 | 1513 | ) -> Text<'_> { |
| 1420 | 1514 | let theme = &store.application.settings.theme; |
| 1421 | 1515 | |
| 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); | |
| 1428 | 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 | 1520 | let (name, mut labels) = |
| 1431 | 1521 | 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]; | |
| 1438 | 1523 | |
| 1439 | 1524 | if let Some(label) = self.room_type.text() { |
| 1440 | 1525 | labels.push(vec![Span::styled(label, tags_style)]); |
| @@ -1768,15 +1853,19 @@ mod tests { | ||
| 1768 | 1853 | } |
| 1769 | 1854 | |
| 1770 | 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 { | |
| 1775 | self.membership | |
| 1859 | fn has_notification(&self) -> bool { | |
| 1860 | self.unread.unread_notifications > 0 | |
| 1776 | 1861 | } |
| 1777 | 1862 | |
| 1778 | 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 | 201 | } = &mut self.store.application; |
| 202 | 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 | 209 | let mut items = info |
| 207 | 210 | .children |
| 208 | 211 | .keys() |
| 209 | 212 | .map(|id| { |
| 210 | 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 | 220 | } else { |
| 213 | 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 | 1272 | None, |
| 1273 | 1273 | ) |
| 1274 | 1274 | .request_config(req_config) |
| 1275 | .with_threading_support(matrix_sdk::ThreadingSupport::Enabled { with_subscriptions: false }) | |
| 1275 | 1276 | .with_encryption_settings(DEFAULT_ENCRYPTION_SETTINGS); |
| 1276 | 1277 | |
| 1277 | 1278 | let builder = if let Some(url) = homeserver { |