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
625625.Sy :rooms
626626window.
627627Defaults 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"] .
629629.It Sy chats
630630How to sort the
631631.Sy :chats
@@ -681,6 +681,8 @@ Put rooms with unread mentions before other rooms.
681681Sort rooms by alphabetically ascending room name.
682682.It Sy notifications
683683Put rooms with unread notifications before other rooms.
684.It Sy marked_unread
685Put rooms that were manually marked as unread before other rooms.
684686.It Sy recent
685687Sort rooms by most recent message timestamp.
686688.It Sy server
src/base.rs +4
@@ -254,6 +254,9 @@ pub enum SortFieldRoom {
254254 /// Sort rooms by whether they have unread mentions.
255255 Mentions,
256256
257 /// Sort rooms by whether they were marked as unread.
258 MarkedUnread,
259
257260 /// Sort rooms by the timestamps of their most recent messages.
258261 Recent,
259262
@@ -340,6 +343,7 @@ impl Visitor<'_> for SortRoomVisitor {
340343 "unread" => SortFieldRoom::Unread,
341344 "notifications" => SortFieldRoom::Notifications,
342345 "mentions" => SortFieldRoom::Mentions,
346 "marked_unread" => SortFieldRoom::MarkedUnread,
343347 "name" => SortFieldRoom::Name,
344348 "alias" => SortFieldRoom::Alias,
345349 "dm" => SortFieldRoom::Direct,
src/config/mod.rs +3 −2
@@ -65,12 +65,13 @@ const DEFAULT_MEMBERS_SORT: [SortColumn<SortFieldUser>; 4] = [
6565 SortColumn(SortFieldUser::UserId, SortOrder::Ascending),
6666];
6767
68const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 10] = [
68const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 11] = [
6969 SortColumn(SortFieldRoom::Favorite, SortOrder::Ascending),
7070 SortColumn(SortFieldRoom::Invite, SortOrder::Ascending),
7171 SortColumn(SortFieldRoom::LowPriority, SortOrder::Ascending),
7272 SortColumn(SortFieldRoom::Mentions, SortOrder::Ascending),
7373 SortColumn(SortFieldRoom::Notifications, SortOrder::Ascending),
74 SortColumn(SortFieldRoom::MarkedUnread, SortOrder::Ascending),
7475 SortColumn(SortFieldRoom::Joined, SortOrder::Ascending),
7576 SortColumn(SortFieldRoom::Space, SortOrder::Ascending),
7677 SortColumn(SortFieldRoom::Direct, SortOrder::Ascending),
@@ -2269,7 +2270,7 @@ time_format = "%"
22692270 #[test]
22702271 fn test_parse_default_rooms_sort() {
22712272 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"]"#)
22732274 .unwrap();
22742275 assert_eq!(sort.as_slice(), &DEFAULT_ROOM_SORT[..]);
22752276 }
src/windows/mod.rs +14
@@ -199,6 +199,10 @@ fn room_cmp<T: RoomLikeItem>(
199199 // Sort true (unread) before false (read)
200200 b.has_mention().cmp(&a.has_mention())
201201 },
202 SortFieldRoom::MarkedUnread => {
203 // Sort true (unread) before false (read)
204 b.marked_unread().cmp(&a.marked_unread())
205 },
202206 SortFieldRoom::Recent => {
203207 // sort larger timestamps towards the top.
204208 some_cmp(a.recent_ts(), b.recent_ts(), |a, b| b.cmp(a))
@@ -340,6 +344,7 @@ impl SortedSection for SortFieldRoom {
340344 SortFieldRoom::Mentions if room.has_mention() => ListSectionHeader::UnreadMentions,
341345 SortFieldRoom::Notifications if room.has_notification() => ListSectionHeader::Unreads,
342346 SortFieldRoom::Unread if room.is_unread() => ListSectionHeader::Unreads,
347 SortFieldRoom::MarkedUnread if room.marked_unread() => ListSectionHeader::Unreads,
343348
344349 // Since the values that these fields sort on are almost always unique to every room,
345350 // we don't do much useful sorting after this and can't provide visually useful section
@@ -453,6 +458,7 @@ trait RoomLikeItem {
453458 fn is_unread(&self) -> bool;
454459 fn has_notification(&self) -> bool;
455460 fn has_mention(&self) -> bool;
461 fn marked_unread(&self) -> bool;
456462 fn recent_ts(&self) -> Option<&MessageTimeStamp>;
457463 fn alias(&self) -> Option<&RoomAliasId>;
458464 fn name(&self) -> &str;
@@ -1593,6 +1599,10 @@ impl RoomLikeItem for GenericRoomItem {
15931599 fn has_notification(&self) -> bool {
15941600 self.unread.has_notification()
15951601 }
1602
1603 fn marked_unread(&self) -> bool {
1604 self.unread.unread_mark
1605 }
15961606}
15971607
15981608impl Display for GenericRoomItem {
@@ -2018,6 +2028,10 @@ mod tests {
20182028 fn membership(&self) -> MatrixRoomState {
20192029 self.membership
20202030 }
2031
2032 fn marked_unread(&self) -> bool {
2033 self.unread.unread_mark
2034 }
20212035 }
20222036
20232037 #[test]