diff --git a/TODO.md b/TODO.md index d2fc735d..834004ca 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ - Refactoring - filter string serialize thing - - set client max timeout to 10s + - `x.__dict__` → `vars(x)` - Make all icon SVG files white/black, since we can now use ColorOverlay - Make the icon blue in EditAccount when hovering and no avatar set diff --git a/src/python/backend.py b/src/python/backend.py index b7281534..375dcd35 100644 --- a/src/python/backend.py +++ b/src/python/backend.py @@ -168,7 +168,7 @@ class Backend: "type": "Account", "id": account.user_id, "user_id": account.user_id, - "data": account.__dict__, + "data": account.serialized, }) for room in sorted(self.models[Room, account.user_id].values()): @@ -176,7 +176,7 @@ class Backend: "type": "Room", "id": "/".join((account.user_id, room.room_id)), "user_id": account.user_id, - "data": room.__dict__, + "data": room.serialized, }) return data diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 6079e0c5..39cdb62e 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -4,7 +4,6 @@ import inspect import json import logging as log import platform -import re from contextlib import suppress from datetime import datetime from enum import Enum @@ -364,13 +363,6 @@ class MatrixClient(nio.AsyncClient): inviter_avatar = (room.avatar_url(inviter) or "") if inviter else "", left = left, - filter_string = " ".join({ - name, - room.topic or "", - re.sub( - r"<.*?>", "", last_ev["inline_content"], - ) if last_ev else "", - }).strip(), last_event = last_ev, ) @@ -383,9 +375,6 @@ class MatrixClient(nio.AsyncClient): avatar_url = member.avatar_url or "", typing = user_id in room.typing_users, power_level = member.power_level, - filter_string = " ".join({ - member.name, room.user_name(user_id), - }).strip(), ) for user_id, member in room.users.items() } self.models[Member, room.room_id].update(new_dict) diff --git a/src/python/models/items.py b/src/python/models/items.py index fa8a0b3a..6b2439fc 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -1,3 +1,4 @@ +import re from dataclasses import dataclass, field from datetime import datetime from typing import Any, Dict, List, Optional @@ -13,16 +14,15 @@ class Account(ModelItem): display_name: str = "" avatar_url: str = "" profile_updated: datetime = field(default_factory=datetime.now) - filter_string: str = "" def __lt__(self, other: "Account") -> bool: name = self.display_name or self.user_id[1:] other_name = other.display_name or other.user_id[1:] return name < other_name - # @property - # def filter_string(self) -> str: # TODO: support serializing properties - # return " ".join((self.user_id, self.display_name)) + @property + def filter_string(self) -> str: + return self.display_name @dataclass @@ -35,7 +35,6 @@ class Room(ModelItem): inviter_name: str = "" inviter_avatar: str = "" left: bool = False - filter_string: str = "" typing_members: List[str] = field(default_factory=list) # Event __dict__ @@ -64,15 +63,23 @@ class Room(ModelItem): other_name = other.display_name or other.room_id return name < other_name + @property + def filter_string(self) -> str: + return " ".join(( + self.display_name, + self.topic, + re.sub(r"<.*?>", "", self.last_event["inline_content"]) + if self.last_event else "", + )) + @dataclass class Member(ModelItem): - user_id: str = field() - display_name: str = "" - avatar_url: str = "" - typing: bool = False - power_level: int = 0 - filter_string: str = "" + user_id: str = field() + display_name: str = "" + avatar_url: str = "" + typing: bool = False + power_level: int = 0 def __lt__(self, other: "Member") -> bool: name = self.display_name or self.user_id[1:] @@ -80,6 +87,11 @@ class Member(ModelItem): return name < other_name + @property + def filter_string(self) -> str: + return self.display_name + + class TypeSpecifier(AutoStrEnum): none = auto() profile_change = auto() diff --git a/src/python/models/model.py b/src/python/models/model.py index e5e8d90e..ebe1dc41 100644 --- a/src/python/models/model.py +++ b/src/python/models/model.py @@ -98,7 +98,7 @@ class Model(MutableMapping): def serialized(self) -> List[Dict[str, Any]]: - return [item.__dict__ for item in sorted(self._data.values())] + return [item.serialized for item in sorted(self._data.values())] def __lt__(self, other: "Model") -> bool: diff --git a/src/python/models/model_item.py b/src/python/models/model_item.py index 75c64aa7..ef2114a8 100644 --- a/src/python/models/model_item.py +++ b/src/python/models/model_item.py @@ -1,4 +1,4 @@ -from typing import ClassVar, Optional +from typing import Any, Dict, Optional class ModelItem: @@ -15,5 +15,16 @@ class ModelItem: with self.parent_model._sync_lock: self.parent_model._changed = True + def __delattr__(self, name: str) -> None: raise NotImplementedError() + + + @property + def serialized(self) -> Dict[str, Any]: + return { + name: getattr(self, name) for name in dir(self) + if not ( + name.startswith("_") or name in ("parent_model", "serialized") + ) + } diff --git a/src/qml/SidePane/AccountRoomList.qml b/src/qml/SidePane/AccountRoomList.qml index af2e74d0..6548fa88 100644 --- a/src/qml/SidePane/AccountRoomList.qml +++ b/src/qml/SidePane/AccountRoomList.qml @@ -29,7 +29,9 @@ HListView { { if (filter && show.length && item.type == "Account" && show[show.length - 1].type == "Account" && - ! Utils.filterMatches(filter, item.data.filter_string)) { + ! Utils.filterMatches( + filter, show[show.length - 1].data.filter_string) + ) { // If current and previous items are both accounts, // that means the previous account had no matching rooms. show.pop() diff --git a/src/qml/SidePane/DelegateRoom.qml b/src/qml/SidePane/DelegateRoom.qml index 6af77714..b13269ad 100644 --- a/src/qml/SidePane/DelegateRoom.qml +++ b/src/qml/SidePane/DelegateRoom.qml @@ -26,7 +26,6 @@ HInteractiveRectangle { function activate() { pageStack.showRoom(model.user_id, model.data.room_id) - print(model.user_id, model.data.room_id) }