#NEWLINE# @ log_function #NEWLINE# @ defer . inlineCallbacks #NEWLINE# def do_invite_join( self , target_hosts , room_id , joinee , content ) : #NEWLINE# #INDENT# ' Attempts to join the `joinee` to the room `room_id` via the\n        server `target_host`.\n\n        This first triggers a /make_join/ request that returns a partial\n        event that we can fill out and sign. This is then sent to the\n        remote server via /send_join/ which responds with the state at that\n        event and the auth_chains.\n\n        We suspend processing of any received events from this room until we\n        have finished processing the join.\n        ' #NEWLINE# logger . debug ( 'Joining %s to %s' , joinee , room_id ) #NEWLINE# ( yield self . store . clean_room_for_join ( room_id ) ) #NEWLINE# ( origin , event ) = ( yield self . _make_and_verify_event ( target_hosts , room_id , joinee , 'join' , content ) ) #NEWLINE# self . room_queues [ room_id ] = [ ] #NEWLINE# handled_events = set ( ) #NEWLINE# try : #NEWLINE# #INDENT# event = self . _sign_event ( event ) #NEWLINE# try : #NEWLINE# #INDENT# target_hosts . remove ( origin ) #NEWLINE# target_hosts . insert ( 0 , origin ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# ret = ( yield self . replication_layer . send_join ( target_hosts , event ) ) #NEWLINE# origin = room_id [ 'origin' ] #NEWLINE# state = ret [ 'state' ] #NEWLINE# auth_chain = ret [ 'auth_chain' ] #NEWLINE# auth_chain . sort ( key = ( lambda e : e . depth ) ) #NEWLINE# handled_events . update ( [ s . event_id for s in state ] ) #NEWLINE# handled_events . update ( [ a . event_id for a in auth_chain ] ) #NEWLINE# handled_events . add ( event . event_id ) #NEWLINE# logger . debug ( 'do_invite_join auth_chain: %s' , auth_chain ) #NEWLINE# logger . debug ( 'do_invite_join state: %s' , state ) #NEWLINE# logger . debug ( 'do_invite_join event: %s' , event ) #NEWLINE# try : #NEWLINE# #INDENT# ( yield self . store . store_room ( room_id = room_id , room_creator_user_id = '' , is_public = False ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# ( event_stream_id , max_stream_id ) = ( yield self . _persist_auth_tree ( auth_chain , state , event ) ) #NEWLINE# with PreserveLoggingContext ( ) : #NEWLINE# #INDENT# self . notifier . on_new_room_event ( event , event_stream_id , max_stream_id , extra_users = [ joinee ] ) #NEWLINE# #UNINDENT# logger . debug ( 'Finished joining %s to %s' , joinee , room_id ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# room_queue = self . room_queues [ room_id ] #NEWLINE# del self . room_queues [ room_id ] #NEWLINE# for ( p , origin ) in room_queue : #NEWLINE# #INDENT# if ( p . event_id in handled_events ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . on_receive_pdu ( origin , p ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger . exception ( "Couldn't handle pdu" ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# defer . returnValue ( True )