Skip to content

Node.js based forum software built for the modern web

added badge to header for unread topics count

psychobunnyf1547a7b1f62
diff --git a/public/css/style.less b/public/css/style.less
index 46e3410ecb..d361197625 100644
--- a/public/css/style.less
+++ b/public/css/style.less
@@ -42,7 +42,7 @@ button, a {
vertical-align: 17%;
}
.nav .badge {
- vertical-align: 10%;
+ vertical-align: 2%;
}
#alert_window {
diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js
index cdf4c8a95c..82819e5f7d 100644
--- a/public/src/forum/unread.js
+++ b/public/src/forum/unread.js
@@ -56,6 +56,10 @@
$('#topics-container').empty();
$('#category-no-topics').removeClass('hidden');
app.alertSuccess('All topics marked as read!');
+ $('#numUnreadBadge')
+ .removeClass('badge-important')
+ .addClass('badge-inverse')
+ .html('0');
} else {
app.alertError('There was an error marking topics read!');
}
diff --git a/public/src/utils.js b/public/src/utils.js
index db25a91d0a..fce4d0ecdd 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -137,6 +137,22 @@
document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
if (numNotifications > 0) document.querySelector('.notifications a i').className = 'icon-circle active';
});
+
+ jQuery.getJSON(RELATIVE_PATH + '/api/unread/total', function(data) {
+ var badge = jQuery('#numUnreadBadge');
+ badge.html(data.count > 20 ? '20+' : data.count);
+
+ if (data.count > 0) {
+ badge
+ .removeClass('badge-inverse')
+ .addClass('badge-important')
+ }
+ else {
+ badge
+ .removeClass('badge-important')
+ .addClass('badge-inverse')
+ }
+ });
}
}
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index cd95b71d80..a806fd56de 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -49,7 +49,7 @@
<a href="/recent">Recent</a>
</li>
<li>
- <a href="/unread">Unread</a>
+ <a href="/unread"><span id="numUnreadBadge" class="badge badge-inverse">0</span> Unread</a>
</li>
<li>
<a href="/users">Users</a>
diff --git a/public/templates/unread.tpl b/public/templates/unread.tpl
index 7e4481aeac..9f0a32afc9 100644
--- a/public/templates/unread.tpl
+++ b/public/templates/unread.tpl
@@ -16,7 +16,7 @@
</div>
<div>
- <button id="mark-allread-btn" class="btn {show_markallread_button}">Mark All Read</button>
+ <button id="mark-allread-btn" class="btn {show_markallread_button}">Mark All As Read</button>
</div>
<div class="category row">
diff --git a/src/topics.js b/src/topics.js
index cc464a6a1a..ed437cc2f3 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -128,11 +128,16 @@ marked.setOptions({
}
Topics.getTotalUnread = function(uid, callback) {
- RDB.zcount('topics:recent', '-inf', '+inf', function(err, count) {
- if (err) count = 0;
- console.log(count);
+ RDB.zrevrange('topics:recent', 0, 21, function (err, tids) {
+ Topics.hasReadTopics(tids, uid, function(read) {
+ var unreadTids = tids.filter(function(tid, index, self) {
+ return read[index] === 0;
+ });
- callback(count);
+ callback({
+ count: unreadTids.length
+ });
+ });
});
};