Trigger model sync ASAP when creating local echoes

This commit is contained in:
miruka 2019-08-31 16:13:50 -04:00
parent 28d8721fe2
commit 69ed35d4dd
2 changed files with 16 additions and 3 deletions

View File

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

View File

@ -95,6 +95,10 @@ class Model(MutableMapping):
if self._changed:
with self._sync_lock:
log.debug("Syncing %s", self)
self.sync_now()
def sync_now(self) -> None:
ModelUpdated(self.sync_id, self.serialized())
self._changed = False