diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2023-03-15 17:19:05 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2023-05-02 15:23:32 +0100 |
commit | 5c1e9f24da77bebdde557a312a532a4f5c857c69 (patch) | |
tree | 351fc73d2ac6f0fd072862394d28d964a30d9631 /synapse/storage | |
parent | Add a new public rooms callback class, a new fetch_public_rooms callback (diff) | |
download | synapse-5c1e9f24da77bebdde557a312a532a4f5c857c69.tar.xz |
wip: call the public room callback
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/databases/main/room.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index dd7dbb6901..d6e8f62f5b 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -16,6 +16,7 @@ import logging from abc import abstractmethod from enum import Enum +from synapse.api.constants import HistoryVisibility from typing import ( TYPE_CHECKING, AbstractSet, @@ -518,7 +519,26 @@ class RoomWorkerStore(CacheInvalidationWorkerStore): ret_val = await self.db_pool.runInteraction( "get_largest_public_rooms", _get_largest_public_rooms_txn ) - return ret_val + + def build_room_entry(room: JsonDict) -> JsonDict: + entry = { + "room_id": room["room_id"], + "name": room["name"], + "topic": room["topic"], + "canonical_alias": room["canonical_alias"], + "num_joined_members": room["joined_members"], + "avatar_url": room["avatar"], + "world_readable": room["history_visibility"] + == HistoryVisibility.WORLD_READABLE, + "guest_can_join": room["guest_access"] == "can_join", + "join_rule": room["join_rules"], + "room_type": room["room_type"], + } + + # Filter out Nones – rather omit the field altogether + return {k: v for k, v in entry.items() if v is not None} + + return [build_room_entry(r) for r in ret_val] @cached(max_entries=10000) async def is_room_blocked(self, room_id: str) -> Optional[bool]: |