From 71885068e59d97a5fa5c4f89f7292da927e4720b Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Fri, 19 May 2023 17:33:34 +0200 Subject: [PATCH] Add changelog + stuffs --- changelog.d/15518.feature | 1 + synapse/storage/databases/main/room.py | 4 +-- tests/module_api/test_fetch_public_rooms.py | 36 +++++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 changelog.d/15518.feature diff --git a/changelog.d/15518.feature b/changelog.d/15518.feature new file mode 100644 index 0000000000..325724bad3 --- /dev/null +++ b/changelog.d/15518.feature @@ -0,0 +1 @@ +Allow modules to provide local /publicRooms results. diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index ec9691a5ce..7ecb8fb3c3 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -543,8 +543,8 @@ class RoomWorkerStore(CacheInvalidationWorkerStore): # Filter out Nones – rather omit the field altogether for key in list(entry): - if entry[key] is None: - del entry[key] + if entry[key] is None: # type: ignore[literal-required] + del entry[key] # type: ignore[misc] return entry diff --git a/tests/module_api/test_fetch_public_rooms.py b/tests/module_api/test_fetch_public_rooms.py index 0d77cf6f74..7543fa96de 100644 --- a/tests/module_api/test_fetch_public_rooms.py +++ b/tests/module_api/test_fetch_public_rooms.py @@ -64,12 +64,25 @@ class FetchPublicRoomsTestCase(HomeserverTestCase): world_readable=True, guest_can_join=False, ) - if limit is not None and limit < 3 and bounds is not None: + room3_2 = PublicRoom( + room_id="!test3_2:test", + num_joined_members=3, + world_readable=True, + guest_can_join=False, + ) + rooms = [room3_2, room3, room1] + if not forwards: + rooms.reverse() + + if limit is not None: + if bounds is None: + return rooms[:limit] + (last_joined_members, last_room_id) = bounds - if last_joined_members < 3 or last_room_id == room3["room_id"]: + if last_joined_members < 3 or last_room_id == room3_2["room_id"]: return [room1] - return [room3, room1] + return [room3_2, room3, room1] self._module_api.register_public_rooms_callbacks(fetch_public_rooms=cb) @@ -92,15 +105,26 @@ class FetchPublicRoomsTestCase(HomeserverTestCase): channel = self.make_request("GET", self.url) self.assertEqual(channel.code, HTTPStatus.OK, channel.result) - self.assertEquals(len(channel.json_body["chunk"]), 3) + self.assertEquals(len(channel.json_body["chunk"]), 4) self.assertEquals(channel.json_body["chunk"][0]["num_joined_members"], 3) - self.assertEquals(channel.json_body["chunk"][1]["num_joined_members"], 2) - self.assertEquals(channel.json_body["chunk"][2]["num_joined_members"], 1) + self.assertEquals(channel.json_body["chunk"][1]["num_joined_members"], 3) + self.assertEquals(channel.json_body["chunk"][2]["num_joined_members"], 2) + self.assertEquals(channel.json_body["chunk"][3]["num_joined_members"], 1) def test_pagination(self) -> None: channel = self.make_request("GET", self.url + "?limit=1") self.assertEqual(channel.code, HTTPStatus.OK, channel.result) self.assertEquals(channel.json_body["chunk"][0]["num_joined_members"], 3) + returned_room3_id = channel.json_body["chunk"][0]["room_id"] + + channel = self.make_request( + "GET", self.url + "?limit=1&since=" + channel.json_body["next_batch"] + ) + self.assertEqual(channel.code, HTTPStatus.OK, channel.result) + self.assertEquals(channel.json_body["chunk"][0]["num_joined_members"], 3) + self.assertNotEquals( + returned_room3_id, channel.json_body["chunk"][0]["room_id"] + ) channel = self.make_request( "GET", self.url + "?limit=1&since=" + channel.json_body["next_batch"]