diff --git a/mautrix_telegram/commands/telegram.py b/mautrix_telegram/commands/telegram.py index 7b2859b6..d28abce2 100644 --- a/mautrix_telegram/commands/telegram.py +++ b/mautrix_telegram/commands/telegram.py @@ -130,7 +130,7 @@ async def sync(evt): sync_only = None 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": await evt.sender.sync_contacts() if not sync_only or sync_only == "me": diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index a22101b0..eab47a81 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -210,14 +210,16 @@ class Portal: await puppet.update_info(user, entity) 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 update_if_exists: if not entity: entity = await user.client.get_entity(self.peer) - asyncio.ensure_future( - self.update_matrix_room(user, entity, self.peer_type == "user"), - loop=self.loop) + update = self.update_matrix_room(user, entity, self.peer_type == "user") + if synchronous: + await update + else: + asyncio.ensure_future(update, loop=self.loop) await self.invite_to_matrix(invites or []) return self.mxid async with self._room_create_lock: diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 32362a68..d9bb5891 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -223,12 +223,13 @@ class User(AbstractUser): return await self._search_remote(query), True - async def sync_dialogs(self): + async def sync_dialogs(self, synchronous_create=False): creators = [] for entity in await self._get_dialogs(limit=30): portal = po.Portal.get_by_entity(entity) 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() await asyncio.gather(*creators, loop=self.loop)