示例#1
0
def get_messages(data):
    try:
        username = data["username"]
        other_user = data["other_user"]
    except KeyError:
        emit('Error', {
            "message": "Invalid keys in get_messages",
            "show": "false"
        })
        return

    message, timestamp, from_user = db.get_messages(username, other_user)

    messages = []
    if message != []:
        for i in range(len(message)):
            print(i)
            messages.append({
                "message": message[i],
                "time": timestamp[i].strftime("%B %-d, %-I:%-M%p"),
                "from": from_user[i]
            })

    response = {
        "success": "success",
        "other_user": other_user,
        "messages": messages
    }

    emit("messages", response)
示例#2
0
def messages():
    id_token = request.headers['Authorization']
    thread_id = None
    if 'thread_id' in request.args:
        thread_id = request.args.get('thread_id')

    print('Get Messages: ' + str(thread_id))
    error_message = None
    claims = None

    if id_token:
        try:
            # Verify the token against the Firebase Auth API.
            # TODO: cache results in an encrypted session store.
            # See http://flask.pocoo.org/docs/1.0/quickstart/#sessions.
            claims = google.oauth2.id_token.verify_firebase_token(
                id_token, firebase_request_adapter)
            uid = claims['sub']
            messages = get_messages(uid, thread_id)
            return jsonify(messages)

        except ValueError as exc:
            # This will be raised if the token is expired or any other
            # verification checks fail.
            error_message = str(exc)
    return error_message
示例#3
0
def get_older_messages(room_id):
    room = get_room(room_id)
    if room and is_room_member(room_id, current_user.username):
        page = int(request.args.get('page', 0))
        messages = get_messages(room_id, page)
        return dumps(messages)
    else:
        return "Room not found", 404
示例#4
0
文件: user.py 项目: Rplubell/Akai
 def message_history(self):
     for message in database.get_messages(self.name):
         sender = database.get_user_by_id(message['sender'])
         receiver = database.get_user_by_id(message['receiver'])
         if sender['name'] == self.name:
             self.send_message('USERMSGSNT %s :%s' %
                               (receiver['name'], message['message']))
         else:
             self.send_message('USERMSG %s :%s' %
                               (sender['name'], message['message']))
示例#5
0
def get_user_messages_by_token():
    arg = request.args.to_dict()
    token = arg.get('token', None)
    email = logged_in_users.get(token, None)
    if email:
        response = database.get_messages(email_to=email)
        response = {'success': True, 'message': 'User messages retrieved.', 'data': response}
    else:
        response = {'success': False, 'message': 'You are not signed in.'}

    return jsonify(response)
示例#6
0
def view_room(room_id):
    room = get_room(room_id)
    if room and is_room_member(room_id, current_user.username):
        room_members = get_room_members(room_id)
        messages = get_messages(room_id)
        return render_template('view_room.html',
                               username=current_user.username,
                               room=room,
                               room_members=room_members,
                               messages=messages)
    else:
        return "Room not found", 404
示例#7
0
def home():
    global email
    if (request.method == 'POST'):
        email = request.form['email']
        password = request.form['pw']
        db.create_connection()
        authenticate(email, password)
        for item in db.get_messages():
            if (item[1] == email):
                messages.append(
                    (item[0], item[2], "".join(cc.decode(item[2], 3))))
        for item in db.get_images():
            if (item[1] == email):
                images.append((item[0], item[2]))
        return render_template('home.html',
                               email=email,
                               messages=messages,
                               images=images)
    else:
        return render_template('login.html')
示例#8
0
def index():
    return {"messages":get_messages()}
示例#9
0
文件: main.py 项目: rako210/Comp4050
def get_messages(db):

    user_id = users.get_userID(db)
    user_messages = database.get_messages(db, user_id)
    return {'data': user_messages}