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 # 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 - when inviting members, prevent if user id is on another server and room
doesn't allow that doesn't allow that
- "exception during sync" aren't caught - "exception during sync" aren't caught

View File

@ -502,13 +502,12 @@ class MatrixClient(nio.AsyncClient):
event = Event( event = Event(
id = f"echo-{transaction_id}", id = f"echo-{transaction_id}",
event_id = "", event_id = "",
source = None, event_type = event_type,
date = datetime.now(), date = datetime.now(),
sender_id = self.user_id, sender_id = self.user_id,
sender_name = our_info.display_name, sender_name = our_info.display_name,
sender_avatar = our_info.avatar_url, sender_avatar = our_info.avatar_url,
is_local_echo = True, is_local_echo = True,
local_event_type = event_type,
**event_fields, **event_fields,
) )
@ -1026,6 +1025,7 @@ class MatrixClient(nio.AsyncClient):
item = Event( item = Event(
id = ev.event_id, id = ev.event_id,
event_id = ev.event_id, event_id = ev.event_id,
event_type = type(ev),
source = ev, source = ev,
date = datetime.fromtimestamp(ev.server_timestamp / 1000), date = datetime.fromtimestamp(ev.server_timestamp / 1000),
sender_id = ev.sender, sender_id = ev.sender,

View File

@ -3,7 +3,6 @@
"""`ModelItem` subclasses definitions.""" """`ModelItem` subclasses definitions."""
import asyncio import asyncio
import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
@ -21,6 +20,7 @@ ZeroDate = datetime.fromtimestamp(0)
OptionalExceptionType = Union[Type[None], Type[Exception]] OptionalExceptionType = Union[Type[None], Type[Exception]]
class TypeSpecifier(AutoStrEnum): class TypeSpecifier(AutoStrEnum):
"""Enum providing clarification of purpose for some matrix events.""" """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): class UploadStatus(AutoStrEnum):
"""Enum describing the status of an upload operation.""" """Enum describing the status of an upload operation."""
@ -142,7 +136,7 @@ class UploadStatus(AutoStrEnum):
@dataclass @dataclass
class Upload(ModelItem): class Upload(ModelItem): # XXX
"""Represent a running or failed file upload operation.""" """Represent a running or failed file upload operation."""
id: UUID = field() id: UUID = field()
@ -219,33 +213,25 @@ class Event(ModelItem):
return self.date > other.date return self.date > other.date
@property @property
def event_type(self) -> Type: def links(self) -> List[Dict[str, Any]]:
"""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]:
"""List of URLs (`<a href=...>` tags) present in the event content.""" """List of URLs (`<a href=...>` tags) present in the event content."""
urls: List[str] = [] urls: List[Dict[str, Any]] = []
if self.content.strip(): 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: if self.media_url:
urls.append(self.media_url) urls.append({"url": self.media_url})
return urls return urls
@property @property
def serialized(self) -> Dict[str, Any]: def serialized(self) -> Dict[str, Any]:
dct = super().serialized dct = super().serialized
del dct["source"] dct["source"] = dct["source"].__dict__
del dct["local_event_type"]
return dct return dct

View File

@ -18,9 +18,6 @@ class ModelItem:
Subclasses are also expected to implement `__lt__()`, Subclasses are also expected to implement `__lt__()`,
to provide support for comparisons with the `<`, `>`, `<=`, `=>` operators to provide support for comparisons with the `<`, `>`, `<=`, `=>` operators
and thus allow a `Model` to sort its `ModelItem`s. 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": def __new__(cls, *_args, **_kwargs) -> "ModelItem":

View File

@ -64,13 +64,8 @@ HColumnLayout {
function json() { function json() {
return JSON.stringify( const events = ModelStore.get(chat.userId, chat.roomId, "events")
{ return JSON.stringify(events.get(model.id), null, 4)
"model": ModelStore.get(chat.userId, chat.roomId, "events")
.get(model.id),
"source": py.getattr(model.source, "__dict__"),
},
null, 4)
} }
function openContextMenu() { function openContextMenu() {