filter_string is now a class property
- Support serializing class properties instead of just dataclass fields - filter_string is now a property that's always up-to-date - Account display names matching the current SidePane filter are shown
This commit is contained in:
parent
d1eec2ee6b
commit
4349643345
2
TODO.md
2
TODO.md
|
@ -1,6 +1,6 @@
|
||||||
- Refactoring
|
- Refactoring
|
||||||
- filter string serialize thing
|
- 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 all icon SVG files white/black, since we can now use ColorOverlay
|
||||||
- Make the icon blue in EditAccount when hovering and no avatar set
|
- Make the icon blue in EditAccount when hovering and no avatar set
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ class Backend:
|
||||||
"type": "Account",
|
"type": "Account",
|
||||||
"id": account.user_id,
|
"id": account.user_id,
|
||||||
"user_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()):
|
for room in sorted(self.models[Room, account.user_id].values()):
|
||||||
|
@ -176,7 +176,7 @@ class Backend:
|
||||||
"type": "Room",
|
"type": "Room",
|
||||||
"id": "/".join((account.user_id, room.room_id)),
|
"id": "/".join((account.user_id, room.room_id)),
|
||||||
"user_id": account.user_id,
|
"user_id": account.user_id,
|
||||||
"data": room.__dict__,
|
"data": room.serialized,
|
||||||
})
|
})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -4,7 +4,6 @@ import inspect
|
||||||
import json
|
import json
|
||||||
import logging as log
|
import logging as log
|
||||||
import platform
|
import platform
|
||||||
import re
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -364,13 +363,6 @@ class MatrixClient(nio.AsyncClient):
|
||||||
inviter_avatar =
|
inviter_avatar =
|
||||||
(room.avatar_url(inviter) or "") if inviter else "",
|
(room.avatar_url(inviter) or "") if inviter else "",
|
||||||
left = left,
|
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,
|
last_event = last_ev,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -383,9 +375,6 @@ class MatrixClient(nio.AsyncClient):
|
||||||
avatar_url = member.avatar_url or "",
|
avatar_url = member.avatar_url or "",
|
||||||
typing = user_id in room.typing_users,
|
typing = user_id in room.typing_users,
|
||||||
power_level = member.power_level,
|
power_level = member.power_level,
|
||||||
filter_string = " ".join({
|
|
||||||
member.name, room.user_name(user_id),
|
|
||||||
}).strip(),
|
|
||||||
) for user_id, member in room.users.items()
|
) for user_id, member in room.users.items()
|
||||||
}
|
}
|
||||||
self.models[Member, room.room_id].update(new_dict)
|
self.models[Member, room.room_id].update(new_dict)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
@ -13,16 +14,15 @@ class Account(ModelItem):
|
||||||
display_name: str = ""
|
display_name: str = ""
|
||||||
avatar_url: str = ""
|
avatar_url: str = ""
|
||||||
profile_updated: datetime = field(default_factory=datetime.now)
|
profile_updated: datetime = field(default_factory=datetime.now)
|
||||||
filter_string: str = ""
|
|
||||||
|
|
||||||
def __lt__(self, other: "Account") -> bool:
|
def __lt__(self, other: "Account") -> bool:
|
||||||
name = self.display_name or self.user_id[1:]
|
name = self.display_name or self.user_id[1:]
|
||||||
other_name = other.display_name or other.user_id[1:]
|
other_name = other.display_name or other.user_id[1:]
|
||||||
return name < other_name
|
return name < other_name
|
||||||
|
|
||||||
# @property
|
@property
|
||||||
# def filter_string(self) -> str: # TODO: support serializing properties
|
def filter_string(self) -> str:
|
||||||
# return " ".join((self.user_id, self.display_name))
|
return self.display_name
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -35,7 +35,6 @@ class Room(ModelItem):
|
||||||
inviter_name: str = ""
|
inviter_name: str = ""
|
||||||
inviter_avatar: str = ""
|
inviter_avatar: str = ""
|
||||||
left: bool = False
|
left: bool = False
|
||||||
filter_string: str = ""
|
|
||||||
typing_members: List[str] = field(default_factory=list)
|
typing_members: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
# Event __dict__
|
# Event __dict__
|
||||||
|
@ -64,6 +63,15 @@ class Room(ModelItem):
|
||||||
other_name = other.display_name or other.room_id
|
other_name = other.display_name or other.room_id
|
||||||
return name < other_name
|
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
|
@dataclass
|
||||||
class Member(ModelItem):
|
class Member(ModelItem):
|
||||||
|
@ -72,7 +80,6 @@ class Member(ModelItem):
|
||||||
avatar_url: str = ""
|
avatar_url: str = ""
|
||||||
typing: bool = False
|
typing: bool = False
|
||||||
power_level: int = 0
|
power_level: int = 0
|
||||||
filter_string: str = ""
|
|
||||||
|
|
||||||
def __lt__(self, other: "Member") -> bool:
|
def __lt__(self, other: "Member") -> bool:
|
||||||
name = self.display_name or self.user_id[1:]
|
name = self.display_name or self.user_id[1:]
|
||||||
|
@ -80,6 +87,11 @@ class Member(ModelItem):
|
||||||
return name < other_name
|
return name < other_name
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filter_string(self) -> str:
|
||||||
|
return self.display_name
|
||||||
|
|
||||||
|
|
||||||
class TypeSpecifier(AutoStrEnum):
|
class TypeSpecifier(AutoStrEnum):
|
||||||
none = auto()
|
none = auto()
|
||||||
profile_change = auto()
|
profile_change = auto()
|
||||||
|
|
|
@ -98,7 +98,7 @@ class Model(MutableMapping):
|
||||||
|
|
||||||
|
|
||||||
def serialized(self) -> List[Dict[str, Any]]:
|
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:
|
def __lt__(self, other: "Model") -> bool:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import ClassVar, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
|
||||||
class ModelItem:
|
class ModelItem:
|
||||||
|
@ -15,5 +15,16 @@ class ModelItem:
|
||||||
with self.parent_model._sync_lock:
|
with self.parent_model._sync_lock:
|
||||||
self.parent_model._changed = True
|
self.parent_model._changed = True
|
||||||
|
|
||||||
|
|
||||||
def __delattr__(self, name: str) -> None:
|
def __delattr__(self, name: str) -> None:
|
||||||
raise NotImplementedError()
|
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")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,9 @@ HListView {
|
||||||
{
|
{
|
||||||
if (filter && show.length && item.type == "Account" &&
|
if (filter && show.length && item.type == "Account" &&
|
||||||
show[show.length - 1].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,
|
// If current and previous items are both accounts,
|
||||||
// that means the previous account had no matching rooms.
|
// that means the previous account had no matching rooms.
|
||||||
show.pop()
|
show.pop()
|
||||||
|
|
|
@ -26,7 +26,6 @@ HInteractiveRectangle {
|
||||||
|
|
||||||
function activate() {
|
function activate() {
|
||||||
pageStack.showRoom(model.user_id, model.data.room_id)
|
pageStack.showRoom(model.user_id, model.data.room_id)
|
||||||
print(model.user_id, model.data.room_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user