diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js
index 4c05432027..aa94b302c5 100644
--- a/public/src/forum/footer.js
+++ b/public/src/forum/footer.js
@@ -109,6 +109,7 @@
numUnread = data.unread.length,
x;
notifList.innerHTML = '';
+ console.log(data);
if ((data.read.length + data.unread.length) > 0) {
for (x = 0; x < numUnread; x++) {
notifEl.setAttribute('data-nid', data.unread[x].nid);
@@ -123,15 +124,16 @@
notifFrag.appendChild(notifEl.cloneNode(true));
}
} else {
+ notifEl.className = 'no-notifs';
notifEl.innerHTML = 'You have no notifications';
- notifFrag.appendChild(notifEl);
+ notifFrag.appendChild(notifEl.cloneNode(true));
}
// Add dedicated link to /notifications
notifEl.removeAttribute('data-nid');
notifEl.className = 'pagelink';
notifEl.innerHTML = 'See all Notifications';
- notifFrag.appendChild(notifEl);
+ notifFrag.appendChild(notifEl.cloneNode(true));
notifList.appendChild(notifFrag);
diff --git a/src/notifications.js b/src/notifications.js
index 4ff52af1a8..2cf1aa37ab 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -7,10 +7,13 @@ var RDB = require('./redis.js'),
RDB.multi()
.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId')
.zrank('uid:' + uid + ':notifications:read', nid)
+ .exists('notifications:' + nid)
.exec(function(err, results) {
var notification = results[0]
readIdx = results[1];
+ if (!results[2]) return callback(null);
+
callback({
nid: nid,
text: notification[0],
@@ -41,6 +44,19 @@ var RDB = require('./redis.js'),
});
});
},
+ destroy: function(nid) {
+ var multi = RDB.multi();
+
+ multi.del('notifications:' + nid);
+ multi.srem('notifications', nid);
+
+ multi.exec(function(err) {
+ if (err) {
+ winston.error('Problem deleting expired notifications. Stack follows.');
+ winston.error(err.stack);
+ }
+ });
+ },
push: function(nid, uids, callback) {
if (!Array.isArray(uids)) uids = [uids];
@@ -153,15 +169,24 @@ var RDB = require('./redis.js'),
var numInboxes = results.inboxes.length,
x;
- async.each(results.nids, function(nid, next) {
+ async.eachSeries(results.nids, function(nid, next) {
var multi = RDB.multi();
for(x=0;x 0) {
async.eachSeries(nids, function(nid, next) {
notifications.get(nid, uid, function(notif_data) {
- unread.push(notif_data);
+ // If the notification could not be found, silently drop it
+ if (notif_data) {
+ unread.push(notif_data);
+ } else {
+ RDB.zrem('uid:' + uid + ':notifications:unread', nid);
+ }
+
next();
});
}, function(err) {
@@ -925,7 +931,13 @@ var utils = require('./../public/src/utils.js'),
if (nids && nids.length > 0) {
async.eachSeries(nids, function(nid, next) {
notifications.get(nid, uid, function(notif_data) {
- read.push(notif_data);
+ // If the notification could not be found, silently drop it
+ if (notif_data) {
+ read.push(notif_data);
+ } else {
+ RDB.zrem('uid:' + uid + ':notifications:read', nid);
+ }
+
next();
});
}, function(err) {