Commit 37c3ecdc3f
37c3ecdc3f2d79f724d3cd5cd7d43d9318c48218
parent: f8e9b9d62f
Unregistered key
vaw <git@nlih.de> · 2026-11-21 14:26 UTC
committer: <noreply@github.com>
Sort rooms by unread mark (#870)
Layout: unified · split
docs/iamb.5
+3 −1
| @@ -625,7 +625,7 @@ How to sort the |
| 625 | 625 | .Sy :rooms |
| 626 | 626 | window. |
| 627 | 627 | Defaults to |
| 628 | | .Sy ["favorite",\ "invite",\ "lowpriority",\ "mentions",\ "notifications",\ "joined",\ "space",\ "dm",\ "recent",\ "name"] . |
| 628 | .Sy ["favorite",\ "invite",\ "lowpriority",\ "mentions",\ "notifications",\ "marked_unread",\ "joined",\ "space",\ "dm",\ "recent",\ "name"] . |
| 629 | 629 | .It Sy chats |
| 630 | 630 | How to sort the |
| 631 | 631 | .Sy :chats |
| @@ -681,6 +681,8 @@ Put rooms with unread mentions before other rooms. |
| 681 | 681 | Sort rooms by alphabetically ascending room name. |
| 682 | 682 | .It Sy notifications |
| 683 | 683 | Put rooms with unread notifications before other rooms. |
| 684 | .It Sy marked_unread |
| 685 | Put rooms that were manually marked as unread before other rooms. |
| 684 | 686 | .It Sy recent |
| 685 | 687 | Sort rooms by most recent message timestamp. |
| 686 | 688 | .It Sy server |
src/base.rs
+4
| @@ -254,6 +254,9 @@ pub enum SortFieldRoom { |
| 254 | 254 | /// Sort rooms by whether they have unread mentions. |
| 255 | 255 | Mentions, |
| 256 | 256 | |
| 257 | /// Sort rooms by whether they were marked as unread. |
| 258 | MarkedUnread, |
| 259 | |
| 257 | 260 | /// Sort rooms by the timestamps of their most recent messages. |
| 258 | 261 | Recent, |
| 259 | 262 | |
| @@ -340,6 +343,7 @@ impl Visitor<'_> for SortRoomVisitor { |
| 340 | 343 | "unread" => SortFieldRoom::Unread, |
| 341 | 344 | "notifications" => SortFieldRoom::Notifications, |
| 342 | 345 | "mentions" => SortFieldRoom::Mentions, |
| 346 | "marked_unread" => SortFieldRoom::MarkedUnread, |
| 343 | 347 | "name" => SortFieldRoom::Name, |
| 344 | 348 | "alias" => SortFieldRoom::Alias, |
| 345 | 349 | "dm" => SortFieldRoom::Direct, |
src/config/mod.rs
+3 −2
| @@ -65,12 +65,13 @@ const DEFAULT_MEMBERS_SORT: [SortColumn<SortFieldUser>; 4] = [ |
| 65 | 65 | SortColumn(SortFieldUser::UserId, SortOrder::Ascending), |
| 66 | 66 | ]; |
| 67 | 67 | |
| 68 | | const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 10] = [ |
| 68 | const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 11] = [ |
| 69 | 69 | SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending), |
| 70 | 70 | SortColumn(SortFieldRoom::Invite, SortOrder::Ascending), |
| 71 | 71 | SortColumn(SortFieldRoom::LowPriority, SortOrder::Ascending), |
| 72 | 72 | SortColumn(SortFieldRoom::Mentions, SortOrder::Ascending), |
| 73 | 73 | SortColumn(SortFieldRoom::Notifications, SortOrder::Ascending), |
| 74 | SortColumn(SortFieldRoom::MarkedUnread, SortOrder::Ascending), |
| 74 | 75 | SortColumn(SortFieldRoom::Joined, SortOrder::Ascending), |
| 75 | 76 | SortColumn(SortFieldRoom::Space, SortOrder::Ascending), |
| 76 | 77 | SortColumn(SortFieldRoom::Direct, SortOrder::Ascending), |
| @@ -2269,7 +2270,7 @@ time_format = "%" |
| 2269 | 2270 | #[test] |
| 2270 | 2271 | fn test_parse_default_rooms_sort() { |
| 2271 | 2272 | let sort: Vec<SortColumn<SortFieldRoom>> = |
| 2272 | | serde_json::from_str(r#"["favorite","invite","lowpriority","mentions","notifications","joined","space","dm","recent","name"]"#) |
| 2273 | serde_json::from_str(r#"["favorite","invite","lowpriority","mentions","notifications","marked_unread","joined","space","dm","recent","name"]"#) |
| 2273 | 2274 | .unwrap(); |
| 2274 | 2275 | assert_eq!(sort.as_slice(), &DEFAULT_ROOM_SORT[..]); |
| 2275 | 2276 | } |
src/windows/mod.rs
+14
| @@ -199,6 +199,10 @@ fn room_cmp<T: RoomLikeItem>( |
| 199 | 199 | // Sort true (unread) before false (read) |
| 200 | 200 | b.has_mention().cmp(&a.has_mention()) |
| 201 | 201 | }, |
| 202 | SortFieldRoom::MarkedUnread => { |
| 203 | // Sort true (unread) before false (read) |
| 204 | b.marked_unread().cmp(&a.marked_unread()) |
| 205 | }, |
| 202 | 206 | SortFieldRoom::Recent => { |
| 203 | 207 | // sort larger timestamps towards the top. |
| 204 | 208 | some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a)) |
| @@ -340,6 +344,7 @@ impl SortedSection for SortFieldRoom { |
| 340 | 344 | SortFieldRoom::Mentions if room.has_mention() => ListSectionHeader::UnreadMentions, |
| 341 | 345 | SortFieldRoom::Notifications if room.has_notification() => ListSectionHeader::Unreads, |
| 342 | 346 | SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads, |
| 347 | SortFieldRoom::MarkedUnread if room.marked_unread() => ListSectionHeader::Unreads, |
| 343 | 348 | |
| 344 | 349 | // Since the values that these fields sort on are almost always unique to every room, |
| 345 | 350 | // we don't do much useful sorting after this and can't provide visually useful section |
| @@ -453,6 +458,7 @@ trait RoomLikeItem { |
| 453 | 458 | fn is_unread(&self) -> bool; |
| 454 | 459 | fn has_notification(&self) -> bool; |
| 455 | 460 | fn has_mention(&self) -> bool; |
| 461 | fn marked_unread(&self) -> bool; |
| 456 | 462 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
| 457 | 463 | fn alias(&self) -> Option<&RoomAliasId>; |
| 458 | 464 | fn name(&self) -> &str; |
| @@ -1593,6 +1599,10 @@ impl RoomLikeItem for GenericRoomItem { |
| 1593 | 1599 | fn has_notification(&self) -> bool { |
| 1594 | 1600 | self.unread.has_notification() |
| 1595 | 1601 | } |
| 1602 | |
| 1603 | fn marked_unread(&self) -> bool { |
| 1604 | self.unread.unread_mark |
| 1605 | } |
| 1596 | 1606 | } |
| 1597 | 1607 | |
| 1598 | 1608 | impl Display for GenericRoomItem { |
| @@ -2018,6 +2028,10 @@ mod tests { |
| 2018 | 2028 | fn membership(&self) -> MatrixRoomState { |
| 2019 | 2029 | self.membership |
| 2020 | 2030 | } |
| 2031 | |
| 2032 | fn marked_unread(&self) -> bool { |
| 2033 | self.unread.unread_mark |
| 2034 | } |
| 2021 | 2035 | } |
| 2022 | 2036 | |
| 2023 | 2037 | #[test] |