#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def _update_states( self , new_states ) : #NEWLINE# #INDENT# 'Updates presence of users. Sets the appropriate timeouts. Pokes\n        the notifier and federation if and only if the changed presence state\n        should be sent to clients/servers.\n        ' #NEWLINE# now = self . clock . time_msec ( ) #NEWLINE# with Measure ( self . clock , 'presence_update_states' ) : #NEWLINE# #INDENT# to_notify = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# to_federation_ping = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for new_state in new_states : #NEWLINE# #INDENT# user_id = new_state . user_id #NEWLINE# prev_state = self . user_to_current_state . get ( user_id , UserPresenceState . default ( user_id ) ) #NEWLINE# ( new_state , should_notify , should_ping ) = handle_update ( prev_state , new_state , is_mine = self . hs . is_mine_id ( user_id ) , wheel_timer = self . wheel_timer , now = now ) #NEWLINE# self . user_to_current_state [ user_id ] = new_state #NEWLINE# if should_notify : #NEWLINE# #INDENT# to_notify [ user_id ] = new_state #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if should_ping : #NEWLINE# #INDENT# to_federation_ping [ user_id ] = new_state #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# presence_updates_counter . inc_by ( len ( new_states ) ) #NEWLINE# if to_notify : #NEWLINE# #INDENT# notified_presence_counter . inc_by ( len ( to_notify ) ) #NEWLINE# ( yield self . _persist_and_notify ( to_notify . values ( ) ) ) #NEWLINE# #UNINDENT# self . unpersisted_users_changes |= set ( ( s . user_id for s in new_states ) ) #NEWLINE# self . unpersisted_users_changes -= set ( to_notify . keys ( ) ) #NEWLINE# to_federation_ping = { user_id : state for ( user_id , state ) in to_federation_ping . items ( ) if ( user_id not in to_notify ) } #NEWLINE# if to_federation_ping : #NEWLINE# #INDENT# federation_presence_out_counter . inc_by ( len ( to_federation_ping ) ) #NEWLINE# ( _ , _ , hosts_to_states ) = ( yield self . _get_interested_parties ( to_federation_ping . values ( ) ) ) #NEWLINE# self . _push_to_remotes ( hosts_to_states )