Allow inviting more than 10 people to a room
This commit is contained in:
parent
d4c7587cf3
commit
b22196ca48
|
@ -9,6 +9,7 @@ from nio import (
|
||||||
MegolmEvent,
|
MegolmEvent,
|
||||||
RoomCreateError,
|
RoomCreateError,
|
||||||
RoomGetEventError,
|
RoomGetEventError,
|
||||||
|
RoomInviteError,
|
||||||
RoomMessagesError,
|
RoomMessagesError,
|
||||||
RoomMessageText,
|
RoomMessageText,
|
||||||
RoomPutStateResponse,
|
RoomPutStateResponse,
|
||||||
|
@ -199,9 +200,13 @@ class Command:
|
||||||
"content": {"history_visibility": "shared"},
|
"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(
|
room_resp = await self.client.room_create(
|
||||||
name=f"Vetting {random_string}",
|
name=f"Vetting {random_string}",
|
||||||
invite=invitees,
|
invite=next(invitee_chunks),
|
||||||
initial_state=initial_state,
|
initial_state=initial_state,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -211,6 +216,18 @@ class Command:
|
||||||
logging.error(text, stack_info=True)
|
logging.error(text, stack_info=True)
|
||||||
return
|
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
|
# Create new vetting entry
|
||||||
self.store.cursor.execute(
|
self.store.cursor.execute(
|
||||||
"INSERT INTO vetting (mxid, room_id, vetting_create_time) VALUES (?, ?, ?)",
|
"INSERT INTO vetting (mxid, room_id, vetting_create_time) VALUES (?, ?, ?)",
|
||||||
|
@ -483,3 +500,10 @@ def validate_user_id(user_id):
|
||||||
)
|
)
|
||||||
is not None
|
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]
|
||||||
|
|
Loading…
Reference in New Issue