Single room list approach, account bar scrolls

This commit is contained in:
miruka
2020-04-29 14:00:02 -04:00
parent 56c09e6b48
commit fcf88209f2
13 changed files with 129 additions and 172 deletions

View File

@@ -871,6 +871,7 @@ class MatrixClient(nio.AsyncClient):
"""
self.models[self.user_id, "rooms"].pop(room_id, None)
self.models["every_room"].pop((self.user_id, room_id), None)
self.models.pop((self.user_id, room_id, "events"), None)
self.models.pop((self.user_id, room_id, "members"), None)
@@ -1209,8 +1210,9 @@ class MatrixClient(nio.AsyncClient):
mentions = 0
unreads = 0
self.models[self.user_id, "rooms"][room.room_id] = Room(
room_item = Room(
id = room.room_id,
for_account = self.user_id,
given_name = room.name or "",
display_name = room.display_name or "",
avatar_url = room.gen_avatar_url or "",
@@ -1244,9 +1246,11 @@ class MatrixClient(nio.AsyncClient):
last_event_date = last_event_date,
mentions = mentions,
unreads = unreads,
)
self.models[self.user_id, "rooms"][room.room_id] = room_item
self.models["every_room"][self.user_id, room.room_id] = room_item
# List members that left the room, then remove them from our model
left_the_room = [
user_id

View File

@@ -40,9 +40,9 @@ class Account(ModelItem):
first_sync_done: bool = False
def __lt__(self, other: "Account") -> bool:
"""Sort by display name or user ID."""
name = self.display_name or self.id[1:]
other_name = other.display_name or other.id[1:]
"""Sort by user ID."""
name = self.id[1:]
other_name = other.id[1:]
return name.lower() < other_name.lower()
@@ -51,6 +51,7 @@ class Room(ModelItem):
"""A matrix room we are invited to, are or were member of."""
id: str = field()
for_account: str = field()
given_name: str = ""
display_name: str = ""
main_alias: str = ""
@@ -90,19 +91,22 @@ class Room(ModelItem):
Invited rooms are first, then joined rooms, then left rooms.
Within these categories, sort by last event date (room with recent
messages are first), then by display names, but
messages are first), then by display names, then account, 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.
return (
self.for_account,
self.left,
other.inviter_id,
bool(other.mentions),
bool(other.unreads),
other.last_event_date,
(self.display_name or self.id).lower(),
) < (
other.for_account,
other.left,
self.inviter_id,
bool(self.mentions),