示例#1
0
def update_chat(chat_id):
    # TODO: Add authentication allowing any member of the chat to use
    data = request.get_json()
    chat_name = data.get("chat_name")
    background = data.get("background")

    chat = Chat.get(Chat.id == chat_id)
    if chat_name:
        query = Chat.update(name=chat_name).where(Chat.id == chat_id)
        query.execute()
    elif background:
        query = Chat.update(background=background).where(Chat.id == chat_id)
        query.execute()
    chat = Chat.get(Chat.id == chat_id)

    return jsonify(model_to_dict(chat)), 200
示例#2
0
def send_message_to_chat(chat_id):
    """
    Adds a specified message to a chat identified by url "chat_id"

    Client must post json including:
        "type": either 'text' or 'image'
        "content": corresponds to above, message or url
        "size": text only. 0.5 is normal size, spans from 0 to 1
    """
    # TODO: Add authentication allowing any member of the chat to use
    data = request.get_json()

    kind = data.get("type")
    content = data.get("content")
    size = data.get("size")
    if kind != "text" and kind != "image":
        return str("Wrong type"), 400
    elif size < 0 or size > 1:
        return str("Bad size"), 400
    # TODO: if set to "image" test to make sure its a valid url

    message = {
        "event": "message",
        "payload": {
            "sender_id": 1,
            "type": kind,
            "content": content,
            "size": size,
            "seen_by": []
        }
    }
    # TODO: Stop hardcoding the sender_id, and get the id using auth
    events = Chat.get(Chat.id == chat_id).events
    events.append(message)
    query = Chat.update(events=events).where(Chat.id == chat_id)
    query.execute()
    # TODO: Update this using PostgreSQL json assessing features

    return jsonify(events), 200
示例#3
0
def unlike_message(chat_id):
    # TODO: Add authentication allowing any member of the chat to use
    data = request.get_json()

    message_index = data.get("message_index")

    # TODO: if set to "image" test to make sure its a valid url

    like = {
        "event": "dislike",
        "payload": {
            "sender_id": 1,
            "message_index": message_index,
        }
    }
    # TODO: Stop hardcoding the sender_id, and get the id using auth
    events = Chat.get(Chat.id == chat_id).events
    events.append(like)
    query = Chat.update(events=events).where(Chat.id == chat_id)
    query.execute()
    # TODO: Update this using PostgreSQL json assessing features

    return jsonify(events), 200