Sort mentioned/unread rooms by last event date

This commit is contained in:
miruka 2020-04-17 18:59:17 -04:00
parent 74e35bd128
commit 4f8dc98d13

View File

@ -85,26 +85,27 @@ class Room(ModelItem):
unreads: int = 0 unreads: int = 0
def __lt__(self, other: "Room") -> bool: def __lt__(self, other: "Room") -> bool:
"""Sort by join state, then descending last event date, then name. """Sort by membership, mentions/unread events, last event date, name.
Invited rooms are first, then joined rooms, then left rooms. Invited rooms are first, then joined rooms, then left rooms.
Within these categories, sort by last event date (room with recent Within these categories, sort by last event date (room with recent
messages are first), then by display names. messages are first), then by display names, but
keep rooms with mentions on top, followed by rooms with unread events.
""" """
# Left rooms may still have an inviter_id, so check left first. # Left rooms may still have an inviter_id, so check left first.
return ( return (
self.left, self.left,
other.inviter_id, other.inviter_id,
other.mentions, bool(other.mentions),
other.unreads, bool(other.unreads),
other.last_event_date, other.last_event_date,
(self.display_name or self.id).lower(), (self.display_name or self.id).lower(),
) < ( ) < (
other.left, other.left,
self.inviter_id, self.inviter_id,
self.mentions, bool(self.mentions),
self.unreads, bool(self.unreads),
self.last_event_date, self.last_event_date,
(other.display_name or other.id).lower(), (other.display_name or other.id).lower(),
) )