1
0

Add shared_rooms api

This commit is contained in:
Will Hunt
2020-07-05 11:46:51 +01:00
parent 5cdca53aa0
commit 26634cb0d9
2 changed files with 52 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ from synapse.rest.client.v2_alpha import (
room_keys,
room_upgrade_rest_servlet,
sendtodevice,
shared_rooms,
sync,
tags,
thirdparty,
@@ -113,6 +114,7 @@ class ClientRestResource(JsonResource):
devices.register_servlets(hs, client_resource)
thirdparty.register_servlets(hs, client_resource)
sendtodevice.register_servlets(hs, client_resource)
shared_rooms.register_servlets(hs, client_resource)
user_directory.register_servlets(hs, client_resource)
groups.register_servlets(hs, client_resource)
room_upgrade_rest_servlet.register_servlets(hs, client_resource)

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Half-Shot
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from synapse.http.servlet import RestServlet
from ._base import client_patterns
logger = logging.getLogger(__name__)
class UserSharedRoomsServlet(RestServlet):
"""
GET /user/{user_id}/shared_rooms/(?P<other_user_id>[^/]*) HTTP/1.1
"""
PATTERNS = client_patterns(
"/user/(?P<user_id>[^/]*)/shared_rooms/(?P<other_user_id>[^/]*)",
releases=(), # This is an unstable feature
)
def __init__(self, hs):
super(UserSharedRoomsServlet, self).__init__()
self.auth = hs.get_auth()
self.store = hs.get_datastore()
async def on_GET(self, request, user_id, other_user_id):
requester = await self.auth.get_user_by_req(request)
if user_id != requester.user.to_string():
raise AuthError(403, "Cannot get shared rooms for other users.")
rooms = await self.store.get_rooms_in_common_for_users(user_id, other_user_id)
return 200, rooms
def register_servlets(hs, http_server):
UserSharedRoomsServlet(hs).register(http_server)