#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def get_events_for( self , user , pagination_config , timeout , only_keys = None , is_guest = False , explicit_room_id = None ) : #NEWLINE# #INDENT# " For the given user and rooms, return any new events for them. If\n        there are no new events wait for up to `timeout` milliseconds for any\n        new events to happen before returning.\n\n        If `only_keys` is not None, events from keys will be sent down.\n\n        If explicit_room_id is not set, the user's joined rooms will be polled\n        for events.\n        If explicit_room_id is set, that room will be polled for events only if\n        it is world readable or the user has joined the room.\n        " #NEWLINE# from_token = pagination_config . from_token #NEWLINE# if ( not from_token ) : #NEWLINE# #INDENT# from_token = ( yield self . event_sources . get_current_token ( ) ) #NEWLINE# #UNINDENT# limit = pagination_config . limit #NEWLINE# ( room_ids , is_joined ) = ( yield self . _get_room_ids ( user , explicit_room_id ) ) #NEWLINE# is_peeking = ( not is_joined ) #NEWLINE# @ defer . inlineCallbacks #NEWLINE# def check_for_updates( before_token , after_token ) : #NEWLINE# #INDENT# if ( not after_token . is_after ( before_token ) ) : #NEWLINE# #INDENT# defer . returnValue ( EventStreamResult ( [ ] , ( from_token , from_token ) ) ) #NEWLINE# #UNINDENT# events = [ ] #NEWLINE# end_token = from_token #NEWLINE# for ( name , source ) in self . event_sources . sources . items ( ) : #NEWLINE# #INDENT# keyname = ( '%s_key' % name ) #NEWLINE# before_id = getattr ( before_token , keyname ) #NEWLINE# after_id = getattr ( after_token , keyname ) #NEWLINE# if ( before_id == after_id ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( only_keys and ( name not in only_keys ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( new_events , new_key ) = ( yield source . get_new_events ( user = user , from_key = getattr ( from_token , keyname ) , limit = limit , is_guest = is_peeking , room_ids = room_ids ) ) #NEWLINE# if ( name == 'room' ) : #NEWLINE# #INDENT# room_member_handler = self . hs . get_handlers ( ) . room_member_handler #NEWLINE# new_events = ( yield room_member_handler . _filter_events_for_client ( user . to_string ( ) , new_events , is_peeking = is_peeking ) ) #NEWLINE# #UNINDENT# events . extend ( new_events ) #NEWLINE# end_token = end_token . copy_and_replace ( keyname , new_key ) #NEWLINE# #UNINDENT# defer . returnValue ( EventStreamResult ( events , ( from_token , end_token ) ) ) #NEWLINE# #UNINDENT# user_id_for_stream = user . to_string ( ) #NEWLINE# if is_peeking : #NEWLINE# #INDENT# user_id_for_stream = ( '_PEEKING_%s_%s' % ( explicit_room_id , user_id_for_stream ) ) #NEWLINE# #UNINDENT# result = ( yield self . wait_for_events ( user_id_for_stream , timeout , check_for_updates , room_ids = room_ids , from_token = from_token ) ) #NEWLINE# defer . returnValue ( result )