Announcement

Collapse
No announcement yet.

vB5 temporary solution for message notification popup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • vB5 temporary solution for message notification popup

    Bring the message notification popup back to vB5 with this temporary pure Javascript solution that uses the existing vB5 dialog style.

    Add this as an inline script or external js file in the footer template right after the footer rollup js. Or you can make it as a Hook if you want.

    Code:
    $(document).ready(function() {
        if (location.pathname.indexOf('/forum/privatemessage/') == -1) { //don't prompt when in the PM page itself
            var notifCount = Number($('.notifications-count').first().text());
            if (notifCount > 0) {
                openConfirmDialog({
                    iconType: 'warning',
                    title: 'New Messages',
                    message: 'You have <strong>' + notifCount + '</strong> new message(s) in the Message Center.<br />Would you like to open it now?',
                    buttonLabel: {
                        yesLabel: 'Open',
                        noLabel: 'Cancel'
                    },
                    onClickYes: function() {
    
                        //if you want to open in new window
                        var w = window.open(pageData.baseurl + '/privatemessage/index', '_blank');
                        if (!w) {
                            openAlertDialog({
                                title: 'Popup Blocked',
                                message: 'The popup window is blocked. Please unblock or allow popups for ' + location.host + '.'
                            });
                        }
    
                        //if you want to open in the same window, remove new window block above, then uncomment this
                        //location.href = pageData.baseurl + '/privatemessage/index';
    
                    }
                });
            }
        }
    });
    Note: If user does not read the new message or delete any notification, the prompt will always appear when any page is loaded. This could be annoying to users.


    Enjoy!
    Last edited by Glenn Vergara; Mon 14th Apr '14, 11:46am.

    GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

  • #2
    Glenn,

    We have modified your solution to be more user-friendly. It will only run on the main forum page, and the post search pages. Also, since we run some Dragonbyte mods for thread tagging and mentions, we needed to differentiate from those types of notifications/PMs, otherwise, our users could get dozens of alerts.

    Code:
    $(document).ready(function() {
        var match = /search|\/forum\/$/.test(location.pathname);
        if (match) { //don't prompt when in the PM page itself
            var legit = 0;
            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status == 200) {
                    var result = xmlhttp.responseText;
                    var matches = result.match(/\<a href=\"http\:\/\/([a-z0-9]|\-|\.)+\/forum\/privatemessage\/view\/[0-9]+\?folderid\=[0-9]+(.+)/g);
                    var resultslist = "";
                    for (count=0; count < matches.length; count++) {
                        var subject = matches[count].match(/(\w|\s)+$/);
                        if (subject[0] != "New Thanks Received") {
                            legit++;
                        }
                    }
                    if (legit > 0) {
                        openConfirmDialog({
                            iconType: 'warning',
                            title: 'New Messages',
                            message: 'You have <strong>' + legit + '</strong> new message(s) in the Message Center.<br />Would you like to open it now?',
                            buttonLabel: {
                                yesLabel: 'Open',
                                noLabel: 'Cancel'
                            },
                            onClickYes: function() {
              
                                //if you want to open in new window
              
                                var w = window.open(pageData.baseurl + '/privatemessage/index', '_blank');
                                //var w = window.open(pageData.baseurl + '/privatemessage/list', '_blank');
                                if (!w) {
                                    openAlertDialog({
                                        title: 'Popup Blocked',
                                        message: 'The popup window is blocked. Please unblock or allow popups for ' + location.host + '.'
                                    });
                                }
              
                                //if you want to open in the same window, remove new window block above, then uncomment this
                                //location.href = pageData.baseurl + '/privatemessage/index';
              
                            }
                        });
                    }
                }
            };
            xmlhttp.open("GET","/forum/privatemessage/index",true);
            xmlhttp.send();
        }   
    });

    Comment


    • #3
      That's not efficient as you are requesting the entire PM index page on home page and search pages. I will try to check if you you can call an API method to get the desired notification. You are only interested in the Inbox notification, right?
      Last edited by Glenn Vergara; Mon 14th Apr '14, 9:58pm.

      GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

      Comment


      • #4
        Try this:

        Code:
        vBulletin.AJAX({
            url: pageData.baseurl + '/ajax/api/content_privatemessage/previewMessages',
            success: function(data){
                console.log(data);
                console.log('New messages: ', data.message.count); //number of new inbox messages
                console.log('New requests: ', data.request.count); //number of new requests
                console.log('New notifications: ', data.notification.count); //number of new notifications (likes, comments, replies, etc)
            }
        });

        GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

        Comment


        • #5

          Note: If user does not read the new message or delete any notification, the prompt will always appear when any page is loaded. This could be annoying to users.


          Is there a way to show this only the initial time it pops up?
          www.hugaming.com

          Comment


          • #6
            Originally posted by jstear View Post
            Is there a way to show this only the initial time it pops up?
            It's possible using cookies or localStorage but it will only be for the browser being used. If you use a different browser or computer, then it'll pop up again.

            GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

            Comment

            Related Topics

            Collapse

            Working...
            X