Trigger model sync ASAP when creating local echoes
This commit is contained in:
parent
28d8721fe2
commit
69ed35d4dd
|
@ -207,6 +207,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
for user_id in self.models[Account]:
|
for user_id in self.models[Account]:
|
||||||
if user_id in self.models[Member, room_id]:
|
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][f"echo-{uuid}"] = local
|
||||||
|
self.models[Event, user_id, room_id].sync_now()
|
||||||
|
|
||||||
await self.set_room_last_event(room_id, local)
|
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:
|
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:
|
if room.last_event is None:
|
||||||
room.last_event = item.serialized
|
room.last_event = item.serialized
|
||||||
|
|
||||||
|
if item.is_local_echo:
|
||||||
|
model.sync_now()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
is_profile_ev = item.type_specifier == TypeSpecifier.profile_change
|
is_profile_ev = item.type_specifier == TypeSpecifier.profile_change
|
||||||
|
@ -405,6 +411,9 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
room.last_event = item.serialized
|
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,
|
async def register_nio_room(self, room: nio.MatrixRoom, left: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
|
@ -95,8 +95,12 @@ class Model(MutableMapping):
|
||||||
if self._changed:
|
if self._changed:
|
||||||
with self._sync_lock:
|
with self._sync_lock:
|
||||||
log.debug("Syncing %s", self)
|
log.debug("Syncing %s", self)
|
||||||
ModelUpdated(self.sync_id, self.serialized())
|
self.sync_now()
|
||||||
self._changed = False
|
|
||||||
|
|
||||||
|
def sync_now(self) -> None:
|
||||||
|
ModelUpdated(self.sync_id, self.serialized())
|
||||||
|
self._changed = False
|
||||||
|
|
||||||
|
|
||||||
def serialized(self) -> List[Dict[str, Any]]:
|
def serialized(self) -> List[Dict[str, Any]]:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user