Room.last_event: be an Event instead of dict
This commit is contained in:
parent
cdd119405e
commit
aaa8411cb9
2
TODO.md
2
TODO.md
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
## Media
|
## Media
|
||||||
|
|
||||||
- Clean up gui test md
|
|
||||||
- nio ClientTimeout
|
- nio ClientTimeout
|
||||||
|
|
||||||
- upload delay at the end?
|
- upload delay at the end?
|
||||||
|
@ -49,7 +48,6 @@
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
|
|
||||||
- last event obj
|
|
||||||
- load_past raise
|
- load_past raise
|
||||||
- Room pane slightly overlaps chat at small width
|
- Room pane slightly overlaps chat at small width
|
||||||
- invisible uploaded mxc images?
|
- invisible uploaded mxc images?
|
||||||
|
|
|
@ -913,7 +913,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
room = model[room_id]
|
room = model[room_id]
|
||||||
|
|
||||||
if room.last_event is None:
|
if room.last_event is None:
|
||||||
room.last_event = item.serialized
|
room.last_event = item
|
||||||
|
|
||||||
if item.is_local_echo:
|
if item.is_local_echo:
|
||||||
model.sync_now()
|
model.sync_now()
|
||||||
|
@ -924,7 +924,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
# If there were no better events available to show previously
|
# If there were no better events available to show previously
|
||||||
prev_is_profile_ev = \
|
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
|
# 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).
|
# 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
|
# If this event is older than the currently shown one, only replace
|
||||||
# it if the previous was a profile event.
|
# 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
|
return
|
||||||
|
|
||||||
room.last_event = item.serialized
|
room.last_event = item
|
||||||
|
|
||||||
if item.is_local_echo:
|
if item.is_local_echo:
|
||||||
model.sync_now()
|
model.sync_now()
|
||||||
|
|
|
@ -72,8 +72,7 @@ class Room(ModelItem):
|
||||||
can_set_join_rules: bool = False
|
can_set_join_rules: bool = False
|
||||||
can_set_guest_access: bool = False
|
can_set_guest_access: bool = False
|
||||||
|
|
||||||
# Event.serialized
|
last_event: Optional["Event"] = field(default=None, repr=False)
|
||||||
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
|
|
||||||
|
|
||||||
def __lt__(self, other: "Room") -> bool:
|
def __lt__(self, other: "Room") -> bool:
|
||||||
"""Sort by join state, then descending last event date, then name.
|
"""Sort by join state, then descending last event date, then name.
|
||||||
|
@ -89,7 +88,7 @@ class Room(ModelItem):
|
||||||
|
|
||||||
other.inviter_id,
|
other.inviter_id,
|
||||||
|
|
||||||
other.last_event["date"] if other.last_event else
|
other.last_event.date if other.last_event else
|
||||||
datetime.fromtimestamp(0),
|
datetime.fromtimestamp(0),
|
||||||
|
|
||||||
self.display_name.lower() or self.room_id,
|
self.display_name.lower() or self.room_id,
|
||||||
|
@ -98,7 +97,7 @@ class Room(ModelItem):
|
||||||
|
|
||||||
self.inviter_id,
|
self.inviter_id,
|
||||||
|
|
||||||
self.last_event["date"] if self.last_event else
|
self.last_event.date if self.last_event else
|
||||||
datetime.fromtimestamp(0),
|
datetime.fromtimestamp(0),
|
||||||
|
|
||||||
other.display_name.lower() or other.room_id,
|
other.display_name.lower() or other.room_id,
|
||||||
|
@ -111,11 +110,22 @@ class Room(ModelItem):
|
||||||
return " ".join((
|
return " ".join((
|
||||||
self.display_name,
|
self.display_name,
|
||||||
self.topic,
|
self.topic,
|
||||||
re.sub(r"<.*?>", "", self.last_event["inline_content"])
|
re.sub(r"<.*?>", "", self.last_event.inline_content)
|
||||||
if self.last_event else "",
|
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
|
@dataclass
|
||||||
class Member(ModelItem):
|
class Member(ModelItem):
|
||||||
"""A member in a matrix room."""
|
"""A member in a matrix room."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user