Is there a way to get notifications/chat/new messages indicator ?

Moved Technical Support
  • Evening, I'm facing a question, is it possible with a socket event listener to get an update whenever something new happens. New unread messages, new notifications & new chat ?
    The idea is that on my theme I've hidden this information and it's available when the menu is open but I want to be able to visually say hey there's new stuff open me.
    Any idea on how I could do this ? I've thought of a SetInterval checking for notifications/messages/chat but performance wise it's absolutely not something cool.
    I need this information cause I may change how my theme works now if not available.
    Thanks for the further help/answers.

  • socket.on('event:new_post', callback) to catch a new post
    socket.on('event:new_topic', callback) to catch a new topic
    socket.on('event:new_notification', callback) to catch a new notification
    socket.on('event:chats.receive', callback) to catch a new chat message.

    Most of these are already used in core, but you can add your own listeners to add custom logic.

  • @baris Thanks a lot I'll try this tommorow too tired 🙂

  • @baris It's working perfectly but for everybody is there a way to restrict the events to one concerned user ? I imagine that in the callback you have to test window.app.uid and maybe a socket.uid ?
    I wanted to know if there's a way to check for the actual values, because this events gets fired only when something new is coming and the user is logged in. I want to be able to do the same callback if the user logs in and there's one of these that have some unread messages.
    Thanks in advance.

  • Not exactly sure what you are trying to do but each of these events send back some data, for example new_post sends the post object and you can compare the uid in that post object with app.uid to see if the post is made by the current user.

    socket.on('event:new_post', function(data) {
        var post = data.posts[0];
        if(parseInt(post.uid,10) !== app.uid) {
             console.log('someone else has posted!);  
        }
    });
    
  • @baris Since my menu is hidden I want a visual indicator to say 'open me, there' s stuff inside' the indicator on the favicon gets updated in real time and when you login too. What I want to achieve is something similar but on the actual forum.
    So chat notification events are linked to user while topic and posts are general. Thanks for the explanation I'll try that this evening.
    The only missing point would be to be able to check for the values instead of the events to have it also when user just logs in/come back. I've thought of checking the apis of unread topics notifications and chat but maybe there' s a better way.

  • @esiao did you make any progress? im trying to do something similar 🙂

  • @agarcia17 Yes I did but then I deleted it because I changed the way I displayed my menu after some feedback.
    But here's what I've done

    //Check if there's unread messages
    var unread = setTimeout(checkUnread,500);
    //Update Unread messages on events
    socket.on('event:chats.receive', function(data) {toggleUnread(data)});
    socket.on('event:new_notification', toggleUnread);
    socket.on('event:new_post', toggleUnread);
    socket.on('event:new_topic', toggleUnread);
    
    function toggleUnread(data) {
    	if (data) var receptor = data.message.touid;
    	if (!$('#unread').length) {
    		var unread = '<span id="unread" title="Vous avez des messages non lus" class="bounce-small infinite animated">';
    		if (receptor != undefined) {
    			if (receptor == window.app.uid) $(unread).insertAfter('.header-top .menu');
    		} else {
    			$(unread).insertAfter('.header-top .menu');
    		}
    	}
    }
    
    function checkUnread() {
    	$('#unread-count, #notif_dropdown i, #chat-count').each(function(){
    		var n = $(this).attr('data-content')
    		if (n > 0) {
    			toggleUnread();
    			return false;
    		}
    	});
    }
    

    I hope it can help you.


Suggested Topics


  • 0 Votes
    4 Posts
    405 Views

    There's no ready made API for this, but you can try the following:

    const allCids = await Categories.getAllCidsFromSet('categories:cid'); const groupCids = await privileges.categories.filterCids('topics:create', allCids, 'groupName');
  • 0 Votes
    8 Posts
    473 Views

    @paul-chambers please do update on your nodebb postgresql journey, as I am interested in this db.

    tia o/

    p.s.; welcome to nodebb. i am old dog as well and nodebb is really great ross - real open source software. toss in very helpful devs and community and you've got a total package you likely haven't seen since... uh.. the nineties? heh... 😜

  • Missing icons / broken CSS

    Unsolved Technical Support
    0 Votes
    9 Posts
    2k Views

    @paviro said in Missing icons / broken CSS:

    How is it that only some of the default skins actually work? 😕

    Obviously not all skins are tested with persona.

  • Issue w/ MongoLab?!?

    Technical Support
    0 Votes
    1 Posts
    645 Views

    Database running fine...until today. I have reached this delightful error - I'm not sure if MongoLab did an update and the order of authentication is now out of wack with NodeBB, but I'd love some insight. I've tried a number of re-installs and created new DB. Nothing is working.

    error: Error creating index not authorized for query on nodebb_west_sand.system.indexes
    8/8 19:09 [3002] - error: MongoError: not authorized for query on nodebb_west_sand.system.indexes
    at Function.MongoError.create (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/error.js:31:11)
    at queryCallback (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/cursor.js:171:34)
    at Callbacks.emit (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/topologies/server.js:95:3)
    at null.messageHandler (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/topologies/server.js:246:23)
    at Socket.<anonymous> (/home/ec2-user/nodebb.2/node_modules/mongodb-core/lib/connection/connection.js:262:22)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

  • 0 Votes
    11 Posts
    4k Views

    @Mega said:

    I'll check that today-tomorrow and will post here.

    aight
    doesn't reproduced anymore on latest