novu icon indicating copy to clipboard operation
novu copied to clipboard

[NV-1243] 🚀 Feature: Event/Hook for new Notifications

Open JustinBack opened this issue 2 years ago • 2 comments

🔖 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?

Are you willing to submit PR?

No response

NV-1243

JustinBack avatar Oct 14 '22 12:10 JustinBack

Hi @JustinBack ! Do you want to pick this one up? if so, LMK and we can see how ti. fits in the roadmap.

oba2311 avatar Dec 19 '22 08:12 oba2311

Yeah I can pick this up, not immediately but over the next weeks I can start the PR

JustinBack avatar Dec 19 '22 08:12 JustinBack

Hi Guys,

It already works if you use the socket with event 'notification_received' :)

TNAJanssen avatar Apr 05 '23 19:04 TNAJanssen