diff --git a/app.py b/app.py index fb2e587..b078c40 100644 --- a/app.py +++ b/app.py @@ -63,7 +63,7 @@ class User(BaseModel): return len(Notification .select() .where( - Notification.target == self + (Notification.target == self) & (Notification.seen == 0) )) # A single public message. @@ -280,6 +280,13 @@ def private_timeline(): .order_by(Message.pub_date.desc())) return object_list('private_messages.html', messages, 'message_list') +@app.route('/explore/') +def public_timeline(): + messages = (Message + .select() + .order_by(Message.pub_date.desc())) + return object_list('explore.html', messages, 'message_list') + @app.route('/signup/', methods=['GET', 'POST']) def register(): if request.method == 'POST' and request.form['username']: @@ -409,6 +416,12 @@ def notifications(): .select() .where(Notification.target == user) .order_by(Notification.pub_date.desc())) + + with database.atomic(): + (Notification + .update(seen=1) + .where((Notification.target == user) & (Notification.seen == 0)) + .execute()) return object_list('notifications.html', notifications, 'notification_list', json=json, User=User) @app.route('/uploads/.jpg') diff --git a/templates/base.html b/templates/base.html index 3c90dd2..6875145 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,8 +12,13 @@ log in register {% else %} - {{ current_user.username }} - - explore + {{ current_user.username }} + {% set notification_count = current_user.unseen_notification_count() %} + {% if notification_count > 0 %} + ({{ notification_count }}) + {% endif %} + - + explore create log out {% endif %} diff --git a/templates/explore.html b/templates/explore.html new file mode 100644 index 0000000..e051af8 --- /dev/null +++ b/templates/explore.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% block body %} +

Explore

+ + {% include "includes/pagination.html" %} +{% endblock %} diff --git a/templates/includes/notification.html b/templates/includes/notification.html index 91a67a6..b891ede 100644 --- a/templates/includes/notification.html +++ b/templates/includes/notification.html @@ -3,6 +3,9 @@ {% if notification.type == 'follow' %} {% set user = User[detail['user']] %}

{{ user.username }} started following you.

+{% elif notification.type == 'mention' %} +{% set user = User[detail['user']] %} +

{{ user.username }} mentioned you in a message.

{% else %}

Unknown Notification

{% endif %}