mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: only mark notifications read that match current filter
closes #13574
This commit is contained in:
@@ -13,7 +13,7 @@ define('forum/notifications', ['components', 'notifications'], function (compone
|
||||
notifications.handleUnreadButton(listEl);
|
||||
|
||||
components.get('notifications/mark_all').on('click', function () {
|
||||
notifications.markAllRead(function () {
|
||||
notifications.markAllRead(ajaxify.data.selectedFilter.filter, function () {
|
||||
components.get('notifications/item').removeClass('unread');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -105,7 +105,7 @@ define('notifications', [
|
||||
});
|
||||
|
||||
if (!unreadNotifs[notifData.nid]) {
|
||||
unreadNotifs[notifData.nid] = true;
|
||||
unreadNotifs[notifData.nid] = notifData;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -165,12 +165,21 @@ define('notifications', [
|
||||
}
|
||||
};
|
||||
|
||||
Notifications.markAllRead = function () {
|
||||
socket.emit('notifications.markAllRead', function (err) {
|
||||
Notifications.markAllRead = function (filter = '') {
|
||||
socket.emit('notifications.markAllRead', { filter }, function (err) {
|
||||
if (err) {
|
||||
alerts.error(err);
|
||||
}
|
||||
unreadNotifs = {};
|
||||
if (filter) {
|
||||
Object.keys(unreadNotifs).forEach(nid => {
|
||||
if (unreadNotifs[nid].type === filter) {
|
||||
delete unreadNotifs[nid];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
unreadNotifs = {};
|
||||
}
|
||||
|
||||
const notifEls = $('[component="notifications/list"] [data-nid]');
|
||||
notifEls.removeClass('unread');
|
||||
notifEls.find('.mark-read .unread').addClass('hidden');
|
||||
|
||||
@@ -383,10 +383,20 @@ Notifications.markReadMultiple = async function (nids, uid) {
|
||||
]);
|
||||
};
|
||||
|
||||
Notifications.markAllRead = async function (uid) {
|
||||
Notifications.markAllRead = async function (uid, filter = '') {
|
||||
await batch.processSortedSet(`uid:${uid}:notifications:unread`, async (unreadNotifs) => {
|
||||
const nids = unreadNotifs.map(n => n && n.value);
|
||||
const datetimes = unreadNotifs.map(n => n && n.score);
|
||||
let nids = unreadNotifs.map(n => n && n.value);
|
||||
let datetimes = unreadNotifs.map(n => n && n.score);
|
||||
if (filter !== '') {
|
||||
const notificationKeys = nids.map(nid => `notifications:${nid}`);
|
||||
let notificationData = await db.getObjectsFields(notificationKeys, ['nid', 'type', 'datetime']);
|
||||
notificationData = notificationData.filter(n => n && n.nid && n.type === filter);
|
||||
if (!notificationData.length) {
|
||||
return;
|
||||
}
|
||||
nids = notificationData.map(n => n.nid);
|
||||
datetimes = notificationData.map(n => n.datetime || Date.now());
|
||||
}
|
||||
await Promise.all([
|
||||
db.sortedSetRemove(`uid:${uid}:notifications:unread`, nids),
|
||||
db.sortedSetAdd(`uid:${uid}:notifications:read`, datetimes, nids),
|
||||
|
||||
@@ -34,8 +34,8 @@ SocketNotifs.markUnread = async function (socket, nid) {
|
||||
user.notifications.pushCount(socket.uid);
|
||||
};
|
||||
|
||||
SocketNotifs.markAllRead = async function (socket) {
|
||||
await notifications.markAllRead(socket.uid);
|
||||
SocketNotifs.markAllRead = async function (socket, data) {
|
||||
await notifications.markAllRead(socket.uid, data.filter);
|
||||
user.notifications.pushCount(socket.uid);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user