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 %}
+
+ {{ _('Messages') }}
+ {% set unread_message_count = current_user.unread_message_count() %}
+
+ {{ unread_message_count }}
+
+
+
{{ _('Profile') }}
@@ -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 %}