MyBB Community Forums

Full Version: creating group for certain notifications
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using this plugin, but modified to create the unread posts number in the tab. However the plugin author abandoned the he is no help. I modified the previous linked file accordingly....

var unreadPosts = {
    timeout:    false,
    interval:   10,
    enable:     false,
    fid:        0,
    hide:       false,
    updateCounter: function() {
        if (!unreadPosts.enable) {
        $.get( "xmlhttp.php?action=unreadPosts_getUnreads&fid" + unreadPosts.fid, function( data ) {
        var d = data.split('<!--')[2] //strip non-counter
        var d = d.split('-->')[1] //strip to only counter
        var d = d.slice(3, -2); //remove extra paren
        var title = document.title;
       // var title = "Python Forum";
        //if title.startsWtih('('){
        //    var title = title.split(')')[1] //remove extra num if there is one
        //var title = title.split(" ").splice(1,-2)
        if (d != "0"){
            var newTitle = '(' + d + ') ' + "Python Forum";
            document.title = newTitle;
            document.title = "Python Forum";
        if (unreadPosts.timeout) clearTimeout(unreadPosts.timeout);
        unreadPosts.timeout = setTimeout('unreadPosts.updateCounter()', unreadPosts.interval * 1000);

Right in the if condition that changes the document.title or leaves it as "Python Forum" I would like to add another clause that if the user is in a certain user group ( a secondary user group that wants to see this notification in the tab) then they see the number, otherwise they do not.

so pseudo code like:

        if (d != "0"){
            if (usergroup == tab_display_true){
                var newTitle = '(' + d + ') ' + "Python Forum";
                document.title = newTitle;
            document.title = "Python Forum";

But i dont know how to define "usergroup" or "tab_display_true" group within the javascript file?

In PHP to get the UID of hte user you would do similar to
I am assuming instead of uid there is one for usergroup?
But still even if there is, how to you apply it to a javascript file?
That's a server-side work. You need to edit this function: inc/plugins/unreadPosts.php#L261

Mainly, you need to return two data: the count template (as the plugin already does) and your cleaned unread posts count (without the manipulation of a template) with your usergroup check. Then in the js file you just need to read the variable (check if is set/greater than 0) and do your document.title manipulation. It is better if you return the data in json since you need to pass multiple data.
thanks a lot!
When i get time later on i will try to apply this and see where i sit.