novu
novu copied to clipboard
[NV-1243] 🚀 Feature: Event/Hook for new Notifications
🔖 Feature description
An event/hook which fires when a new notification comes in
🎤 Why is this feature needed ?
Right now a workaround is by listening to DOM changes on the unseen badge see my working code below I currently use in combination with Swal2
let unseenBadgeSelector = "#unseen-badge";
setTimeout(() => {
let savedCount = ($(unseenBadgeSelector).html() == "" ? 0 :Number.parseInt($(unseenBadgeSelector).html()));
setInterval(() => {
let currentCount = ($(unseenBadgeSelector).html() == "" ? 0 :Number.parseInt($(unseenBadgeSelector).html()));
if(currentCount > savedCount){
$(document).trigger("new_novu_notification", [currentCount, (currentCount - savedCount)]);
savedCount = currentCount;
}
}, 1000);
}, 2500); // Wait for novu to load initial badge count
$(document).on("new_novu_notification", function (totalNotifications, newNotifications){
Swal.fire({
text: `${newNotifications} new notification(s)`,
toast: true,
position: 'top-right',
showConfirmButton: false,
timer: 3000
});
});
✌️ How do you aim to achieve this?
By using the existing trigger system which also fires action_click and notification_click events
🔄️ Additional Information
No response
👀 Have you spent some time to check if this feature request has been raised before?
- [X] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [X] I have read the Contributing Guidelines
Are you willing to submit PR?
No response
Hi @JustinBack ! Do you want to pick this one up? if so, LMK and we can see how ti. fits in the roadmap.
Yeah I can pick this up, not immediately but over the next weeks I can start the PR
Hi Guys,
It already works if you use the socket with event 'notification_received' :)