4141 run_as_background_process ,
4242 wrap_as_background_process ,
4343)
44+ from synapse .replication .http .devices import ReplicationUploadKeysForUserRestServlet
4445from synapse .types import (
4546 JsonDict ,
4647 StrCollection ,
@@ -656,15 +657,17 @@ async def store_dehydrated_device(
656657 device_id : Optional [str ],
657658 device_data : JsonDict ,
658659 initial_device_display_name : Optional [str ] = None ,
660+ device_keys : Optional [JsonDict ] = None ,
659661 ) -> str :
660- """Store a dehydrated device for a user. If the user had a previous
661- dehydrated device, it is removed.
662+ """Store a dehydrated device for a user, optionally storing the keys associated with
663+ it as well. If the user had a previous dehydrated device, it is removed.
662664
663665 Args:
664666 user_id: the user that we are storing the device for
665667 device_id: device id supplied by client
666668 device_data: the dehydrated device information
667669 initial_device_display_name: The display name to use for the device
670+ device_keys: keys for the dehydrated device
668671 Returns:
669672 device id of the dehydrated device
670673 """
@@ -678,6 +681,18 @@ async def store_dehydrated_device(
678681 )
679682 if old_device_id is not None :
680683 await self .delete_devices (user_id , [old_device_id ])
684+
685+ # we do this here to avoid a circular import
686+ if self .hs .config .worker .worker_app is None :
687+ # if main process
688+ key_uploader = self .hs .get_e2e_keys_handler ().upload_keys_for_user
689+ else :
690+ # if worker process
691+ key_uploader = ReplicationUploadKeysForUserRestServlet .make_client (self .hs )
692+
693+ # if keys are provided store them
694+ if device_keys :
695+ await key_uploader (user_id = user_id , device_id = device_id , keys = device_keys )
681696 return device_id
682697
683698 async def rehydrate_device (
0 commit comments