14
14
# limitations under the License.
15
15
16
16
import logging
17
+ from typing import TYPE_CHECKING
17
18
18
19
from twisted .internet import defer
19
20
22
23
from synapse .events .validator import EventValidator
23
24
from synapse .handlers .presence import format_user_presence_state
24
25
from synapse .logging .context import make_deferred_yieldable , run_in_background
26
+ from synapse .storage .roommember import RoomsForUser
25
27
from synapse .streams .config import PaginationConfig
26
- from synapse .types import StreamToken , UserID
28
+ from synapse .types import JsonDict , Requester , StreamToken , UserID
27
29
from synapse .util import unwrapFirstError
28
30
from synapse .util .async_helpers import concurrently_execute
29
31
from synapse .util .caches .response_cache import ResponseCache
30
32
from synapse .visibility import filter_events_for_client
31
33
32
34
from ._base import BaseHandler
33
35
36
+ if TYPE_CHECKING :
37
+ from synapse .server import HomeServer
38
+
39
+
34
40
logger = logging .getLogger (__name__ )
35
41
36
42
37
43
class InitialSyncHandler (BaseHandler ):
38
- def __init__ (self , hs ):
44
+ def __init__ (self , hs : "HomeServer" ):
39
45
super (InitialSyncHandler , self ).__init__ (hs )
40
46
self .hs = hs
41
47
self .state = hs .get_state_handler ()
@@ -48,27 +54,25 @@ def __init__(self, hs):
48
54
49
55
def snapshot_all_rooms (
50
56
self ,
51
- user_id = None ,
52
- pagin_config = None ,
53
- as_client_event = True ,
54
- include_archived = False ,
55
- ):
57
+ user_id : str ,
58
+ pagin_config : PaginationConfig ,
59
+ as_client_event : bool = True ,
60
+ include_archived : bool = False ,
61
+ ) -> JsonDict :
56
62
"""Retrieve a snapshot of all rooms the user is invited or has joined.
57
63
58
64
This snapshot may include messages for all rooms where the user is
59
65
joined, depending on the pagination config.
60
66
61
67
Args:
62
- user_id (str) : The ID of the user making the request.
63
- pagin_config (synapse.api.streams.PaginationConfig) : The pagination
64
- config used to determine how many messages *PER ROOM* to return.
65
- as_client_event (bool) : True to get events in client-server format.
66
- include_archived (bool) : True to get rooms that the user has left
68
+ user_id: The ID of the user making the request.
69
+ pagin_config: The pagination config used to determine how many
70
+ messages *PER ROOM* to return.
71
+ as_client_event: True to get events in client-server format.
72
+ include_archived: True to get rooms that the user has left
67
73
Returns:
68
- A list of dicts with "room_id" and "membership" keys for all rooms
69
- the user is currently invited or joined in on. Rooms where the user
70
- is joined on, may return a "messages" key with messages, depending
71
- on the specified PaginationConfig.
74
+ A JsonDict with the same format as the response to `/intialSync`
75
+ API
72
76
"""
73
77
key = (
74
78
user_id ,
@@ -91,11 +95,11 @@ def snapshot_all_rooms(
91
95
92
96
async def _snapshot_all_rooms (
93
97
self ,
94
- user_id = None ,
95
- pagin_config = None ,
96
- as_client_event = True ,
97
- include_archived = False ,
98
- ):
98
+ user_id : str ,
99
+ pagin_config : PaginationConfig ,
100
+ as_client_event : bool = True ,
101
+ include_archived : bool = False ,
102
+ ) -> JsonDict :
99
103
100
104
memberships = [Membership .INVITE , Membership .JOIN ]
101
105
if include_archived :
@@ -134,7 +138,7 @@ async def _snapshot_all_rooms(
134
138
if limit is None :
135
139
limit = 10
136
140
137
- async def handle_room (event ):
141
+ async def handle_room (event : RoomsForUser ):
138
142
d = {
139
143
"room_id" : event .room_id ,
140
144
"membership" : event .membership ,
@@ -251,17 +255,18 @@ async def handle_room(event):
251
255
252
256
return ret
253
257
254
- async def room_initial_sync (self , requester , room_id , pagin_config = None ):
258
+ async def room_initial_sync (
259
+ self , requester : Requester , room_id : str , pagin_config : PaginationConfig
260
+ ) -> JsonDict :
255
261
"""Capture the a snapshot of a room. If user is currently a member of
256
262
the room this will be what is currently in the room. If the user left
257
263
the room this will be what was in the room when they left.
258
264
259
265
Args:
260
- requester(Requester): The user to get a snapshot for.
261
- room_id(str): The room to get a snapshot of.
262
- pagin_config(synapse.streams.config.PaginationConfig):
263
- The pagination config used to determine how many messages to
264
- return.
266
+ requester: The user to get a snapshot for.
267
+ room_id: The room to get a snapshot of.
268
+ pagin_config: The pagination config used to determine how many
269
+ messages to return.
265
270
Raises:
266
271
AuthError if the user wasn't in the room.
267
272
Returns:
@@ -305,8 +310,14 @@ async def room_initial_sync(self, requester, room_id, pagin_config=None):
305
310
return result
306
311
307
312
async def _room_initial_sync_parted (
308
- self , user_id , room_id , pagin_config , membership , member_event_id , is_peeking
309
- ):
313
+ self ,
314
+ user_id : str ,
315
+ room_id : str ,
316
+ pagin_config : PaginationConfig ,
317
+ membership : Membership ,
318
+ member_event_id : str ,
319
+ is_peeking : bool ,
320
+ ) -> JsonDict :
310
321
room_state = await self .state_store .get_state_for_events ([member_event_id ])
311
322
312
323
room_state = room_state [member_event_id ]
@@ -350,8 +361,13 @@ async def _room_initial_sync_parted(
350
361
}
351
362
352
363
async def _room_initial_sync_joined (
353
- self , user_id , room_id , pagin_config , membership , is_peeking
354
- ):
364
+ self ,
365
+ user_id : str ,
366
+ room_id : str ,
367
+ pagin_config : PaginationConfig ,
368
+ membership : Membership ,
369
+ is_peeking : bool ,
370
+ ) -> JsonDict :
355
371
current_state = await self .state .get_current_state (room_id = room_id )
356
372
357
373
# TODO: These concurrently
0 commit comments