示例#1
0
def handle_chat_message(sender, request, event, **kwargs):
    socket = sender
    session = socket.session

    message = event.args[0]

    if not session.user_name:
        event.ack(failure())
    else:
        socket.broadcast_emit('chat_message', session.user_name, message, include_self = True)
        event.ack(success())
示例#2
0
def handle_set_name(sender, request, event, **kwargs):
    socket = sender
    user_name = event.args[0]

    session = socket.session
    if session.user_name:
        socket.broadcast_emit('system_message', '{0} changed his name to {1}'.format(
            session.user_name, user_name), include_self = True)
    else:
        socket.broadcast_emit('system_message', '{0} has joined'.format(user_name), include_self = True)

    session.user_name = user_name
    event.ack(success())
示例#3
0
def handle_chat_message(sender, request, event, **kwargs):
    socket = sender
    session = socket.session

    message = event.args[0]
    namespace = kwargs['namespace']

    if 'user_name' not in session:
        result = failure()
    else:
        namespace.broadcast_event('chat_message', session['user_name'], message)
        result = success()

    return result
示例#4
0
def handle_set_name(sender, request, event, **kwargs):
    socket = sender
    user_name = event.args[0]
    namespace = kwargs['namespace']

    session = socket.session
    if 'user_name' in session:
        namespace.broadcast_event('system_message', '{0} changed his name to {1}'.format(
            session['user_name'], user_name))
    else:
        namespace.broadcast_event('system_message', '{0} has joined'.format(user_name))

    session['user_name'] = user_name
    return success()
示例#5
0
def handle_chat_message(sender, request, event, **kwargs):
    socket = sender
    session = socket.session

    message = event.args[0]
    namespace = kwargs['namespace']

    if 'user_name' not in session:
        result = failure()
    else:
        namespace.broadcast_event('chat_message', session['user_name'],
                                  message)
        result = success()

    return result
示例#6
0
def handle_set_name(sender, request, event, **kwargs):
    socket = sender
    user_name = event.args[0]
    namespace = kwargs['namespace']

    session = socket.session
    if 'user_name' in session:
        namespace.broadcast_event(
            'system_message',
            '{0} changed his name to {1}'.format(session['user_name'],
                                                 user_name))
    else:
        namespace.broadcast_event('system_message',
                                  '{0} has joined'.format(user_name))

    session['user_name'] = user_name
    return success()
示例#7
0
def handle_create_shortcut(sender, request, event, **kwargs):
    data = event.args[0]

    shortcut = data.get('shortcut', '')
    if shortcut and not Shortcut.is_available(shortcut):
        event.ack(failure(message = 'Skrót {0!r} jest juz zajety'.format(shortcut)))
        return

    url = data.get('url')
    if not url.startswith('http'):
        url = 'http://' + url

    print(url)
    try:
        URLValidator()(url)
    except:
        event.ack(failure(message = 'Adres {0!r} jest niepoprawnym URL-em'.format(url)))
        return

    shortcut = Shortcut(shortcut = shortcut, url = url)
    shortcut.full_clean()
    shortcut.save()
    event.ack(success(shortcut_url = 'http://{0}/{1}'.format(settings.SERVER_ADDRESS, shortcut.shortcut)))
示例#8
0
def handle_shortcut_availability(sender, request, event, **kwargs):
    shortcut = Shortcut.normalize_shortcut(event.args[0])
    available = Shortcut.is_available(shortcut)
    event.ack(success(available = available))