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