@@ -463,18 +463,67 @@ class DeviceListsStream(Stream):
463463 @attr .s (slots = True , frozen = True , auto_attribs = True )
464464 class DeviceListsStreamRow :
465465 entity : str
466+ # Indicates that a user has signed their own device with their user-signing key
467+ is_signature : bool
466468
467469 NAME = "device_lists"
468470 ROW_TYPE = DeviceListsStreamRow
469471
470472 def __init__ (self , hs : "HomeServer" ):
471- store = hs .get_datastores ().main
473+ self . store = hs .get_datastores ().main
472474 super ().__init__ (
473475 hs .get_instance_name (),
474- current_token_without_instance (store .get_device_stream_token ),
475- store .get_all_device_list_changes_for_remotes ,
476+ current_token_without_instance (self .store .get_device_stream_token ),
477+ self ._update_function ,
478+ )
479+
480+ async def _update_function (
481+ self ,
482+ instance_name : str ,
483+ from_token : Token ,
484+ current_token : Token ,
485+ target_row_count : int ,
486+ ) -> StreamUpdateResult :
487+ (
488+ device_updates ,
489+ devices_to_token ,
490+ devices_limited ,
491+ ) = await self .store .get_all_device_list_changes_for_remotes (
492+ instance_name , from_token , current_token , target_row_count
476493 )
477494
495+ (
496+ signatures_updates ,
497+ signatures_to_token ,
498+ signatures_limited ,
499+ ) = await self .store .get_all_user_signature_changes_for_remotes (
500+ instance_name , from_token , current_token , target_row_count
501+ )
502+
503+ upper_limit_token = current_token
504+ if devices_limited :
505+ upper_limit_token = min (upper_limit_token , devices_to_token )
506+ if signatures_limited :
507+ upper_limit_token = min (upper_limit_token , signatures_to_token )
508+
509+ device_updates = [
510+ (stream_id , (entity , False ))
511+ for stream_id , (entity ,) in device_updates
512+ if stream_id <= upper_limit_token
513+ ]
514+
515+ signatures_updates = [
516+ (stream_id , (entity , True ))
517+ for stream_id , (entity ,) in signatures_updates
518+ if stream_id <= upper_limit_token
519+ ]
520+
521+ updates = list (
522+ heapq .merge (device_updates , signatures_updates , key = lambda row : row [0 ])
523+ )
524+
525+ return updates , upper_limit_token , devices_limited or signatures_limited
526+
478527
479528class ToDeviceStream (Stream ):
480529 """New to_device messages for a client"""
@@ -583,22 +632,3 @@ async def _update_function(
583632 heapq .merge (room_rows , global_rows , tag_rows , key = lambda row : row [0 ])
584633 )
585634 return updates , to_token , limited
586-
587-
588- class UserSignatureStream (Stream ):
589- """A user has signed their own device with their user-signing key"""
590-
591- @attr .s (slots = True , frozen = True , auto_attribs = True )
592- class UserSignatureStreamRow :
593- user_id : str
594-
595- NAME = "user_signature"
596- ROW_TYPE = UserSignatureStreamRow
597-
598- def __init__ (self , hs : "HomeServer" ):
599- store = hs .get_datastores ().main
600- super ().__init__ (
601- hs .get_instance_name (),
602- current_token_without_instance (store .get_device_stream_token ),
603- store .get_all_user_signature_changes_for_remotes ,
604- )
0 commit comments