def gone_online(stream):
    """
    Distributes the users online status to everyone he has dialog with
    """
    while True:
        packet = yield from stream.get()
        session_id = packet.get('session_key')
        if session_id:
            user_owner = get_user_from_session(session_id)
            if user_owner:
                logger.debug('User ' + user_owner.username + ' gone online')
                # find all connections including user_owner as opponent,
                # send them a message that the user has gone online
                online_opponents = list(filter(lambda x: x[1] == user_owner.username, ws_connections))
                online_opponents_sockets = [ws_connections[i] for i in online_opponents]
                yield from fanout_message(online_opponents_sockets,
                                          {'type': 'gone-online', 'usernames': [user_owner.username]})
            else:
                pass  # invalid session id
        else:
            pass
def gone_online ( stream ) : while True : packet = yield from stream . get ( ) session_id = packet . get ( 'session_key' ) if session_id : user_owner = get_user_from_session ( session_id ) if user_owner : logger . debug ( 'User ' + user_owner . username + ' gone online' ) online_opponents = list ( filter ( lambda x : x [ 1 ] == user_owner . username , ws_connections ) ) online_opponents_sockets = [ ws_connections [ i ] for i in online_opponents ] yield from fanout_message ( online_opponents_sockets , { 'type' : 'gone-online' , 'usernames' : [ user_owner . username ] } ) else : pass else : pass
Distributes the users online status to everyone he has dialog with