3030"""
3131
3232import logging
33- from collections import namedtuple
3433from typing import (
3534 TYPE_CHECKING ,
3635 Dict ,
4342 Type ,
4443)
4544
45+ import attr
4646from sortedcontainers import SortedDict
4747
4848from synapse .api .presence import UserPresenceState
@@ -382,13 +382,11 @@ def add_to_buffer(self, buff: "ParsedFederationStreamData") -> None:
382382 raise NotImplementedError ()
383383
384384
385- class PresenceDestinationsRow (
386- BaseFederationRow ,
387- namedtuple (
388- "PresenceDestinationsRow" ,
389- ("state" , "destinations" ), # UserPresenceState # list[str]
390- ),
391- ):
385+ @attr .s (slots = True , frozen = True , auto_attribs = True )
386+ class PresenceDestinationsRow (BaseFederationRow ):
387+ state : UserPresenceState
388+ destinations : List [str ]
389+
392390 TypeId = "pd"
393391
394392 @staticmethod
@@ -404,17 +402,15 @@ def add_to_buffer(self, buff: "ParsedFederationStreamData") -> None:
404402 buff .presence_destinations .append ((self .state , self .destinations ))
405403
406404
407- class KeyedEduRow (
408- BaseFederationRow ,
409- namedtuple (
410- "KeyedEduRow" ,
411- ("key" , "edu" ), # tuple(str) - the edu key passed to send_edu # Edu
412- ),
413- ):
405+ @attr .s (slots = True , frozen = True , auto_attribs = True )
406+ class KeyedEduRow (BaseFederationRow ):
414407 """Streams EDUs that have an associated key that is ued to clobber. For example,
415408 typing EDUs clobber based on room_id.
416409 """
417410
411+ key : Tuple [str , ...] # the edu key passed to send_edu
412+ edu : Edu
413+
418414 TypeId = "k"
419415
420416 @staticmethod
@@ -428,9 +424,12 @@ def add_to_buffer(self, buff: "ParsedFederationStreamData") -> None:
428424 buff .keyed_edus .setdefault (self .edu .destination , {})[self .key ] = self .edu
429425
430426
431- class EduRow (BaseFederationRow , namedtuple ("EduRow" , ("edu" ,))): # Edu
427+ @attr .s (slots = True , frozen = True , auto_attribs = True )
428+ class EduRow (BaseFederationRow ):
432429 """Streams EDUs that don't have keys. See KeyedEduRow"""
433430
431+ edu : Edu
432+
434433 TypeId = "e"
435434
436435 @staticmethod
@@ -453,14 +452,14 @@ def add_to_buffer(self, buff: "ParsedFederationStreamData") -> None:
453452TypeToRow = {Row .TypeId : Row for Row in _rowtypes }
454453
455454
456- ParsedFederationStreamData = namedtuple (
457- " ParsedFederationStreamData" ,
458- (
459- " presence_destinations" , # list of tuples of UserPresenceState and destinations
460- "keyed_edus" , # dict of destination -> { key -> Edu }
461- "edus" , # dict of destination -> [ Edu]
462- ),
463- )
455+ @ attr . s ( slots = True , frozen = True , auto_attribs = True )
456+ class ParsedFederationStreamData :
457+ # list of tuples of UserPresenceState and destinations
458+ presence_destinations : List [ Tuple [ UserPresenceState , List [ str ]]]
459+ # dict of destination -> { key -> Edu }
460+ keyed_edus : Dict [ str , Dict [ Tuple [ str , ...], Edu ] ]
461+ # dict of destination -> [Edu]
462+ edus : Dict [ str , List [ Edu ]]
464463
465464
466465def process_rows_for_federation (
0 commit comments