From 5c1e9f24da77bebdde557a312a532a4f5c857c69 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 15 Mar 2023 17:19:05 +0000 Subject: wip: call the public room callback --- synapse/storage/databases/main/room.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'synapse/storage') 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]: -- cgit 1.5.1