#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def full_state_sync( self , sync_config , timeline_since_token ) : #NEWLINE# #INDENT# "Get a sync for a client which is starting without any state.\n\n        If a 'message_since_token' is given, only timeline events which have\n        happened since that token will be returned.\n\n        Returns:\n            A Deferred SyncResult.\n        " #NEWLINE# now_token = ( yield self . event_sources . get_current_token ( ) ) #NEWLINE# ( now_token , ephemeral_by_room ) = ( yield self . ephemeral_by_room ( sync_config , now_token ) ) #NEWLINE# presence_stream = self . event_sources . sources [ 'presence' ] #NEWLINE# pagination_config = PaginationConfig ( from_token = now_token ) #NEWLINE# ( presence , _ ) = ( yield presence_stream . get_pagination_rows ( user = sync_config . user , pagination_config = pagination_config . get_source_config ( 'presence' ) , key = None ) ) #NEWLINE# membership_list = ( Membership . INVITE , Membership . JOIN , Membership . LEAVE , Membership . BAN ) #NEWLINE# room_list = ( yield self . store . get_rooms_for_user_where_membership_is ( user_id = sync_config . user . to_string ( ) , membership_list = membership_list ) ) #NEWLINE# ( account_data , account_data_by_room ) = ( yield self . store . get_account_data_for_user ( sync_config . user . to_string ( ) ) ) #NEWLINE# account_data [ 'm.push_rules' ] = ( yield self . push_rules_for_user ( sync_config . user ) ) #NEWLINE# tags_by_room = ( yield self . store . get_tags_for_user ( sync_config . user . to_string ( ) ) ) #NEWLINE# joined = [ ] #NEWLINE# invited = [ ] #NEWLINE# archived = [ ] #NEWLINE# deferreds = [ ] #NEWLINE# room_list_chunks = [ room_list [ i : ( i + 10 ) ] for i in xrange ( 0 , len ( room_list ) , 10 ) ] #NEWLINE# for room_list_chunk in room_list_chunks : #NEWLINE# #INDENT# for event in room_list_chunk : #NEWLINE# #INDENT# if ( event . membership == Membership . JOIN ) : #NEWLINE# #INDENT# room_sync_deferred = preserve_fn ( self . full_state_sync_for_joined_room ) ( room_id = event . room_id , sync_config = sync_config , now_token = now_token , timeline_since_token = timeline_since_token , ephemeral_by_room = ephemeral_by_room , tags_by_room = tags_by_room , account_data_by_room = account_data_by_room ) #NEWLINE# room_sync_deferred . addCallback ( joined . append ) #NEWLINE# deferreds . append ( room_sync_deferred ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( event . membership == Membership . INVITE ) : #NEWLINE# #INDENT# invite = ( yield self . store . get_event ( event . event_id ) ) #NEWLINE# invited . append ( InvitedSyncResult ( room_id = event . room_id , invite = invite ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( event . membership in ( Membership . LEAVE , Membership . BAN ) ) : #NEWLINE# #INDENT# if ( not sync_config . filter_collection . include_leave ) : #NEWLINE# #INDENT# if ( event . membership == Membership . LEAVE ) : #NEWLINE# #INDENT# if ( sync_config . user . to_string ( ) == event . sender ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# leave_token = now_token . copy_and_replace ( 'room_key' , ( 's%d' % ( event . stream_ordering , ) ) ) #NEWLINE# room_sync_deferred = preserve_fn ( self . full_state_sync_for_archived_room ) ( sync_config = sync_config , room_id = event . room_id , leave_event_id = event . event_id , leave_token = leave_token , timeline_since_token = timeline_since_token , tags_by_room = tags_by_room , account_data_by_room = account_data_by_room ) #NEWLINE# room_sync_deferred . addCallback ( archived . append ) #NEWLINE# deferreds . append ( room_sync_deferred ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# ( yield defer . gatherResults ( deferreds , consumeErrors = True ) . addErrback ( unwrapFirstError ) ) #NEWLINE# #UNINDENT# account_data_for_user = sync_config . filter_collection . filter_account_data ( self . account_data_for_user ( account_data ) ) #NEWLINE# presence = sync_config . filter_collection . filter_presence ( presence ) #NEWLINE# defer . returnValue ( SyncResult ( presence = presence , account_data = account_data_for_user , joined = joined , invited = invited , archived = archived , next_batch = now_token ) )