@@ -1073,6 +1073,32 @@ async def get_space_summary(
1073
1073
max_rooms_per_space : Optional [int ],
1074
1074
exclude_rooms : List [str ],
1075
1075
) -> "FederationSpaceSummaryResult" :
1076
+ """
1077
+ Call other servers to get a summary of the given space
1078
+
1079
+
1080
+ Args:
1081
+ destinations: The remote servers. We will try them in turn, omitting any
1082
+ that have been blacklisted.
1083
+
1084
+ room_id: ID of the space to be queried
1085
+
1086
+ suggested_only: If true, ask the remote server to only return children
1087
+ with the "suggested" flag set
1088
+
1089
+ max_rooms_per_space: A limit on the number of children to return for each
1090
+ space
1091
+
1092
+ exclude_rooms: A list of room IDs to tell the remote server to skip
1093
+
1094
+ Returns:
1095
+ a parsed FederationSpaceSummaryResult
1096
+
1097
+ Raises:
1098
+ SynapseError if we were unable to get a valid summary from any of the
1099
+ remote servers
1100
+ """
1101
+
1076
1102
async def send_request (destination : str ) -> FederationSpaceSummaryResult :
1077
1103
res = await self .transport_layer .get_space_summary (
1078
1104
destination = destination ,
@@ -1097,6 +1123,13 @@ async def send_request(destination: str) -> FederationSpaceSummaryResult:
1097
1123
1098
1124
@attr .s (frozen = True , slots = True )
1099
1125
class FederationSpaceSummaryEventResult :
1126
+ """Represents a single event in the result of a successful get_space_summary call.
1127
+
1128
+ It's essentially just a serialised event object, but we do a bit of parsing and
1129
+ validation in `from_json_dict` and store some of the validated properties in
1130
+ object attributes.
1131
+ """
1132
+
1100
1133
event_type = attr .ib (type = str )
1101
1134
state_key = attr .ib (type = str )
1102
1135
via = attr .ib (type = Sequence [str ])
@@ -1105,7 +1138,16 @@ class FederationSpaceSummaryEventResult:
1105
1138
data = attr .ib (type = JsonDict )
1106
1139
1107
1140
@classmethod
1108
- def from_json_dict (cls , d : JsonDict ):
1141
+ def from_json_dict (cls , d : JsonDict ) -> "FederationSpaceSummaryEventResult" :
1142
+ """Parse an event within the result of a /spaces/ request
1143
+
1144
+ Args:
1145
+ d: json object to be parsed
1146
+
1147
+ Raises:
1148
+ ValueError if d is not a valid event
1149
+ """
1150
+
1109
1151
event_type = d .get ("type" )
1110
1152
if not isinstance (event_type , str ):
1111
1153
raise ValueError ("Invalid event: 'event_type' must be a str" )
@@ -1129,11 +1171,21 @@ def from_json_dict(cls, d: JsonDict):
1129
1171
1130
1172
@attr .s (frozen = True , slots = True )
1131
1173
class FederationSpaceSummaryResult :
1174
+ """Represents the data returned by a successful get_space_summary call."""
1175
+
1132
1176
rooms = attr .ib (type = Sequence [JsonDict ])
1133
1177
events = attr .ib (type = Sequence [FederationSpaceSummaryEventResult ])
1134
1178
1135
1179
@classmethod
1136
- def from_json_dict (cls , d : JsonDict ):
1180
+ def from_json_dict (cls , d : JsonDict ) -> "FederationSpaceSummaryResult" :
1181
+ """Parse the result of a /spaces/ request
1182
+
1183
+ Args:
1184
+ d: json object to be parsed
1185
+
1186
+ Raises:
1187
+ ValueError if d is not a valid /spaces/ response
1188
+ """
1137
1189
rooms = d .get ("rooms" )
1138
1190
if not isinstance (rooms , Sequence ):
1139
1191
raise ValueError ("'rooms' must be a list" )
0 commit comments