@@ -165,7 +165,11 @@ def __init__(self, hs: "HomeServer"):
165165
166166 @abc .abstractmethod
167167 async def user_syncing (
168- self , user_id : str , affect_presence : bool , presence_state : str
168+ self ,
169+ user_id : str ,
170+ device_id : Optional [str ],
171+ affect_presence : bool ,
172+ presence_state : str ,
169173 ) -> ContextManager [None ]:
170174 """Returns a context manager that should surround any stream requests
171175 from the user.
@@ -176,6 +180,7 @@ async def user_syncing(
176180
177181 Args:
178182 user_id: the user that is starting a sync
183+ device_id: the user's device that is starting a sync
179184 affect_presence: If false this function will be a no-op.
180185 Useful for streams that are not associated with an actual
181186 client that is being used by a user.
@@ -252,6 +257,7 @@ async def current_state_for_user(self, user_id: str) -> UserPresenceState:
252257 async def set_state (
253258 self ,
254259 target_user : UserID ,
260+ device_id : Optional [str ],
255261 state : JsonDict ,
256262 force_notify : bool = False ,
257263 is_sync : bool = False ,
@@ -260,6 +266,7 @@ async def set_state(
260266
261267 Args:
262268 target_user: The ID of the user to set the presence state of.
269+ device_id: the device that the user is setting the presence state of.
263270 state: The presence state as a JSON dictionary.
264271 force_notify: Whether to force notification of the update to clients.
265272 is_sync: True if this update was from a sync, which results in
@@ -269,7 +276,9 @@ async def set_state(
269276 """
270277
271278 @abc .abstractmethod
272- async def bump_presence_active_time (self , user : UserID ) -> None :
279+ async def bump_presence_active_time (
280+ self , user : UserID , device_id : Optional [str ]
281+ ) -> None :
273282 """We've seen the user do something that indicates they're interacting
274283 with the app.
275284 """
@@ -381,7 +390,9 @@ async def send_full_presence_to_users(self, user_ids: StrCollection) -> None:
381390 # We set force_notify=True here so that this presence update is guaranteed to
382391 # increment the presence stream ID (which resending the current user's presence
383392 # otherwise would not do).
384- await self .set_state (UserID .from_string (user_id ), state , force_notify = True )
393+ await self .set_state (
394+ UserID .from_string (user_id ), None , state , force_notify = True
395+ )
385396
386397 async def is_visible (self , observed_user : UserID , observer_user : UserID ) -> bool :
387398 raise NotImplementedError (
@@ -481,7 +492,11 @@ def send_stop_syncing(self) -> None:
481492 self .send_user_sync (user_id , False , last_sync_ms )
482493
483494 async def user_syncing (
484- self , user_id : str , affect_presence : bool , presence_state : str
495+ self ,
496+ user_id : str ,
497+ device_id : Optional [str ],
498+ affect_presence : bool ,
499+ presence_state : str ,
485500 ) -> ContextManager [None ]:
486501 """Record that a user is syncing.
487502
@@ -495,6 +510,7 @@ async def user_syncing(
495510 # what the spec wants.
496511 await self .set_state (
497512 UserID .from_string (user_id ),
513+ device_id ,
498514 state = {"presence" : presence_state },
499515 is_sync = True ,
500516 )
@@ -592,6 +608,7 @@ def get_currently_syncing_users_for_replication(self) -> Iterable[str]:
592608 async def set_state (
593609 self ,
594610 target_user : UserID ,
611+ device_id : Optional [str ],
595612 state : JsonDict ,
596613 force_notify : bool = False ,
597614 is_sync : bool = False ,
@@ -600,6 +617,7 @@ async def set_state(
600617
601618 Args:
602619 target_user: The ID of the user to set the presence state of.
620+ device_id: the device that the user is setting the presence state of.
603621 state: The presence state as a JSON dictionary.
604622 force_notify: Whether to force notification of the update to clients.
605623 is_sync: True if this update was from a sync, which results in
@@ -622,12 +640,15 @@ async def set_state(
622640 await self ._set_state_client (
623641 instance_name = self ._presence_writer_instance ,
624642 user_id = user_id ,
643+ device_id = device_id ,
625644 state = state ,
626645 force_notify = force_notify ,
627646 is_sync = is_sync ,
628647 )
629648
630- async def bump_presence_active_time (self , user : UserID ) -> None :
649+ async def bump_presence_active_time (
650+ self , user : UserID , device_id : Optional [str ]
651+ ) -> None :
631652 """We've seen the user do something that indicates they're interacting
632653 with the app.
633654 """
@@ -638,7 +659,9 @@ async def bump_presence_active_time(self, user: UserID) -> None:
638659 # Proxy request to instance that writes presence
639660 user_id = user .to_string ()
640661 await self ._bump_active_client (
641- instance_name = self ._presence_writer_instance , user_id = user_id
662+ instance_name = self ._presence_writer_instance ,
663+ user_id = user_id ,
664+ device_id = device_id ,
642665 )
643666
644667
@@ -943,7 +966,9 @@ async def _handle_timeouts(self) -> None:
943966
944967 return await self ._update_states (changes )
945968
946- async def bump_presence_active_time (self , user : UserID ) -> None :
969+ async def bump_presence_active_time (
970+ self , user : UserID , device_id : Optional [str ]
971+ ) -> None :
947972 """We've seen the user do something that indicates they're interacting
948973 with the app.
949974 """
@@ -966,6 +991,7 @@ async def bump_presence_active_time(self, user: UserID) -> None:
966991 async def user_syncing (
967992 self ,
968993 user_id : str ,
994+ device_id : Optional [str ],
969995 affect_presence : bool = True ,
970996 presence_state : str = PresenceState .ONLINE ,
971997 ) -> ContextManager [None ]:
@@ -977,7 +1003,8 @@ async def user_syncing(
9771003 when users disconnect/reconnect.
9781004
9791005 Args:
980- user_id
1006+ user_id: the user that is starting a sync
1007+ device_id: the user's device that is starting a sync
9811008 affect_presence: If false this function will be a no-op.
9821009 Useful for streams that are not associated with an actual
9831010 client that is being used by a user.
@@ -993,6 +1020,7 @@ async def user_syncing(
9931020 # what the spec wants.
9941021 await self .set_state (
9951022 UserID .from_string (user_id ),
1023+ device_id ,
9961024 state = {"presence" : presence_state },
9971025 is_sync = True ,
9981026 )
@@ -1163,6 +1191,7 @@ async def incoming_presence(self, origin: str, content: JsonDict) -> None:
11631191 async def set_state (
11641192 self ,
11651193 target_user : UserID ,
1194+ device_id : Optional [str ],
11661195 state : JsonDict ,
11671196 force_notify : bool = False ,
11681197 is_sync : bool = False ,
@@ -1171,6 +1200,7 @@ async def set_state(
11711200
11721201 Args:
11731202 target_user: The ID of the user to set the presence state of.
1203+ device_id: the device that the user is setting the presence state of.
11741204 state: The presence state as a JSON dictionary.
11751205 force_notify: Whether to force notification of the update to clients.
11761206 is_sync: True if this update was from a sync, which results in
0 commit comments