Allow inviting more than 10 people to a room

This commit is contained in:
Panoramic 2024-07-25 17:58:44 +03:00
parent d4c7587cf3
commit b22196ca48
1 changed files with 25 additions and 1 deletions

View File

@ -9,6 +9,7 @@ from nio import (
MegolmEvent,
RoomCreateError,
RoomGetEventError,
RoomInviteError,
RoomMessagesError,
RoomMessageText,
RoomPutStateResponse,
@ -199,9 +200,13 @@ class Command:
"content": {"history_visibility": "shared"},
},
]
# Max amount of users to invite is 10 here:
invitee_chunks = divide_chunks(invitees, 10)
room_resp = await self.client.room_create(
name=f"Vetting {random_string}",
invite=invitees,
invite=next(invitee_chunks),
initial_state=initial_state,
)
@ -211,6 +216,18 @@ class Command:
logging.error(text, stack_info=True)
return
# Invite more people
for chunk in invitee_chunks:
for mxid in chunk:
invite_resp = await self.client.room_invite(room_resp.room_id, mxid)
if isinstance(invite_resp, RoomInviteError):
text = (
f"Unable to invite {mxid} to newly created room: {invite_resp}"
)
await send_text_to_room(self.client, self.room.room_id, text)
logging.error(text, stack_info=True)
# Create new vetting entry
self.store.cursor.execute(
"INSERT INTO vetting (mxid, room_id, vetting_create_time) VALUES (?, ?, ?)",
@ -483,3 +500,10 @@ def validate_user_id(user_id):
)
is not None
)
# Yield successive n-sized chunks from l.
def divide_chunks(l, n: int):
# looping till length l
for i in range(0, len(l), n):
yield l[i : i + n]