2828 Membership ,
2929 RoomTypes ,
3030)
31- from synapse .api .errors import AuthError , Codes , SynapseError
31+ from synapse .api .errors import AuthError , Codes , NotFoundError , SynapseError
3232from synapse .events import EventBase
3333from synapse .events .utils import format_event_for_client_v2
3434from synapse .types import JsonDict
@@ -75,7 +75,7 @@ class _PaginationSession:
7575 processed_rooms : Set [str ]
7676
7777
78- class SpaceSummaryHandler :
78+ class RoomSummaryHandler :
7979 # The time a pagination session remains valid for.
8080 _PAGINATION_SESSION_VALIDITY_PERIOD_MS = 5 * 60 * 1000
8181
@@ -412,7 +412,7 @@ async def _get_room_hierarchy(
412412 room_entry ,
413413 children_room_entries ,
414414 inaccessible_children ,
415- ) = await self ._summarize_remote_room_hiearchy (
415+ ) = await self ._summarize_remote_room_hierarchy (
416416 queue_entry ,
417417 suggested_only ,
418418 )
@@ -724,7 +724,7 @@ async def _summarize_remote_room(
724724
725725 return results
726726
727- async def _summarize_remote_room_hiearchy (
727+ async def _summarize_remote_room_hierarchy (
728728 self , room : "_RoomQueueEntry" , suggested_only : bool
729729 ) -> Tuple [Optional ["_RoomEntry" ], Dict [str , JsonDict ], Set [str ]]:
730730 """
@@ -781,25 +781,25 @@ async def _is_local_room_accessible(
781781 self , room_id : str , requester : Optional [str ], origin : Optional [str ] = None
782782 ) -> bool :
783783 """
784- Calculate whether the room should be shown in the spaces summary .
784+ Calculate whether the room should be shown to the requester .
785785
786- It should be included if:
786+ It should return true if:
787787
788788 * The requester is joined or can join the room (per MSC3173).
789789 * The origin server has any user that is joined or can join the room.
790790 * The history visibility is set to world readable.
791791
792792 Args:
793- room_id: The room ID to summarize .
793+ room_id: The room ID to check accessibility of .
794794 requester:
795- The user requesting the summary , if it is a local request. None
796- if this is a federation request.
795+ The user making the request , if it is a local request.
796+ None if this is a federation request.
797797 origin:
798- The server requesting the summary , if it is a federation request.
798+ The server making the request , if it is a federation request.
799799 None if this is a local request.
800800
801801 Returns:
802- True if the room should be included in the spaces summary .
802+ True if the room is accessible to the requesting user or server .
803803 """
804804 state_ids = await self ._store .get_current_state_ids (room_id )
805805
@@ -893,9 +893,9 @@ async def _is_remote_room_accessible(
893893 self , requester : str , room_id : str , room : JsonDict
894894 ) -> bool :
895895 """
896- Calculate whether the room received over federation should be shown in the spaces summary .
896+ Calculate whether the room received over federation should be shown to the requester .
897897
898- It should be included if:
898+ It should return true if:
899899
900900 * The requester is joined or can join the room (per MSC3173).
901901 * The history visibility is set to world readable.
@@ -907,10 +907,10 @@ async def _is_remote_room_accessible(
907907 Args:
908908 requester: The user requesting the summary.
909909 room_id: The room ID returned over federation.
910- room: The summary of the child room returned over federation.
910+ room: The summary of the room returned over federation.
911911
912912 Returns:
913- True if the room should be included in the spaces summary .
913+ True if the room is accessible to the requesting user .
914914 """
915915 # The API doesn't return the room version so assume that a
916916 # join rule of knock is valid.
@@ -936,7 +936,7 @@ async def _is_remote_room_accessible(
936936
937937 async def _build_room_entry (self , room_id : str , for_federation : bool ) -> JsonDict :
938938 """
939- Generate en entry suitable for the 'rooms' list in the summary response .
939+ Generate en entry summarising a single room .
940940
941941 Args:
942942 room_id: The room ID to summarize.
@@ -1024,6 +1024,61 @@ async def _get_child_events(self, room_id: str) -> Iterable[EventBase]:
10241024 # and order to ensure we return stable results.
10251025 return sorted (filter (_has_valid_via , events ), key = _child_events_comparison_key )
10261026
1027+ async def get_room_summary (
1028+ self ,
1029+ requester : Optional [str ],
1030+ room_id : str ,
1031+ remote_room_hosts : Optional [List [str ]] = None ,
1032+ ) -> JsonDict :
1033+ """
1034+ Implementation of the room summary C-S API from MSC3266
1035+
1036+ Args:
1037+ requester: user id of the user making this request, will be None
1038+ for unauthenticated requests
1039+
1040+ room_id: room id to summarise.
1041+
1042+ remote_room_hosts: a list of homeservers to try fetching data through
1043+ if we don't know it ourselves
1044+
1045+ Returns:
1046+ summary dict to return
1047+ """
1048+ is_in_room = await self ._store .is_host_joined (room_id , self ._server_name )
1049+
1050+ if is_in_room :
1051+ room_entry = await self ._summarize_local_room (
1052+ requester ,
1053+ None ,
1054+ room_id ,
1055+ # Suggested-only doesn't matter since no children are requested.
1056+ suggested_only = False ,
1057+ max_children = 0 ,
1058+ )
1059+
1060+ if not room_entry :
1061+ raise NotFoundError ("Room not found or is not accessible" )
1062+
1063+ room_summary = room_entry .room
1064+
1065+ # If there was a requester, add their membership.
1066+ if requester :
1067+ (
1068+ membership ,
1069+ _ ,
1070+ ) = await self ._store .get_local_current_membership_for_user_in_room (
1071+ requester , room_id
1072+ )
1073+
1074+ room_summary ["membership" ] = membership or "leave"
1075+ else :
1076+ # TODO federation API, descoped from initial unstable implementation
1077+ # as MSC needs more maturing on that side.
1078+ raise SynapseError (400 , "Federation is not currently supported." )
1079+
1080+ return room_summary
1081+
10271082
10281083@attr .s (frozen = True , slots = True , auto_attribs = True )
10291084class _RoomQueueEntry :
0 commit comments