Esempio n. 1
0
def user(user_id):
    user = User.query.filter_by(id=user_id).first_or_404()
    profile = user.profile
    total_friends = len(get_friends(user.id))
    friends = get_friends(user.id)
    limited_friends = friends[:6]

    user_id_1 = session["current_user"]["id"]
    notifications = get_notifications(user_id_1)

    are_friends, is_pending_sent, is_pending_recieved = are_friends_or_pending(
        user_id_1, user_id)

    conversation_id = conversation_exists(user.id, user_id_1)

    return render_template('profile.html',
                           user=user,
                           profile=profile,
                           total_friends=total_friends,
                           are_friends=are_friends,
                           is_pending_sent=is_pending_sent,
                           is_pending_recieved=is_pending_recieved,
                           friends=friends,
                           notifications=notifications,
                           limited_friends=limited_friends,
                           conversation_id=conversation_id)
Esempio n. 2
0
def new_conversation():
    cur_user_id = session["current_user"]["id"]
    notifications = get_notifications(cur_user_id)
    conversations = get_conversations(cur_user_id)
    return render_template("new_conversation.html",
                           conversations=conversations,
                           notifications=notifications)
Esempio n. 3
0
def get_user_data(user, current_user):
    are_friends, is_pending_sent, is_pending_received = are_friends_or_pending(
        current_user.id, user.id)
    friends = get_friends(user.id)
    limited_friends = friends[:6]
    total_friends = len(friends)
    notifications = get_notifications(current_user.id)
    conversation = conversation_exists(user.id, current_user.id)
    age = calculate_age(user.birthday)
    return are_friends, is_pending_sent, is_pending_received, friends, limited_friends, total_friends, notifications, conversation, age
Esempio n. 4
0
def friends(user_id):
    """Show all friends"""
    user = User.query.filter_by(id=user_id).first_or_404()
    user_id_1 = session["current_user"]["id"]
    are_friends, is_pending_sent, is_pending_recieved = are_friends_or_pending(
        user_id_1, user_id)

    friends = get_friends(user_id)
    limited_friends = friends[:6]
    total_friends = len(friends)
    notifications = get_notifications(session["current_user"]["id"])
    return render_template("friends.html",
                           user=user,
                           friends=friends,
                           total_friends=total_friends,
                           are_friends=are_friends,
                           is_pending_sent=is_pending_sent,
                           is_pending_recieved=is_pending_recieved,
                           notifications=notifications,
                           limited_friends=limited_friends)
Esempio n. 5
0
def conversation(id):
    conversation = Conversation.query.filter_by(id=id).first_or_404()
    cur_user_id = session["current_user"]["id"]
    notifications = get_notifications(cur_user_id)

    if cur_user_id == conversation.user_id_1:
        user_2 = User.query.filter_by(id=conversation.user_id_2).first()
    elif cur_user_id == conversation.user_id_2:
        user_2 = User.query.filter_by(id=conversation.user_id_1).first()
    else:
        return redirect(url_for('home'))

    messages_query = conversation.messages.order_by(desc(
        Message.timestamp)).limit(10).all()
    messages = messages_query[::-1]
    conversations = get_conversations(cur_user_id)
    return render_template("messenger.html",
                           conversation=conversation,
                           user_2=user_2,
                           conversations=conversations,
                           messages=messages,
                           notifications=notifications)
Esempio n. 6
0
def home():
    notifications = get_notifications(session["current_user"]["id"])
    return render_template('home.html',
                           title='Home',
                           notifications=notifications)