예제 #1
0
def chat_info(chat_id):
    chat = Chat.get(Chat.id == chat_id)
    users = [
        model_to_dict(x.user)
        for x in Participation.select().where(Participation.chat == chat_id)
    ]
    return dict(chat=model_to_dict(chat), users=users)
예제 #2
0
def list_user_chats(user_id):
    """List all chats for a given user"""
    chats = []
    raw_chats = Participation.select().where(Participation.user == user_id)
    for item in raw_chats:
        chat = Chat.get(Chat.id == item.chat)
        chats.append(model_to_dict(chat))
    return jsonify(chats), 200
예제 #3
0
def chat_updates(user_id):
    """List all chat updates for a given user"""
    chats = []
    raw_chats = Participation.select().where(Participation.user == user_id)
    for item in raw_chats:
        events = item.chat.events
        updates = events[item.cursor:]
        if updates:
            chats.append({"chat": int(item.chat.id), "events": updates})
    return jsonify(chats), 200