#NEWLINE# @ defer . inlineCallbacks #NEWLINE# @ log_function #NEWLINE# def get_stream( self , auth_user_id , pagin_config , timeout = 0 , as_client_event = True , affect_presence = True , only_keys = None , room_id = None , is_guest = False ) : #NEWLINE# #INDENT# 'Fetches the events stream for a given user.\n\n        If `only_keys` is not None, events from keys will be sent down.\n        ' #NEWLINE# auth_user = UserID . from_string ( auth_user_id ) #NEWLINE# presence_handler = self . hs . get_handlers ( ) . presence_handler #NEWLINE# context = ( yield presence_handler . user_syncing ( auth_user_id , affect_presence = affect_presence ) ) #NEWLINE# with context : #NEWLINE# #INDENT# if timeout : #NEWLINE# #INDENT# timeout = max ( timeout , 500 ) #NEWLINE# timeout = random . randint ( int ( ( timeout * 0.9 ) ) , int ( ( timeout * 1.1 ) ) ) #NEWLINE# #UNINDENT# ( events , tokens ) = ( yield self . notifier . get_events_for ( auth_user , pagin_config , timeout , only_keys = only_keys , is_guest = is_guest , explicit_room_id = room_id ) ) #NEWLINE# to_add = [ ] #NEWLINE# for event in events : #NEWLINE# #INDENT# if ( not isinstance ( event , EventBase ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( event . type == EventTypes . Member ) : #NEWLINE# #INDENT# if ( event . membership != Membership . JOIN ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( event . state_key == auth_user_id ) : #NEWLINE# #INDENT# users = ( yield self . store . get_users_in_room ( event . room_id ) ) #NEWLINE# states = ( yield presence_handler . get_states ( users , as_event = True ) ) #NEWLINE# to_add . extend ( states ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ev = ( yield presence_handler . get_state ( UserID . from_string ( event . state_key ) , as_event = True ) ) #NEWLINE# to_add . append ( ev ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# events . extend ( to_add ) #NEWLINE# time_now = self . clock . time_msec ( ) #NEWLINE# chunks = [ serialize_event ( e , time_now , as_client_event ) for e in events ] #NEWLINE# chunk = { #NEWLINE# #INDENT# 'chunk' : chunks , #NEWLINE# 'start' : tokens [ 0 ] . to_string ( ) , #NEWLINE# 'end' : tokens [ 1 ] . to_string ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# defer . returnValue ( chunk )