Wait for sync to complete when running sync explicitly

This commit is contained in:
Tulir Asokan
2018-04-28 22:01:29 +03:00
parent 445d997be8
commit 193dcc714b
3 changed files with 10 additions and 7 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ async def sync(evt):
sync_only = None sync_only = None
if not sync_only or sync_only == "chats": if not sync_only or sync_only == "chats":
await evt.sender.sync_dialogs() await evt.sender.sync_dialogs(synchronous_create=True)
if not sync_only or sync_only == "contacts": if not sync_only or sync_only == "contacts":
await evt.sender.sync_contacts() await evt.sender.sync_contacts()
if not sync_only or sync_only == "me": if not sync_only or sync_only == "me":
+6 -4
View File
@@ -210,14 +210,16 @@ class Portal:
await puppet.update_info(user, entity) await puppet.update_info(user, entity)
await puppet.intent.join_room(self.mxid) await puppet.intent.join_room(self.mxid)
async def create_matrix_room(self, user, entity=None, invites=None, update_if_exists=True): async def create_matrix_room(self, user, entity=None, invites=None, update_if_exists=True, synchronous=False):
if self.mxid: if self.mxid:
if update_if_exists: if update_if_exists:
if not entity: if not entity:
entity = await user.client.get_entity(self.peer) entity = await user.client.get_entity(self.peer)
asyncio.ensure_future( update = self.update_matrix_room(user, entity, self.peer_type == "user")
self.update_matrix_room(user, entity, self.peer_type == "user"), if synchronous:
loop=self.loop) await update
else:
asyncio.ensure_future(update, loop=self.loop)
await self.invite_to_matrix(invites or []) await self.invite_to_matrix(invites or [])
return self.mxid return self.mxid
async with self._room_create_lock: async with self._room_create_lock:
+3 -2
View File
@@ -223,12 +223,13 @@ class User(AbstractUser):
return await self._search_remote(query), True return await self._search_remote(query), True
async def sync_dialogs(self): async def sync_dialogs(self, synchronous_create=False):
creators = [] creators = []
for entity in await self._get_dialogs(limit=30): for entity in await self._get_dialogs(limit=30):
portal = po.Portal.get_by_entity(entity) portal = po.Portal.get_by_entity(entity)
self.portals[portal.tgid_full] = portal self.portals[portal.tgid_full] = portal
creators.append(portal.create_matrix_room(self, entity, invites=[self.mxid])) creators.append(
portal.create_matrix_room(self, entity, invites=[self.mxid], synchronous=synchronous_create))
self.save() self.save()
await asyncio.gather(*creators, loop=self.loop) await asyncio.gather(*creators, loop=self.loop)