mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: show more unread notifs
This commit is contained in:
@@ -16,20 +16,25 @@ UserNotifications.get = function (uid, callback) {
|
|||||||
if (parseInt(uid, 10) <= 0) {
|
if (parseInt(uid, 10) <= 0) {
|
||||||
return setImmediate(callback, null, { read: [], unread: [] });
|
return setImmediate(callback, null, { read: [], unread: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let unread;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
getNotifications(uid, 0, 9, next);
|
getNotificationsFromSet('uid:' + uid + ':notifications:unread', uid, 0, 29, next);
|
||||||
},
|
},
|
||||||
function (notifications, next) {
|
function (_unread, next) {
|
||||||
notifications.read = notifications.read.filter(Boolean);
|
unread = _unread.filter(Boolean);
|
||||||
notifications.unread = notifications.unread.filter(Boolean);
|
if (unread.length < 30) {
|
||||||
|
getNotificationsFromSet('uid:' + uid + ':notifications:read', uid, 0, 29 - unread.length, next);
|
||||||
var maxNotifs = 15;
|
} else {
|
||||||
if (notifications.read.length + notifications.unread.length > maxNotifs) {
|
next(null, []);
|
||||||
notifications.read.length = maxNotifs - notifications.unread.length;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
next(null, notifications);
|
function (read, next) {
|
||||||
|
next(null, {
|
||||||
|
read: read.filter(Boolean),
|
||||||
|
unread: unread,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
@@ -102,18 +107,7 @@ function deleteUserNids(nids, uid, callback) {
|
|||||||
], nids, callback);
|
], nids, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNotifications(uid, start, stop, callback) {
|
function getNotificationsFromSet(set, uid, start, stop, callback) {
|
||||||
async.parallel({
|
|
||||||
unread: function (next) {
|
|
||||||
getNotificationsFromSet('uid:' + uid + ':notifications:unread', false, uid, start, stop, next);
|
|
||||||
},
|
|
||||||
read: function (next) {
|
|
||||||
getNotificationsFromSet('uid:' + uid + ':notifications:read', true, uid, start, stop, next);
|
|
||||||
},
|
|
||||||
}, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNotificationsFromSet(set, read, uid, start, stop, callback) {
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
db.getSortedSetRevRange(set, start, stop, next);
|
db.getSortedSetRevRange(set, start, stop, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user