BuddyDev

Search

[Resolved] Show new notification without having to refresh?

Tagged: 

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3430

    It seems that by default, you have to refresh to see any new notifications in Buddypress. Is there a way to make it so that the new notification is fetched live without having to manually refresh? I’ve seen this being done on a premium theme once, looked like it used heartbeat, redux or something of the sort? Any help would be appreciated!

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3431

    Sorry, I meant to post this in How-Tos & Troubleshooting but I can’t move it.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3432

    Hi Alayna,

    Thank You for posting, Yes you can achieve this functionality using one our free plugin named “BuddyPress Live Notification”. It works exactly like your requirement. Please refer the following Link

    https://buddydev.com/plugins/buddypress-live-notification/

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3437

    Hello again Ravi and thanks for your response.

    I have installed the plugin and it works great for the default admin bar notifications however I coded notifications into my custom header and it isn’t showing the live updates there.

    Here is the code for the notifications that I have in functions.php in my child theme: http://pastebin.com/ciQL8C5C

    And I call that code from header.php using <?php my_bp_adminbar_notifications_menu()?>

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #3440

    Hi Alayna,
    Ravi will be away for a few more hours, so I am posting here.

    Since you have different elements, you will need to bind to ‘bpln:new_notifications’ event in javascript and handle it as you wish.

    Please see the code below to find what data you can access
    https://github.com/sbrajesh/bp-live-notification/blob/master/assets/js/bpln.js#L128

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3705

    Hi Brajesh,
    I’m revisiting this and having quite a bit of difficulty. Could you please give me a brief description on how to bind to ‘bpln:new_notifications’, if it’s not a bother? Thanks!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3706

    Hi Alayna,

    Please refer the following url as I have bind a callback function to this event here

    https://github.com/buddydev/bp-live-notification-tone/blob/master/assets/js/bp-live-notification-tone.js#L11

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3712

    Thank you, that shines a little more light on how to do so but the audio elements are throwing me off a bit.

    How do I replace “ion.sound.play(‘bell_ring’);” with a div? Since I need to bind it to the notification count, right?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #3714

    Hi Alayna,

    You can do something like this.

    
      jQuery(document).on( 'bpln:new_notifications', function( event, res ){
    
            // pass count selector here
            jQuery('#count').text(res.count); //to show no. of count
            // pass message selector here
            jQuery('#message').html(res.messages);
            //alert(res.count);
        });
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 19
    Alayna on #3725

    Thank you, I gave that a try and successfully tied the event to the count, but whenever a new notification came in, the count would just go down to 1 and stay there instead of increasing.

    I can’t seem to get this working successfully so I think I’m going to give up here. Might hire a developer for it.

    Thank you for your help regardless!

You must be logged in to reply to this topic.

This topic is: resolved