Node.js based forum software built for the modern web
Fix: send unread count with new notifications (#14632)
palmoni556ade8c9a6ee
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.jsindex 8b7e1b8d3c..d0e346890f 100644--- a/public/src/modules/notifications.js+++ b/public/src/modules/notifications.js@@ -103,7 +103,8 @@ define('notifications', [});};- Notifications.onNewNotification = async function (notifData) {+ Notifications.onNewNotification = async function (data) {+ const { notification: notifData, unreadCount } = data;if (ajaxify.currentPage === 'notifications') {ajaxify.refresh();}@@ -122,8 +123,9 @@ define('notifications', [return;}- const { unread } = await api.get('/notifications/count');- Notifications.updateNotifCount(unread);+ if (unreadCount !== undefined) {+ Notifications.updateNotifCount(unreadCount);+ }if (!unreadNotifs[notifData.nid]) {unreadNotifs[notifData.nid] = notifData;diff --git a/src/notifications.js b/src/notifications.jsindex aebc6fbca7..c96a309406 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -248,7 +248,13 @@ async function pushToUids(uids, notification) {uid,notification,});- websockets.in(`uid_${uid}`).emit('event:new_notification', notification);+ const uidsInRoom = await websockets.getUidsInRoom(`uid_${uid}`);+ let unreadCount;+ if (uidsInRoom.length) {+ // only calculate the unread count for users connected right now+ unreadCount = await User.notifications.getUnreadCount(uid);+ }+ websockets.in(`uid_${uid}`).emit('event:new_notification', { notification, unreadCount });}));}}