Skip to content

Node.js based forum software built for the modern web

fix: closes #14355 dont flash unread notif for topics

Barış Soner Uşaklı0e8544b8eb1a
diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js
index 10c5d54cf2..6d66e85d0b 100644
--- a/public/src/client/topic/events.js
+++ b/public/src/client/topic/events.js
@@ -44,7 +44,6 @@ define('forum/topic/events', [
'posts.downvote': togglePostVote,
'posts.unvote': togglePostVote,
- 'event:new_notification': onNewNotification,
'event:new_post': posts.onNewPost,
};
@@ -258,12 +257,5 @@ define('forum/topic/events', [
}).toggleClass('downvoted', data.downvote);
}
- function onNewNotification(data) {
- const tid = ajaxify.data.tid;
- if (data && data.tid && String(data.tid) === String(tid)) {
- socket.emit('topics.markTopicNotificationsRead', [tid]);
- }
- }
-
return Events;
});
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index 7e4cf91ebb..3649884d01 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -95,17 +95,22 @@ define('notifications', [
});
};
- Notifications.onNewNotification = function (notifData) {
+ Notifications.onNewNotification = async function (notifData) {
if (ajaxify.currentPage === 'notifications') {
ajaxify.refresh();
}
- if (ajaxify.data.template.chats && parseInt(ajaxify.data.roomId, 10) === parseInt(notifData.roomId, 10)) {
+ const { template } = ajaxify.data;
+ if (template.chats && String(ajaxify.data.roomId) === String(notifData.roomId)) {
return;
}
- api.get('/notifications/count').then(({ unread }) => {
- Notifications.updateNotifCount(unread);
- }).catch(alerts.error);
+ if (template.topic && String(ajaxify.data.tid) === String(notifData.tid)) {
+ await socket.emit('topics.markTopicNotificationsRead', [notifData.tid]);
+ return;
+ }
+
+ const { unread } = await api.get('/notifications/count');
+ Notifications.updateNotifCount(unread);
if (!unreadNotifs[notifData.nid]) {
unreadNotifs[notifData.nid] = notifData;