mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
final pass, #999
This commit is contained in:
@@ -19,10 +19,12 @@ var async = require('async'),
|
||||
Notifications.get = function(nid, uid, callback) {
|
||||
|
||||
db.exists('notifications:' + nid, function(err, exists) {
|
||||
if(!exists) {
|
||||
if (err) {
|
||||
winston.error('[notifications.get] Could not retrieve nid ' + nid + ': ' + err.message);
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
||||
|
||||
db.getObjectFields('notifications:' + nid, ['nid', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
|
||||
@@ -31,6 +33,23 @@ var async = require('async'),
|
||||
callback(notification);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Remove from the user's boxes
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('[notifications.get] nid ' + nid + ' not found. Removing.');
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nid, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetRemove('uid:' + uid + ':notifications:read', nid, next);
|
||||
}
|
||||
], function(err) {
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
14
src/user.js
14
src/user.js
@@ -999,13 +999,9 @@ var bcrypt = require('bcryptjs'),
|
||||
|
||||
async.map(nids, function(nid, next) {
|
||||
notifications.get(nid, uid, function(notif_data) {
|
||||
if(!notif_data) {
|
||||
db.sortedSetRemove(set, nid);
|
||||
} else {
|
||||
if(typeof iterator === 'function') {
|
||||
iterator(notif_data);
|
||||
}
|
||||
}
|
||||
|
||||
next(null, notif_data);
|
||||
});
|
||||
@@ -1018,7 +1014,9 @@ var bcrypt = require('bcryptjs'),
|
||||
async.parallel({
|
||||
unread: function(next) {
|
||||
getNotifications('uid:' + uid + ':notifications:unread', 0, 9, function(notif_data) {
|
||||
if (notif_data) {
|
||||
notif_data.readClass = !notif_data.read ? 'label-warning' : '';
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
read: function(next) {
|
||||
@@ -1029,6 +1027,14 @@ var bcrypt = require('bcryptjs'),
|
||||
return calback(err);
|
||||
}
|
||||
|
||||
// Remove empties
|
||||
notifications.read = notifications.read.filter(function(notifObj) {
|
||||
return notifObj;
|
||||
});
|
||||
notifications.unread = notifications.unread.filter(function(notifObj) {
|
||||
return notifObj;
|
||||
});
|
||||
|
||||
// Limit the number of notifications to `maxNotifs`, prioritising unread notifications
|
||||
if (notifications.read.length + notifications.unread.length > maxNotifs) {
|
||||
notifications.read.length = maxNotifs - notifications.unread.length;
|
||||
|
||||
Reference in New Issue
Block a user