Nodebb: The Nodebb does not post alerts and does not sound alerts

Created on 25 Nov 2020  Â·  12Comments  Â·  Source: NodeBB/NodeBB

  • NodeBB version: 1.15.2

  • Installed NodeBB Plugins:
  • Database type: mongo, redis, or postgres
  • Database version: mongo
  • Exact steps to cause this issue: Any situation that the forum sends an alert to

  • What you expected: To send a pop-up alert to the user
  • What happened instead: The alert is saved in the alerts, but there is no sound or alert about it.

Most helpful comment

Full code for custom js tab

socket.on('event:new_notification', function (notifData) { 
        const audio = new Audio('https://your-file.mp3');
        audio.play();
    app.alert({
        alert_id: 'new_notif',
        type: 'info',
        title: '[[notifications:new_notification]]',
        timeout: 5000,
        message: notifData.bodyShort,
        clickfn: function () {
            socket.emit('notifications.markRead', notifData.nid);
            if (notifData.path) {
                if (notifData.path.startsWith('http') || notifData.path.startsWith('https')) {
                    window.location.href = notifData.path;
                } else {
                    window.location.href = window.location.protocol + '//' + window.location.host + config.relative_path + notifData.path;
                }
            }           
        }
    });
});

All 12 comments

Are you looking for desktop notifications?

Maybe https://github.com/NodeBB/NodeBB/issues/4695?

The toasters that were displayed on every notification got removed in https://github.com/NodeBB/NodeBB/commit/fd4c3cda42d1e8f91a338f12ed087ff5aa237dca. Since you get a notification counter in the header.

The usual alerts that were always on the right.
It disappeared.
The sound on a new alert also disappears and does not appear on the settings page.

Sounds were removed too in https://github.com/NodeBB/NodeBB/pull/8617

this is horrible mistake, that's my opinion.

i think most of the people will want sound alerts.
as much as the app.alert's that are removed too.

this is very useful. Especially in forums with a very active community - so you have to zigzag between threads every minute - the visual alerts and even more - the voice alerts - were extremely useful.

I will ask simply - why not give it a possibility to set it up? By default - visual alerts and sound will be turned off. But that it will be possible to define differently, for those who need it.

@barisusakli @julianlam

I think it is not wise - disabling such an option.
I've seen a lot of angry posts on the subject in various nodeBB forums,
In my opinion, this should be allowed, but they can add a setting that any user can disable or enable these toast alerts and sounds.

I disagree, and support the removal. I think anger from anyone is an odd overreaction . You could look into making a plugin if you need such things perhaps?

Custom JS tab in acp can be used to bring back alerts for every notification as well. Just put this in your custom js tab if you don't want to build a plugin.

socket.on('event:new_notification', function (notifData) { 
    app.alert({
        alert_id: 'new_notif',
        type: 'info',
        title: '[[notifications:new_notification]]',
        timeout: 5000,
        message: notifData.bodyShort,
        clickfn: function () {
            socket.emit('notifications.markRead', notifData.nid);
            if (notifData.path) {
                if (notifData.path.startsWith('http') || notifData.path.startsWith('https')) {
                    window.location.href = notifData.path;
                } else {
                    window.location.href = window.location.protocol + '//' + window.location.host + config.relative_path + notifData.path;
                }
            }           
        }
    });
});

thank you @barisusakli !!
this is very helpful!!

but if you can do it for the notifications, maybe you can share us with some code for the sound alerts?
this is very important for some forums i know.

thank you

You can play sounds with the below code in modern browsers

  const audio = new Audio(urlToSoundToPlay);
  audio.play();

Just upload a notification sound on your server or use a public one.

Full code for custom js tab

socket.on('event:new_notification', function (notifData) { 
        const audio = new Audio('https://your-file.mp3');
        audio.play();
    app.alert({
        alert_id: 'new_notif',
        type: 'info',
        title: '[[notifications:new_notification]]',
        timeout: 5000,
        message: notifData.bodyShort,
        clickfn: function () {
            socket.emit('notifications.markRead', notifData.nid);
            if (notifData.path) {
                if (notifData.path.startsWith('http') || notifData.path.startsWith('https')) {
                    window.location.href = notifData.path;
                } else {
                    window.location.href = window.location.protocol + '//' + window.location.host + config.relative_path + notifData.path;
                }
            }           
        }
    });
});

There's also the desktop notifications plugin!

Was this page helpful?
0 / 5 - 0 ratings