Room.last_event: be an Event instead of dict

This commit is contained in:
miruka 2019-12-19 16:52:21 -04:00
parent cdd119405e
commit aaa8411cb9
3 changed files with 19 additions and 11 deletions

View File

@ -5,7 +5,6 @@
## Media
- Clean up gui test md
- nio ClientTimeout
- upload delay at the end?
@ -49,7 +48,6 @@
## Issues
- last event obj
- load_past raise
- Room pane slightly overlaps chat at small width
- invisible uploaded mxc images?

View File

@ -913,7 +913,7 @@ class MatrixClient(nio.AsyncClient):
room = model[room_id]
if room.last_event is None:
room.last_event = item.serialized
room.last_event = item
if item.is_local_echo:
model.sync_now()
@ -924,7 +924,7 @@ class MatrixClient(nio.AsyncClient):
# If there were no better events available to show previously
prev_is_profile_ev = \
room.last_event["type_specifier"] == TypeSpecifier.profile_change
room.last_event.type_specifier == TypeSpecifier.profile_change
# If this is a profile event, only replace the currently shown one if
# it was also a profile event (we had nothing better to show).
@ -933,10 +933,10 @@ class MatrixClient(nio.AsyncClient):
# If this event is older than the currently shown one, only replace
# it if the previous was a profile event.
if item.date < room.last_event["date"] and not prev_is_profile_ev:
if item.date < room.last_event.date and not prev_is_profile_ev:
return
room.last_event = item.serialized
room.last_event = item
if item.is_local_echo:
model.sync_now()

View File

@ -72,8 +72,7 @@ class Room(ModelItem):
can_set_join_rules: bool = False
can_set_guest_access: bool = False
# Event.serialized
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
last_event: Optional["Event"] = field(default=None, repr=False)
def __lt__(self, other: "Room") -> bool:
"""Sort by join state, then descending last event date, then name.
@ -89,7 +88,7 @@ class Room(ModelItem):
other.inviter_id,
other.last_event["date"] if other.last_event else
other.last_event.date if other.last_event else
datetime.fromtimestamp(0),
self.display_name.lower() or self.room_id,
@ -98,7 +97,7 @@ class Room(ModelItem):
self.inviter_id,
self.last_event["date"] if self.last_event else
self.last_event.date if self.last_event else
datetime.fromtimestamp(0),
other.display_name.lower() or other.room_id,
@ -111,11 +110,22 @@ class Room(ModelItem):
return " ".join((
self.display_name,
self.topic,
re.sub(r"<.*?>", "", self.last_event["inline_content"])
re.sub(r"<.*?>", "", self.last_event.inline_content)
if self.last_event else "",
))
@property
def serialized(self) -> Dict[str, Any]:
dct = super().serialized
if self.last_event is not None:
dct["last_event"] = self.last_event.serialized
return dct
@dataclass
class Member(ModelItem):
"""A member in a matrix room."""