Gather both Accounts and Rooms in all_rooms model

This commit is contained in:
miruka
2020-05-12 06:09:07 -04:00
parent 19243ec5a6
commit 4d3c26abd4
8 changed files with 145 additions and 59 deletions

View File

@@ -53,7 +53,7 @@ class Room(ModelItem):
"""A matrix room we are invited to, are or were member of."""
id: str = field()
for_account: str = field()
for_account: str = ""
given_name: str = ""
display_name: str = ""
main_alias: str = ""
@@ -118,6 +118,33 @@ class Room(ModelItem):
)
@dataclass
class AccountOrRoom(Account, Room):
type: Union[Type[Account], Type[Room]] = Account
def __lt__(self, other: "AccountOrRoom") -> bool: # type: ignore
return (
self.id if self.type is Account else self.for_account,
other.type is Account,
self.left,
other.inviter_id,
bool(other.mentions),
bool(other.unreads),
other.last_event_date,
(self.display_name or self.id).lower(),
) < (
other.id if other.type is Account else other.for_account,
self.type is Account,
other.left,
self.inviter_id,
bool(self.mentions),
bool(self.unreads),
self.last_event_date,
(other.display_name or other.id).lower(),
)
@dataclass
class Member(ModelItem):
"""A member in a matrix room."""