Working Event.event_type & source fields

This commit is contained in:
miruka 2020-02-11 17:17:11 -04:00
parent b992db9bfe
commit 8a29143b60
5 changed files with 15 additions and 37 deletions

View File

@ -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

View File

@ -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,

View File

@ -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 (`<a href=...>` 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

View File

@ -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":

View File

@ -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() {