notifications.create then notifications.push not showing unread notification alert

NodeBB Development
  • I am able to get the notification alert to appear but it does not show inside the header notifications/icon.

    Screen Shot 2018-12-24 at 11.26.09 AM.png

    What am i doing wrong here?

     var websockets = require.main.require('./src/');
            bodyShort: `Yay, this is a notification!`,
            pid: pid,
            path: '/post/' + pid,
            nid: 'tid:' + tid + ':uid:' + uid,
            tid: tid,
            from: 1, // 1 is my admin account 
        }, (err, notification)=>{
            console.log(notification); // this response object is OK
            notifications.push(notification, [uid], ()=>{
                console.log('Notification created')

    I just want to make this notification show inside the notifications icon.

    Note: When this code triggers the client user logged in does see a small alert message appear, however, the actual notification icon does not show the unread status indicator.

    Do I need to set a special 'type' key on the notifications object I'm creating?

    Thank you everyone for your help. Happy holidays.

  • Happy holidays!

    Are you using a custom theme? Does it work on persona?

    You can add some debugging console.logs in here to see if the unread counter is actually being incremented. It has a data-content attribute which should change when a new notification is received.

  • @baris I am using the persona theme with my own custom theme installed . However, my custom theme is not doing any major changes to the default persona theme that are related to the unread counter.

    I have added a console.log to:

    // nodebb/public/src/modules/notifications.js
    Notifications.updateNotifCount = function (count) {
      console.log('updateNotifCount count:', count); // 0

    Screen Shot 2018-12-24 at 1.21.32 PM.png

    The notification alert message does appear OK.
    I get the following alert message "NEW NOTIFICATION" from the notification being triggered (screenshot):
    Screen Shot 2018-12-24 at 1.21.16 PM.png

    However the console.log on the count object coming from the Notifications.updateNotifCount === 0

    So to answer your question: The result of the console.log related to the count object is showing 0.

    What should I try next?

    Thank you!

  • If you are seeing 0 there the notification might already be marked read before it gets to the client side. Do you see the notification at /notifications? If so you have to figure out why it is being marked as read. I would also try on a default persona install just to rule out any theme interference.

  • I reviewed my code and my plugin is automatically bringing the user to the new post page via ajaxify.go().... It appears that when you go directly to a new post the unread notification associated with this is automatically marked as read.

    Thanks for your help.

  • One other question that maybe you or somebody else knows the answer… I have been testing and have noticed that when you create the notification if the person creating the notification has admin privileges than all the administrators also receive the notification.

    So for example the user who creates the post has administrative privileges and the notification is created and pushed and that user is able to see the notification on their account however all of the other users who also have administrative privileges also receive the same notification… Is this the intended default behavior or is this potential bug?

    I am trying to determine if there is some setting that I missed or if I need to write a tweak to the code to make sure that the other administrators do not see the notification that was only intended for the administrator who posted the content.


  • Unless you are pushing the notification to the administrators group that is not intended.

  • @baris in notification data object passed to notifications.create what option would need to be passed to specify a specific group?

    My example above has somehow a relationship to admin group?

  • @jzbg said in notifications.create then notifications.push not showing unread notification alert:

    notifications.push(notification, [uid], ()=>{

    This should only push the notification to uid, to push it to groups you need to use notifications.pushToGroup(s)

  • I solved my own problem... I setup a custom notification to fire on the hook and I was using the same default standard format for the notifications nid value. Basically I was firing off a notification with the same nid as the notification that auto generates when you post a new topic.

    Long story short: Make sure the nid is unique. ☺

Suggested Topics