Ejemplo n.º 1
0
def contacts():
    u = current_user()
    all_contacts = Message.contacts(user_id=u.id)

    contacts_returned = [c.json() for c in all_contacts]
    contacts_returned.sort(key=lambda c: c['updated_time'])

    for c in contacts_returned:
        if c['receiver_id'] == u.id:
            c['other'] = User.one(id=c['sender_id']).json()
        elif c['sender_id'] == u.id:
            c['other'] = User.one(id=c['receiver_id']).json()
        # 都不满足,就会没有 other 字段

    return json_succeed(
        user=u.json(),
        contacts=contacts_returned,
    )