diff options
author | Mathieu Velten <mathieuv@matrix.org> | 2023-05-22 18:32:32 +0200 |
---|---|---|
committer | Mathieu Velten <mathieuv@matrix.org> | 2023-05-22 18:32:32 +0200 |
commit | 7709a99e6ffe690abe9dd6999bf09f6f1ad7d32f (patch) | |
tree | 28fe836e8164c172826df1d1fc4b4175c2f2b79c | |
parent | use attrs class (diff) | |
download | synapse-7709a99e6ffe690abe9dd6999bf09f6f1ad7d32f.tar.xz |
Fix order
-rw-r--r-- | synapse/handlers/room_list.py | 1 | ||||
-rw-r--r-- | synapse/module_api/callbacks/public_rooms_callbacks.py | 4 | ||||
-rw-r--r-- | tests/module_api/test_fetch_public_rooms.py | 68 |
3 files changed, 41 insertions, 32 deletions
diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index f759c2888b..6c821669b0 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -189,6 +189,7 @@ class RoomListHandler: if batch_token else None, ) + module_public_rooms.reverse() # Insert the module's reported public rooms into the list for new_room in module_public_rooms: diff --git a/synapse/module_api/callbacks/public_rooms_callbacks.py b/synapse/module_api/callbacks/public_rooms_callbacks.py index 88f996b684..9934f70c27 100644 --- a/synapse/module_api/callbacks/public_rooms_callbacks.py +++ b/synapse/module_api/callbacks/public_rooms_callbacks.py @@ -13,7 +13,7 @@ # limitations under the License. import logging -from typing import Awaitable, Callable, Iterable, List, Optional, Tuple +from typing import Awaitable, Callable, List, Optional, Tuple from synapse.types import PublicRoom @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) # Types for callbacks to be registered via the module api FETCH_PUBLIC_ROOMS_CALLBACK = Callable[ [bool, Optional[int], Optional[Tuple[int, str]]], - Awaitable[Iterable[PublicRoom]], + Awaitable[List[PublicRoom]], ] diff --git a/tests/module_api/test_fetch_public_rooms.py b/tests/module_api/test_fetch_public_rooms.py index dacc05ac5f..bee351f29e 100644 --- a/tests/module_api/test_fetch_public_rooms.py +++ b/tests/module_api/test_fetch_public_rooms.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from http import HTTPStatus -from typing import Iterable, Optional, Tuple +from typing import List, Optional, Tuple from twisted.test.proto_helpers import MemoryReactor @@ -47,38 +47,46 @@ class FetchPublicRoomsTestCase(HomeserverTestCase): async def cb( forwards: bool, limit: Optional[int], bounds: Optional[Tuple[int, str]] - ) -> Iterable[PublicRoom]: - room1 = PublicRoom( - room_id="!test1:test", - num_joined_members=1, - world_readable=True, - guest_can_join=False, - ) - room3 = PublicRoom( - room_id="!test3:test", - num_joined_members=3, - world_readable=True, - guest_can_join=False, - ) - 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() + ) -> List[PublicRoom]: + rooms_db = [ + PublicRoom( + room_id="!test1:test", + num_joined_members=1, + world_readable=True, + guest_can_join=False, + ), + PublicRoom( + room_id="!test3:test", + num_joined_members=3, + world_readable=True, + guest_can_join=False, + ), + PublicRoom( + room_id="!test3_2:test", + num_joined_members=3, + world_readable=True, + guest_can_join=False, + ), + ] + + result = [] + if limit is not None and bounds is not None: + (last_joined_members, last_room_id) = bounds + for r in rooms_db: + if r.num_joined_members <= last_joined_members: + if r.room_id == last_room_id: + break + result.append(r) + else: + result = rooms_db - if limit is not None: - if bounds is None: - return rooms[:limit] + if forwards: + result.reverse() - (last_joined_members, last_room_id) = bounds - if last_joined_members < 3 or last_room_id == room3_2.room_id: - return [room3, room1] + if limit is not None: + result = result[:limit] - return [room3_2, room3, room1] + return result self._module_api.register_public_rooms_callbacks(fetch_public_rooms=cb) |