mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
fixed #4294
This commit is contained in:
@@ -208,8 +208,30 @@ var async = require('async'),
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, 0);
|
||||
}
|
||||
db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
|
||||
callback(err, Array.isArray(nids) ? nids.length : 0);
|
||||
|
||||
// Collapse any notifications with identical mergeIds
|
||||
async.waterfall([
|
||||
async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':notifications:unread', 0, 99),
|
||||
function(nids, next) {
|
||||
var keys = nids.map(function(nid) {
|
||||
return 'notifications:' + nid;
|
||||
});
|
||||
|
||||
db.getObjectsFields(keys, ['mergeId'], next);
|
||||
}
|
||||
], function(err, mergeIds) {
|
||||
// A missing (null) mergeId means that notification is counted separately.
|
||||
mergeIds = mergeIds.map(function(set) {
|
||||
return set.mergeId;
|
||||
});
|
||||
|
||||
callback(err, mergeIds.reduce(function(count, cur, idx, arr) {
|
||||
if (cur === null || idx === arr.indexOf(cur)) {
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}, 0));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user