Synchronize all users and fix joining chats via invite links, deleting portals
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user