diff --git a/TODO.md b/TODO.md index 64c7f7c2..aee38678 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ # TODO -- room last event date previous year show month if <3 month +- members filtering - when inviting members, prevent if user id is on another server and room doesn't allow that - "exception during sync" aren't caught diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 4b8cec68..67d201b9 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -502,13 +502,12 @@ class MatrixClient(nio.AsyncClient): event = Event( id = f"echo-{transaction_id}", event_id = "", - source = None, + event_type = event_type, date = datetime.now(), sender_id = self.user_id, sender_name = our_info.display_name, sender_avatar = our_info.avatar_url, is_local_echo = True, - local_event_type = event_type, **event_fields, ) @@ -1026,6 +1025,7 @@ class MatrixClient(nio.AsyncClient): item = Event( id = ev.event_id, event_id = ev.event_id, + event_type = type(ev), source = ev, date = datetime.fromtimestamp(ev.server_timestamp / 1000), sender_id = ev.sender, diff --git a/src/backend/models/items.py b/src/backend/models/items.py index a98eec9c..e3837d9f 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -3,7 +3,6 @@ """`ModelItem` subclasses definitions.""" import asyncio -import re from dataclasses import dataclass, field from datetime import datetime, timedelta from pathlib import Path @@ -21,6 +20,7 @@ ZeroDate = datetime.fromtimestamp(0) OptionalExceptionType = Union[Type[None], Type[Exception]] + class TypeSpecifier(AutoStrEnum): """Enum providing clarification of purpose for some matrix events.""" @@ -127,12 +127,6 @@ class Member(ModelItem): ) - @property - def filter_string(self) -> str: - """Filter members based on display name.""" - return self.display_name - - class UploadStatus(AutoStrEnum): """Enum describing the status of an upload operation.""" @@ -142,7 +136,7 @@ class UploadStatus(AutoStrEnum): @dataclass -class Upload(ModelItem): +class Upload(ModelItem): # XXX """Represent a running or failed file upload operation.""" id: UUID = field() @@ -219,33 +213,25 @@ class Event(ModelItem): return self.date > other.date @property - def event_type(self) -> Type: - """Type of the source nio event used to create this `Event`.""" - - if self.local_event_type: - return self.local_event_type - - return type(self.source) - - @property - def links(self) -> List[str]: + def links(self) -> List[Dict[str, Any]]: """List of URLs (`` tags) present in the event content.""" - urls: List[str] = [] + urls: List[Dict[str, Any]] = [] if self.content.strip(): - urls += [link[2] for link in lxml.html.iterlinks(self.content)] + urls += [ + {"url": link[2]} for link in lxml.html.iterlinks(self.content) + ] if self.media_url: - urls.append(self.media_url) + urls.append({"url": self.media_url}) return urls @property def serialized(self) -> Dict[str, Any]: - dct = super().serialized - del dct["source"] - del dct["local_event_type"] + dct = super().serialized + dct["source"] = dct["source"].__dict__ return dct diff --git a/src/backend/models/model_item.py b/src/backend/models/model_item.py index 7a156ff7..ebbc10f5 100644 --- a/src/backend/models/model_item.py +++ b/src/backend/models/model_item.py @@ -18,9 +18,6 @@ class ModelItem: Subclasses are also expected to implement `__lt__()`, to provide support for comparisons with the `<`, `>`, `<=`, `=>` operators and thus allow a `Model` to sort its `ModelItem`s. - - They may also implement a `filter_string` property, that will be used - for filtering from the UI. """ def __new__(cls, *_args, **_kwargs) -> "ModelItem": diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index 0c2ce111..5e6eed83 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -64,13 +64,8 @@ HColumnLayout { function json() { - return JSON.stringify( - { - "model": ModelStore.get(chat.userId, chat.roomId, "events") - .get(model.id), - "source": py.getattr(model.source, "__dict__"), - }, - null, 4) + const events = ModelStore.get(chat.userId, chat.roomId, "events") + return JSON.stringify(events.get(model.id), null, 4) } function openContextMenu() {