コード例 #1
0
def handle_mess(msg):
    send_user_id = json.loads(session['log'])['id']
    user = User()
    if not user.is_matched(send_user_id, msg['rec_user_id']):
        return
    chat_socket = Chat(send_user_id, msg['rec_user_id'])
    chat_socket.send(msg['message'])
    private_room = chat_socket.get_room()
    socketio.emit('mess_received', msg, room=private_room)
    notif_inst = Notif(send_user_id)
    notif_inst.send(msg['rec_user_id'], 'message')
コード例 #2
0
def get_messages():
    current_id = json.loads(session['log'])['id']
    chat_user_id = request.args.get('target_user_id')
    chat_socket = Chat(current_id, chat_user_id)
    messages = chat_socket.get()
    notif_inst = Notif(current_id)
    notif_inst.flush(chat_user_id, 'message')
    messages = format_timestamp(messages, current_id)
    user = User()
    if len(messages) > 0 and user.is_matched(current_id, chat_user_id):
        return jsonify(result=messages)
    return jsonify(result=[])