diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 3544ec1f..2093dc3f 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -207,6 +207,7 @@ class MatrixClient(nio.AsyncClient): for user_id in self.models[Account]: if user_id in self.models[Member, room_id]: self.models[Event, user_id, room_id][f"echo-{uuid}"] = local + self.models[Event, user_id, room_id].sync_now() await self.set_room_last_event(room_id, local) @@ -381,10 +382,15 @@ class MatrixClient(nio.AsyncClient): async def set_room_last_event(self, room_id: str, item: Event) -> None: - room = self.models[Room, self.user_id][room_id] + model = self.models[Room, self.user_id] + room = model[room_id] if room.last_event is None: room.last_event = item.serialized + + if item.is_local_echo: + model.sync_now() + return is_profile_ev = item.type_specifier == TypeSpecifier.profile_change @@ -405,6 +411,9 @@ class MatrixClient(nio.AsyncClient): room.last_event = item.serialized + if item.is_local_echo: + model.sync_now() + async def register_nio_room(self, room: nio.MatrixRoom, left: bool = False, ) -> None: diff --git a/src/python/models/model.py b/src/python/models/model.py index 52eee322..85f97a4b 100644 --- a/src/python/models/model.py +++ b/src/python/models/model.py @@ -95,8 +95,12 @@ class Model(MutableMapping): if self._changed: with self._sync_lock: log.debug("Syncing %s", self) - ModelUpdated(self.sync_id, self.serialized()) - self._changed = False + self.sync_now() + + + def sync_now(self) -> None: + ModelUpdated(self.sync_id, self.serialized()) + self._changed = False def serialized(self) -> List[Dict[str, Any]]: