From 1a1d7e6d900bb9b56433a97a0041f2315ffe2b1a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 19 Feb 2018 18:10:14 +0200 Subject: [PATCH] Synchronize all users and fix joining chats via invite links, deleting portals --- mautrix_telegram/commands/telegram.py | 7 ++++--- mautrix_telegram/portal.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/mautrix_telegram/commands/telegram.py b/mautrix_telegram/commands/telegram.py index f77c2110..cb1f0b17 100644 --- a/mautrix_telegram/commands/telegram.py +++ b/mautrix_telegram/commands/telegram.py @@ -151,11 +151,12 @@ async def join(evt): for chat in updates.chats: portal = po.Portal.get_by_entity(chat) if portal.mxid: - await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid]) - return await evt.reply(f"Created room for {portal.title}") - else: await portal.invite_matrix([evt.sender.mxid]) return await evt.reply(f"Invited you to portal of {portal.title}") + else: + await evt.reply(f"Creating room for {chat.title}... This might take a while.") + await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid]) + return await evt.reply(f"Created room for {portal.title}") @command_handler() diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index f7290287..6a65aede 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -360,10 +360,18 @@ class Portal: return chat.users, chat.full_chat.participants.participants elif self.peer_type == "channel": try: - participants = await user.client(GetParticipantsRequest( - entity, ChannelParticipantsRecent(), offset=0, limit=100, hash=0 - )) - return participants.users, participants.participants + users, participants = [], [] + offset = 0 + while True: + response = await user.client(GetParticipantsRequest( + entity, ChannelParticipantsSearch(""), offset=offset, limit=100, hash=0 + )) + if not response.users: + break + participants += response.participants + users += response.users + offset += len(response.users) + return users, participants except ChatAdminRequiredError: return [], [] elif self.peer_type == "user": @@ -986,6 +994,11 @@ class Portal: self.db.commit() def delete(self): + try: + del self.by_tgid[self.tgid_full] + del self.by_mxid[self.mxid] + except KeyError: + pass self.db.delete(self.to_db()) self.db.commit()