vB5 temporary solution for message notification popup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glennrocksvb
    Former vBulletin Developer
    • Mar 2011
    • 4011
    • 5.7.X

    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 glennrocksvb; Mon 14 Apr '14, 11:46am.

    Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!
  • GaWd
    New Member
    • May 2011
    • 29
    • 3.8.x

    #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

    • glennrocksvb
      Former vBulletin Developer
      • Mar 2011
      • 4011
      • 5.7.X

      #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 glennrocksvb; Mon 14 Apr '14, 9:58pm.

      Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

      Comment

      • glennrocksvb
        Former vBulletin Developer
        • Mar 2011
        • 4011
        • 5.7.X

        #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)
            }
        });

        Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

        Comment

        • jstear
          Member
          • Oct 2013
          • 42
          • 5.1.x

          #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

          • glennrocksvb
            Former vBulletin Developer
            • Mar 2011
            • 4011
            • 5.7.X

            #6
            Originally posted by jstear
            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.

            Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

            Comment

            Related Topics

            Collapse

            Working...