mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-05-28 09:32:11 -04:00
Directly lookup local membership instead of getting all members in a room first (get_users_in_room
mis-use) (#13608)
See https://github.com/matrix-org/synapse/pull/13575#discussion_r953023755
This commit is contained in:
parent
b93bd95e8a
commit
d58615c82c
8 changed files with 60 additions and 17 deletions
|
@ -534,6 +534,32 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||
desc="get_local_users_in_room",
|
||||
)
|
||||
|
||||
async def check_local_user_in_room(self, user_id: str, room_id: str) -> bool:
|
||||
"""
|
||||
Check whether a given local user is currently joined to the given room.
|
||||
|
||||
Returns:
|
||||
A boolean indicating whether the user is currently joined to the room
|
||||
|
||||
Raises:
|
||||
Exeption when called with a non-local user to this homeserver
|
||||
"""
|
||||
if not self.hs.is_mine_id(user_id):
|
||||
raise Exception(
|
||||
"Cannot call 'check_local_user_in_room' on "
|
||||
"non-local user %s" % (user_id,),
|
||||
)
|
||||
|
||||
(
|
||||
membership,
|
||||
member_event_id,
|
||||
) = await self.get_local_current_membership_for_user_in_room(
|
||||
user_id=user_id,
|
||||
room_id=room_id,
|
||||
)
|
||||
|
||||
return membership == Membership.JOIN
|
||||
|
||||
async def get_local_current_membership_for_user_in_room(
|
||||
self, user_id: str, room_id: str
|
||||
) -> Tuple[Optional[str], Optional[str]]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue