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:
|
for chat in updates.chats:
|
||||||
portal = po.Portal.get_by_entity(chat)
|
portal = po.Portal.get_by_entity(chat)
|
||||||
if portal.mxid:
|
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])
|
await portal.invite_matrix([evt.sender.mxid])
|
||||||
return await evt.reply(f"Invited you to portal of {portal.title}")
|
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()
|
@command_handler()
|
||||||
|
|||||||
@@ -360,10 +360,18 @@ class Portal:
|
|||||||
return chat.users, chat.full_chat.participants.participants
|
return chat.users, chat.full_chat.participants.participants
|
||||||
elif self.peer_type == "channel":
|
elif self.peer_type == "channel":
|
||||||
try:
|
try:
|
||||||
participants = await user.client(GetParticipantsRequest(
|
users, participants = [], []
|
||||||
entity, ChannelParticipantsRecent(), offset=0, limit=100, hash=0
|
offset = 0
|
||||||
))
|
while True:
|
||||||
return participants.users, participants.participants
|
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:
|
except ChatAdminRequiredError:
|
||||||
return [], []
|
return [], []
|
||||||
elif self.peer_type == "user":
|
elif self.peer_type == "user":
|
||||||
@@ -986,6 +994,11 @@ class Portal:
|
|||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
def delete(self):
|
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.delete(self.to_db())
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user