mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-26 17:29:53 +01:00
completed notifications pruning method
This commit is contained in:
@@ -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 = '<a>You have no notifications</a>';
|
||||
notifFrag.appendChild(notifEl);
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
}
|
||||
|
||||
// Add dedicated link to /notifications
|
||||
notifEl.removeAttribute('data-nid');
|
||||
notifEl.className = 'pagelink';
|
||||
notifEl.innerHTML = '<a href="' + RELATIVE_PATH + '/notifications">See all Notifications</a>';
|
||||
notifFrag.appendChild(notifEl);
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
|
||||
notifList.appendChild(notifFrag);
|
||||
|
||||
|
||||
@@ -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<numInboxes;x++) {
|
||||
multi.zscore(inboxKey, results.inboxes[x]);
|
||||
multi.zscore(results.inboxes[x], nid);
|
||||
}
|
||||
|
||||
multi.exec(function(results) {
|
||||
multi.exec(function(err, results) {
|
||||
// If the notification is not present in any inbox, delete it altogether
|
||||
var expired = results.every(function(present) {
|
||||
if (present === null) return true;
|
||||
});
|
||||
|
||||
if (expired) {
|
||||
notifications.destroy(nid);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
|
||||
|
||||
16
src/user.js
16
src/user.js
@@ -903,7 +903,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) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user