notifications: Fix desktop notifications for message not grouping.

Earlier, message notifications for same key would not get grouped
together because of the old notification_object close event listener
firing up when not supposed to.

This commit fixes this behaviour by checking the notification object
instance is the same as the currently displayed notification object
from notice memory when closing it.

Co-authored-by: prakhar1144 <prakhar@zulip.com>
(cherry picked from commit 6af4e82c49)
This commit is contained in:
Pratik Chanda
2025-08-18 16:45:49 +05:30
committed by Tim Abbott
parent cd682f3dee
commit 6052630cae

View File

@@ -215,7 +215,12 @@ export function process_notification(notification: {
window.focus();
});
notification_object.addEventListener("close", () => {
desktop_notifications.notice_memory.delete(key);
const current_notice_memory = desktop_notifications.notice_memory.get(key);
// This check helps avoid race between close event for current notification
// object and the previous notification_object close handler.
if (current_notice_memory?.obj === notification_object) {
desktop_notifications.notice_memory.delete(key);
}
});
}
}