mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-29 07:28:55 +03:00
Rename shared_rooms to mutual_rooms (#12036)
Co-authored-by: reivilibre <olivier@librepush.net>
This commit is contained in:
parent
831d4797ab
commit
516d092ff9
5 changed files with 27 additions and 25 deletions
1
changelog.d/12036.misc
Normal file
1
changelog.d/12036.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Rename `shared_rooms` to `mutual_rooms` (MSC2666), as per proposal changes.
|
|
@ -32,6 +32,7 @@ from synapse.rest.client import (
|
||||||
knock,
|
knock,
|
||||||
login as v1_login,
|
login as v1_login,
|
||||||
logout,
|
logout,
|
||||||
|
mutual_rooms,
|
||||||
notifications,
|
notifications,
|
||||||
openid,
|
openid,
|
||||||
password_policy,
|
password_policy,
|
||||||
|
@ -49,7 +50,6 @@ from synapse.rest.client import (
|
||||||
room_keys,
|
room_keys,
|
||||||
room_upgrade_rest_servlet,
|
room_upgrade_rest_servlet,
|
||||||
sendtodevice,
|
sendtodevice,
|
||||||
shared_rooms,
|
|
||||||
sync,
|
sync,
|
||||||
tags,
|
tags,
|
||||||
thirdparty,
|
thirdparty,
|
||||||
|
@ -132,4 +132,4 @@ class ClientRestResource(JsonResource):
|
||||||
admin.register_servlets_for_client_rest_resource(hs, client_resource)
|
admin.register_servlets_for_client_rest_resource(hs, client_resource)
|
||||||
|
|
||||||
# unstable
|
# unstable
|
||||||
shared_rooms.register_servlets(hs, client_resource)
|
mutual_rooms.register_servlets(hs, client_resource)
|
||||||
|
|
|
@ -28,13 +28,13 @@ if TYPE_CHECKING:
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UserSharedRoomsServlet(RestServlet):
|
class UserMutualRoomsServlet(RestServlet):
|
||||||
"""
|
"""
|
||||||
GET /uk.half-shot.msc2666/user/shared_rooms/{user_id} HTTP/1.1
|
GET /uk.half-shot.msc2666/user/mutual_rooms/{user_id} HTTP/1.1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PATTERNS = client_patterns(
|
PATTERNS = client_patterns(
|
||||||
"/uk.half-shot.msc2666/user/shared_rooms/(?P<user_id>[^/]*)",
|
"/uk.half-shot.msc2666/user/mutual_rooms/(?P<user_id>[^/]*)",
|
||||||
releases=(), # This is an unstable feature
|
releases=(), # This is an unstable feature
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,7 +64,8 @@ class UserSharedRoomsServlet(RestServlet):
|
||||||
msg="You cannot request a list of shared rooms with yourself",
|
msg="You cannot request a list of shared rooms with yourself",
|
||||||
errcode=Codes.FORBIDDEN,
|
errcode=Codes.FORBIDDEN,
|
||||||
)
|
)
|
||||||
rooms = await self.store.get_shared_rooms_for_users(
|
|
||||||
|
rooms = await self.store.get_mutual_rooms_for_users(
|
||||||
requester.user.to_string(), user_id
|
requester.user.to_string(), user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,4 +73,4 @@ class UserSharedRoomsServlet(RestServlet):
|
||||||
|
|
||||||
|
|
||||||
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
|
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
|
||||||
UserSharedRoomsServlet(hs).register(http_server)
|
UserMutualRoomsServlet(hs).register(http_server)
|
|
@ -730,7 +730,7 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore):
|
||||||
users.update(rows)
|
users.update(rows)
|
||||||
return list(users)
|
return list(users)
|
||||||
|
|
||||||
async def get_shared_rooms_for_users(
|
async def get_mutual_rooms_for_users(
|
||||||
self, user_id: str, other_user_id: str
|
self, user_id: str, other_user_id: str
|
||||||
) -> Set[str]:
|
) -> Set[str]:
|
||||||
"""
|
"""
|
||||||
|
@ -744,7 +744,7 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore):
|
||||||
A set of room ID's that the users share.
|
A set of room ID's that the users share.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_shared_rooms_for_users_txn(
|
def _get_mutual_rooms_for_users_txn(
|
||||||
txn: LoggingTransaction,
|
txn: LoggingTransaction,
|
||||||
) -> List[Dict[str, str]]:
|
) -> List[Dict[str, str]]:
|
||||||
txn.execute(
|
txn.execute(
|
||||||
|
@ -768,7 +768,7 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore):
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
rows = await self.db_pool.runInteraction(
|
rows = await self.db_pool.runInteraction(
|
||||||
"get_shared_rooms_for_users", _get_shared_rooms_for_users_txn
|
"get_mutual_rooms_for_users", _get_mutual_rooms_for_users_txn
|
||||||
)
|
)
|
||||||
|
|
||||||
return {row["room_id"] for row in rows}
|
return {row["room_id"] for row in rows}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
from twisted.test.proto_helpers import MemoryReactor
|
from twisted.test.proto_helpers import MemoryReactor
|
||||||
|
|
||||||
import synapse.rest.admin
|
import synapse.rest.admin
|
||||||
from synapse.rest.client import login, room, shared_rooms
|
from synapse.rest.client import login, mutual_rooms, room
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
from synapse.util import Clock
|
from synapse.util import Clock
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ from tests import unittest
|
||||||
from tests.server import FakeChannel
|
from tests.server import FakeChannel
|
||||||
|
|
||||||
|
|
||||||
class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
class UserMutualRoomsTest(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Tests the UserSharedRoomsServlet.
|
Tests the UserMutualRoomsServlet.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
servlets = [
|
servlets = [
|
||||||
login.register_servlets,
|
login.register_servlets,
|
||||||
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
||||||
room.register_servlets,
|
room.register_servlets,
|
||||||
shared_rooms.register_servlets,
|
mutual_rooms.register_servlets,
|
||||||
]
|
]
|
||||||
|
|
||||||
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
||||||
|
@ -43,10 +43,10 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.store = hs.get_datastores().main
|
self.store = hs.get_datastores().main
|
||||||
self.handler = hs.get_user_directory_handler()
|
self.handler = hs.get_user_directory_handler()
|
||||||
|
|
||||||
def _get_shared_rooms(self, token: str, other_user: str) -> FakeChannel:
|
def _get_mutual_rooms(self, token: str, other_user: str) -> FakeChannel:
|
||||||
return self.make_request(
|
return self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/%s"
|
"/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/%s"
|
||||||
% other_user,
|
% other_user,
|
||||||
access_token=token,
|
access_token=token,
|
||||||
)
|
)
|
||||||
|
@ -56,14 +56,14 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
A room should show up in the shared list of rooms between two users
|
A room should show up in the shared list of rooms between two users
|
||||||
if it is public.
|
if it is public.
|
||||||
"""
|
"""
|
||||||
self._check_shared_rooms_with(room_one_is_public=True, room_two_is_public=True)
|
self._check_mutual_rooms_with(room_one_is_public=True, room_two_is_public=True)
|
||||||
|
|
||||||
def test_shared_room_list_private(self) -> None:
|
def test_shared_room_list_private(self) -> None:
|
||||||
"""
|
"""
|
||||||
A room should show up in the shared list of rooms between two users
|
A room should show up in the shared list of rooms between two users
|
||||||
if it is private.
|
if it is private.
|
||||||
"""
|
"""
|
||||||
self._check_shared_rooms_with(
|
self._check_mutual_rooms_with(
|
||||||
room_one_is_public=False, room_two_is_public=False
|
room_one_is_public=False, room_two_is_public=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
The shared room list between two users should contain both public and private
|
The shared room list between two users should contain both public and private
|
||||||
rooms.
|
rooms.
|
||||||
"""
|
"""
|
||||||
self._check_shared_rooms_with(room_one_is_public=True, room_two_is_public=False)
|
self._check_mutual_rooms_with(room_one_is_public=True, room_two_is_public=False)
|
||||||
|
|
||||||
def _check_shared_rooms_with(
|
def _check_mutual_rooms_with(
|
||||||
self, room_one_is_public: bool, room_two_is_public: bool
|
self, room_one_is_public: bool, room_two_is_public: bool
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Checks that shared public or private rooms between two users appear in
|
"""Checks that shared public or private rooms between two users appear in
|
||||||
|
@ -94,7 +94,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Check shared rooms from user1's perspective.
|
# Check shared rooms from user1's perspective.
|
||||||
# We should see the one room in common
|
# We should see the one room in common
|
||||||
channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_mutual_rooms(u1_token, u2)
|
||||||
self.assertEqual(200, channel.code, channel.result)
|
self.assertEqual(200, channel.code, channel.result)
|
||||||
self.assertEqual(len(channel.json_body["joined"]), 1)
|
self.assertEqual(len(channel.json_body["joined"]), 1)
|
||||||
self.assertEqual(channel.json_body["joined"][0], room_id_one)
|
self.assertEqual(channel.json_body["joined"][0], room_id_one)
|
||||||
|
@ -107,7 +107,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room_id_two, user=u2, tok=u2_token)
|
self.helper.join(room_id_two, user=u2, tok=u2_token)
|
||||||
|
|
||||||
# Check shared rooms again. We should now see both rooms.
|
# Check shared rooms again. We should now see both rooms.
|
||||||
channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_mutual_rooms(u1_token, u2)
|
||||||
self.assertEqual(200, channel.code, channel.result)
|
self.assertEqual(200, channel.code, channel.result)
|
||||||
self.assertEqual(len(channel.json_body["joined"]), 2)
|
self.assertEqual(len(channel.json_body["joined"]), 2)
|
||||||
for room_id_id in channel.json_body["joined"]:
|
for room_id_id in channel.json_body["joined"]:
|
||||||
|
@ -128,7 +128,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room, user=u2, tok=u2_token)
|
self.helper.join(room, user=u2, tok=u2_token)
|
||||||
|
|
||||||
# Assert user directory is not empty
|
# Assert user directory is not empty
|
||||||
channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_mutual_rooms(u1_token, u2)
|
||||||
self.assertEqual(200, channel.code, channel.result)
|
self.assertEqual(200, channel.code, channel.result)
|
||||||
self.assertEqual(len(channel.json_body["joined"]), 1)
|
self.assertEqual(len(channel.json_body["joined"]), 1)
|
||||||
self.assertEqual(channel.json_body["joined"][0], room)
|
self.assertEqual(channel.json_body["joined"][0], room)
|
||||||
|
@ -136,11 +136,11 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.leave(room, user=u1, tok=u1_token)
|
self.helper.leave(room, user=u1, tok=u1_token)
|
||||||
|
|
||||||
# Check user1's view of shared rooms with user2
|
# Check user1's view of shared rooms with user2
|
||||||
channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_mutual_rooms(u1_token, u2)
|
||||||
self.assertEqual(200, channel.code, channel.result)
|
self.assertEqual(200, channel.code, channel.result)
|
||||||
self.assertEqual(len(channel.json_body["joined"]), 0)
|
self.assertEqual(len(channel.json_body["joined"]), 0)
|
||||||
|
|
||||||
# Check user2's view of shared rooms with user1
|
# Check user2's view of shared rooms with user1
|
||||||
channel = self._get_shared_rooms(u2_token, u1)
|
channel = self._get_mutual_rooms(u2_token, u1)
|
||||||
self.assertEqual(200, channel.code, channel.result)
|
self.assertEqual(200, channel.code, channel.result)
|
||||||
self.assertEqual(len(channel.json_body["joined"]), 0)
|
self.assertEqual(len(channel.json_body["joined"]), 0)
|
Loading…
Reference in a new issue