From 1b6cea77cf256b379348d83a99e035b9aa1124d4 Mon Sep 17 00:00:00 2001 From: R2 Date: Thu, 15 Feb 2024 15:13:27 +0700 Subject: [PATCH] Add messages.html and refactoring base.html, user.html --- app/templates/base.html | 32 ++++++++++++++++++++++++++++++++ app/templates/messages.html | 22 ++++++++++++++++++++++ app/templates/user.html | 3 +++ 3 files changed, 57 insertions(+) create mode 100644 app/templates/messages.html diff --git a/app/templates/base.html b/app/templates/base.html index 3f09a90..47d3f14 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -43,6 +43,16 @@ {{ _('Login') }} {% else %} + @@ -117,6 +127,28 @@ } } document.addEventListener('DOMContentLoaded', initialize_popovers); + + function set_message_count(n) { + const count = document.getElementById('message_count'); + count.innerText = n; + count.style.visibility = n ? 'visible' : 'hidden'; + } + + {% if current_user.is_authenticated %} + function initialize_notifications() { + let since = 0; + setInterval(async function() { + const response = await fetch('{{ url_for('main.notifications') }}?since=' + since); + const notifications = await response.json(); + for (let i = 0; i < notifications.length; i++) { + if (notifications[i].name == 'unread_message_count') + set_message_count(notifications[i].data); + since = notifications[i].timestamp; + } + }, 10000); + } + document.addEventListener('DOMContentLoaded', initialize_notifications); + {% endif %} \ No newline at end of file diff --git a/app/templates/messages.html b/app/templates/messages.html new file mode 100644 index 0000000..fe09eae --- /dev/null +++ b/app/templates/messages.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block content %} +

{{ _('Messages') }}

+ {% for post in messages %} + {% include '_post.html' %} + {% endfor %} + +{% endblock %} diff --git a/app/templates/user.html b/app/templates/user.html index 5b566a1..68bd886 100644 --- a/app/templates/user.html +++ b/app/templates/user.html @@ -28,6 +28,9 @@

{{ _('User') }}: {{ user.username }}

{% endif %} + {% if user != current_user %} +

{{ _('Send private message') }}

+ {% endif %}