14
14
# limitations under the License.
15
15
16
16
import logging
17
- from typing import Any , Dict
17
+ from typing import TYPE_CHECKING , Any , Dict
18
18
19
19
from synapse .api .errors import SynapseError
20
20
from synapse .logging .context import run_in_background
24
24
set_tag ,
25
25
start_active_span ,
26
26
)
27
- from synapse .types import UserID , get_domain_from_id
27
+ from synapse .types import JsonDict , UserID , get_domain_from_id
28
28
from synapse .util import json_encoder
29
29
from synapse .util .stringutils import random_string
30
30
31
+ if TYPE_CHECKING :
32
+ from synapse .app .homeserver import HomeServer
33
+
34
+
31
35
logger = logging .getLogger (__name__ )
32
36
33
37
34
38
class DeviceMessageHandler :
35
- def __init__ (self , hs ):
39
+ def __init__ (self , hs : "HomeServer" ):
36
40
"""
37
41
Args:
38
- hs (synapse.server.HomeServer) : server
42
+ hs: server
39
43
"""
40
44
self .store = hs .get_datastore ()
41
45
self .notifier = hs .get_notifier ()
@@ -48,7 +52,7 @@ def __init__(self, hs):
48
52
49
53
self ._device_list_updater = hs .get_device_handler ().device_list_updater
50
54
51
- async def on_direct_to_device_edu (self , origin , content ) :
55
+ async def on_direct_to_device_edu (self , origin : str , content : JsonDict ) -> None :
52
56
local_messages = {}
53
57
sender_user_id = content ["sender" ]
54
58
if origin != get_domain_from_id (sender_user_id ):
@@ -95,7 +99,7 @@ async def _check_for_unknown_devices(
95
99
message_type : str ,
96
100
sender_user_id : str ,
97
101
by_device : Dict [str , Dict [str , Any ]],
98
- ):
102
+ ) -> None :
99
103
"""Checks inbound device messages for unknown remote devices, and if
100
104
found marks the remote cache for the user as stale.
101
105
"""
@@ -138,11 +142,16 @@ async def _check_for_unknown_devices(
138
142
self ._device_list_updater .user_device_resync , sender_user_id
139
143
)
140
144
141
- async def send_device_message (self , sender_user_id , message_type , messages ):
145
+ async def send_device_message (
146
+ self ,
147
+ sender_user_id : str ,
148
+ message_type : str ,
149
+ messages : Dict [str , Dict [str , JsonDict ]],
150
+ ) -> None :
142
151
set_tag ("number_of_messages" , len (messages ))
143
152
set_tag ("sender" , sender_user_id )
144
153
local_messages = {}
145
- remote_messages = {}
154
+ remote_messages = {} # type: Dict[str, Dict[str, Dict[str, JsonDict]]]
146
155
for user_id , by_device in messages .items ():
147
156
# we use UserID.from_string to catch invalid user ids
148
157
if self .is_mine (UserID .from_string (user_id )):
0 commit comments