1515# limitations under the License.
1616
1717import logging
18+ from typing import TYPE_CHECKING , Dict , Iterable , List , Set
1819
1920from synapse .api .errors import HttpResponseException , RequestSendFailed , SynapseError
20- from synapse .types import GroupID , get_domain_from_id
21+ from synapse .types import GroupID , JsonDict , get_domain_from_id
22+
23+ if TYPE_CHECKING :
24+ from synapse .app .homeserver import HomeServer
2125
2226logger = logging .getLogger (__name__ )
2327
@@ -56,7 +60,7 @@ async def f(self, group_id, *args, **kwargs):
5660
5761
5862class GroupsLocalWorkerHandler :
59- def __init__ (self , hs ):
63+ def __init__ (self , hs : "HomeServer" ):
6064 self .hs = hs
6165 self .store = hs .get_datastore ()
6266 self .room_list_handler = hs .get_room_list_handler ()
@@ -84,7 +88,9 @@ def __init__(self, hs):
8488 get_group_role = _create_rerouter ("get_group_role" )
8589 get_group_roles = _create_rerouter ("get_group_roles" )
8690
87- async def get_group_summary (self , group_id , requester_user_id ):
91+ async def get_group_summary (
92+ self , group_id : str , requester_user_id : str
93+ ) -> JsonDict :
8894 """Get the group summary for a group.
8995
9096 If the group is remote we check that the users have valid attestations.
@@ -137,14 +143,15 @@ async def get_group_summary(self, group_id, requester_user_id):
137143
138144 return res
139145
140- async def get_users_in_group (self , group_id , requester_user_id ):
146+ async def get_users_in_group (
147+ self , group_id : str , requester_user_id : str
148+ ) -> JsonDict :
141149 """Get users in a group
142150 """
143151 if self .is_mine_id (group_id ):
144- res = await self .groups_server_handler .get_users_in_group (
152+ return await self .groups_server_handler .get_users_in_group (
145153 group_id , requester_user_id
146154 )
147- return res
148155
149156 group_server_name = get_domain_from_id (group_id )
150157
@@ -178,11 +185,11 @@ async def get_users_in_group(self, group_id, requester_user_id):
178185
179186 return res
180187
181- async def get_joined_groups (self , user_id ) :
188+ async def get_joined_groups (self , user_id : str ) -> JsonDict :
182189 group_ids = await self .store .get_joined_groups (user_id )
183190 return {"groups" : group_ids }
184191
185- async def get_publicised_groups_for_user (self , user_id ) :
192+ async def get_publicised_groups_for_user (self , user_id : str ) -> JsonDict :
186193 if self .hs .is_mine_id (user_id ):
187194 result = await self .store .get_publicised_groups_for_user (user_id )
188195
@@ -206,8 +213,10 @@ async def get_publicised_groups_for_user(self, user_id):
206213 # TODO: Verify attestations
207214 return {"groups" : result }
208215
209- async def bulk_get_publicised_groups (self , user_ids , proxy = True ):
210- destinations = {}
216+ async def bulk_get_publicised_groups (
217+ self , user_ids : Iterable [str ], proxy : bool = True
218+ ) -> JsonDict :
219+ destinations = {} # type: Dict[str, Set[str]]
211220 local_users = set ()
212221
213222 for user_id in user_ids :
@@ -220,7 +229,7 @@ async def bulk_get_publicised_groups(self, user_ids, proxy=True):
220229 raise SynapseError (400 , "Some user_ids are not local" )
221230
222231 results = {}
223- failed_results = []
232+ failed_results = [] # type: List[str]
224233 for destination , dest_user_ids in destinations .items ():
225234 try :
226235 r = await self .transport_client .bulk_get_publicised_groups (
@@ -242,7 +251,7 @@ async def bulk_get_publicised_groups(self, user_ids, proxy=True):
242251
243252
244253class GroupsLocalHandler (GroupsLocalWorkerHandler ):
245- def __init__ (self , hs ):
254+ def __init__ (self , hs : "HomeServer" ):
246255 super ().__init__ (hs )
247256
248257 # Ensure attestations get renewed
@@ -271,7 +280,9 @@ def __init__(self, hs):
271280
272281 set_group_join_policy = _create_rerouter ("set_group_join_policy" )
273282
274- async def create_group (self , group_id , user_id , content ):
283+ async def create_group (
284+ self , group_id : str , user_id : str , content : JsonDict
285+ ) -> JsonDict :
275286 """Create a group
276287 """
277288
@@ -284,27 +295,7 @@ async def create_group(self, group_id, user_id, content):
284295 local_attestation = None
285296 remote_attestation = None
286297 else :
287- local_attestation = self .attestations .create_attestation (group_id , user_id )
288- content ["attestation" ] = local_attestation
289-
290- content ["user_profile" ] = await self .profile_handler .get_profile (user_id )
291-
292- try :
293- res = await self .transport_client .create_group (
294- get_domain_from_id (group_id ), group_id , user_id , content
295- )
296- except HttpResponseException as e :
297- raise e .to_synapse_error ()
298- except RequestSendFailed :
299- raise SynapseError (502 , "Failed to contact group server" )
300-
301- remote_attestation = res ["attestation" ]
302- await self .attestations .verify_attestation (
303- remote_attestation ,
304- group_id = group_id ,
305- user_id = user_id ,
306- server_name = get_domain_from_id (group_id ),
307- )
298+ raise SynapseError (400 , "Unable to create remote groups" )
308299
309300 is_publicised = content .get ("publicise" , False )
310301 token = await self .store .register_user_group_membership (
@@ -320,7 +311,9 @@ async def create_group(self, group_id, user_id, content):
320311
321312 return res
322313
323- async def join_group (self , group_id , user_id , content ):
314+ async def join_group (
315+ self , group_id : str , user_id : str , content : JsonDict
316+ ) -> JsonDict :
324317 """Request to join a group
325318 """
326319 if self .is_mine_id (group_id ):
@@ -365,7 +358,9 @@ async def join_group(self, group_id, user_id, content):
365358
366359 return {}
367360
368- async def accept_invite (self , group_id , user_id , content ):
361+ async def accept_invite (
362+ self , group_id : str , user_id : str , content : JsonDict
363+ ) -> JsonDict :
369364 """Accept an invite to a group
370365 """
371366 if self .is_mine_id (group_id ):
@@ -410,7 +405,9 @@ async def accept_invite(self, group_id, user_id, content):
410405
411406 return {}
412407
413- async def invite (self , group_id , user_id , requester_user_id , config ):
408+ async def invite (
409+ self , group_id : str , user_id : str , requester_user_id : str , config : JsonDict
410+ ) -> JsonDict :
414411 """Invite a user to a group
415412 """
416413 content = {"requester_user_id" : requester_user_id , "config" : config }
@@ -434,7 +431,9 @@ async def invite(self, group_id, user_id, requester_user_id, config):
434431
435432 return res
436433
437- async def on_invite (self , group_id , user_id , content ):
434+ async def on_invite (
435+ self , group_id : str , user_id : str , content : JsonDict
436+ ) -> JsonDict :
438437 """One of our users were invited to a group
439438 """
440439 # TODO: Support auto join and rejection
@@ -465,8 +464,8 @@ async def on_invite(self, group_id, user_id, content):
465464 return {"state" : "invite" , "user_profile" : user_profile }
466465
467466 async def remove_user_from_group (
468- self , group_id , user_id , requester_user_id , content
469- ):
467+ self , group_id : str , user_id : str , requester_user_id : str , content : JsonDict
468+ ) -> JsonDict :
470469 """Remove a user from a group
471470 """
472471 if user_id == requester_user_id :
@@ -499,7 +498,9 @@ async def remove_user_from_group(
499498
500499 return res
501500
502- async def user_removed_from_group (self , group_id , user_id , content ):
501+ async def user_removed_from_group (
502+ self , group_id : str , user_id : str , content : JsonDict
503+ ) -> None :
503504 """One of our users was removed/kicked from a group
504505 """
505506 # TODO: Check if user in group
0 commit comments