summary refs log tree commit diff
diff options
context:
space:
mode:
authorHalf-Shot <will@half-shot.uk>2019-11-15 01:22:05 +0000
committerWill Hunt <will@half-shot.uk>2019-11-15 01:37:31 +0000
commit7ab9f44b5a2ca9a2ef112f468456a8d9cf4ba1c3 (patch)
tree38835990efb4198d6ece163b76838449164ec72c
parentAdd optional python dependencies to snap packaging (#6317) (diff)
downloadsynapse-7ab9f44b5a2ca9a2ef112f468456a8d9cf4ba1c3.tar.xz
Add many joined members Servlet
-rw-r--r--synapse/rest/client/v1/room.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/synapse/rest/client/v1/room.py b/synapse/rest/client/v1/room.py
index 86bbcc0eea..38632c7234 100644
--- a/synapse/rest/client/v1/room.py
+++ b/synapse/rest/client/v1/room.py
@@ -487,6 +487,33 @@ class JoinedRoomMemberListRestServlet(RestServlet):
 
         return 200, {"joined": users_with_profile}
 
+class JoinedManyRoomMemberListRestServlet(RestServlet):
+    PATTERNS = client_patterns("/rooms/joined_members$", v1=True)
+
+    def __init__(self, hs):
+        super(JoinedManyRoomMemberListRestServlet, self).__init__()
+        self.message_handler = hs.get_message_handler()
+        self.auth = hs.get_auth()
+
+    async def on_POST(self, request):
+        requester = await self.auth.get_user_by_req(request)
+
+        content = parse_json_object_from_request(request)
+
+        if content.get("rooms", None) is None:
+            raise SynapseError(400, "'rooms' not given in request body.", errcode=Codes.BAD_JSON)    
+
+        result = {}
+
+        for room_id in set(content["rooms"]):
+            if not isinstance(room_id, str):
+                raise SynapseError(400, "Invalid room_id given.", errcode=Codes.BAD_JSON)    
+            result[room_id] = await self.message_handler.get_joined_members(
+                requester, room_id
+            )
+
+        return 200, {"rooms": result}
+
 
 # TODO: Needs better unit testing
 class RoomMessageListRestServlet(RestServlet):
@@ -900,6 +927,7 @@ def register_servlets(hs, http_server):
     RoomCreateRestServlet(hs).register(http_server)
     RoomMemberListRestServlet(hs).register(http_server)
     JoinedRoomMemberListRestServlet(hs).register(http_server)
+    JoinedManyRoomMemberListRestServlet(hs).register(http_server)
     RoomMessageListRestServlet(hs).register(http_server)
     JoinRoomAliasServlet(hs).register(http_server)
     RoomForgetRestServlet(hs).register(http_server)