Room.__lt__(): use tuple comparison

This commit is contained in:
miruka 2019-11-26 16:17:15 -04:00
parent 2754fff0df
commit e57ffdae3f

View File

@ -52,27 +52,28 @@ class Room(ModelItem):
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False) last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
def __lt__(self, other: "Room") -> bool: def __lt__(self, other: "Room") -> bool:
# Left rooms may still have an inviter_id, check left first. # Order: Invited rooms > joined rooms > left rooms.
if self.left and not other.left: # Within these categories, sort by date then by name.
return False # Left rooms may still have an inviter_id, so check left first.
if other.left and not self.left: return (
return True self.left,
if self.inviter_id and not other.inviter_id: other.inviter_id,
return True
if other.inviter_id and not self.inviter_id:
return False
if self.last_event and other.last_event: other.last_event["date"] if other.last_event else
return self.last_event["date"] > other.last_event["date"] datetime.fromtimestamp(0),
if self.last_event and not other.last_event:
return True
if other.last_event and not self.last_event:
return False
name = self.display_name or self.room_id self.display_name or self.room_id,
other_name = other.display_name or other.room_id ) < (
return name < other_name other.left,
self.inviter_id,
self.last_event["date"] if self.last_event else
datetime.fromtimestamp(0),
other.display_name or other.room_id,
)
@property @property
def filter_string(self) -> str: def filter_string(self) -> str: