forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Sat Nov 18, 2017 2:30 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Feb 05, 2010 7:10 pm 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Quite self explanatory, and very useful.
Am trialling a hacked version of this on Olidip, and it seems to be ok. The current version has a very minor bug in that it doesn't differentiate between sent & recieved messages, although this has been updated in a new patch to be installed soon.


Top
 Profile  
 
PostPosted: Tue Sep 21, 2010 2:51 am 
Offline
Site Admin

Joined: Sat Jun 28, 2008 6:24 am
Posts: 892
I think I've wrote elsewhere that I expect Sleepcap would have done this in a way that makes sense for his installation at the moment but wouldn't scale for our installation. It is on the todo list to have this feature, it'll come with improved JS and static JSON data caching, but a direct patch probably won't be possible


Top
 Profile  
 
PostPosted: Thu Sep 23, 2010 6:31 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
kestasjk wrote:
I think I've wrote elsewhere that I expect Sleepcap would have done this in a way that makes sense for his installation at the moment but wouldn't scale for our installation.

I just use figlesquidge's hack for this.

Oliver


Top
 Profile  
 
PostPosted: Fri Oct 08, 2010 1:03 am 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Wow, this thread is old :P
The method used on OliDip is not a good one, as we all acknowledge it is most definitely a hack.
This was mainly to highlight that it is a feature that would be very useful and wanted.


Top
 Profile  
 
PostPosted: Sat Oct 16, 2010 12:27 am 
Offline

Joined: Sat Mar 28, 2009 7:13 am
Posts: 185
I'm still not fluent in php and haven't looked at the webdip code.

But how hard would it be to add a flag to the player database that indicated whether or not you had any "new" PMs? When someone sends a PM,that flag gets set. When that flag is set, the PM tab appears at the top of the page. When you click on that tab you go to http://webdiplomacy.net/index.php?notices=on. And when you go to index.php with notices=on, clear the flag if it is set.

The only not quite nice thing about it, that I see, is you could read a PM on your home page without going to the notices=on version, and the tab would still be there, so then you go to that page and see the messages you already read. But I think that would just be a matter of people getting used to it. The other thing is it does add another piece of data to the player database.

Just a thought.


Top
 Profile  
 
PostPosted: Sat Oct 16, 2010 12:51 am 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Not at all, although it would require a change of the database schema, something that was opposed in the past for a completely logical reason I no longer remember


Top
 Profile  
 
PostPosted: Tue Dec 27, 2011 11:43 pm 
Offline

Joined: Sat Mar 28, 2009 7:13 am
Posts: 185
Okay, so I have this working on my dev box.

This is based on using the currently existing wd_user table notifications column, which I'm not seeing used anywhere in the code, but maybe it is hiding where I don't know where to find it. I'm guessing that this field was planed on being used for email notifications, and perhaps some others are already using it as such.

In lib/html.php, in the gameNotifyBlock() function, after $gameNotifyBlock is initialized to blank (on line 521 of the current version), add:
Code:
        if ( $User->notifications['PrivateMessage'] and ! isset($_REQUEST['notices']))
        {
         $gameNotifyBlock .= '<span class=""><a href="index.php?notices=on">'.
                'PM <img src="images/icons/mail.png" alt="New private messages" title="New private messages!" />'.
             '</a></span> ';
        }
I'm not sure what to put in the class attribute of the span, but having it blank seems to work. If someone has a suggestion for that, that would be great.

In index.php, in the elseif( isset($_REQUEST['notices']) ) section, add $User->clearPMNotification(); to the top, for example:
Code:
elseif( isset($_REQUEST['notices']) )
{
    $User->clearPMNotification();

   print '<div class="content"><a href="index.php" class="light">&lt; Back</a></div>';

The rest of the changes are all in objects/user.php. In the User class, add:
Code:
    /**
     * Notification flags; an array of notification flags, each set to true if notification should be done.
     * @var array
     */
    public $notifications;
...after public $type;

In function load() add u.notifications, after u.silenceID and then near the bottom of the function, before $this->online is set, set $this->notifications similar to how $this->type is set. Seems like notifications and type could both call a common method, but I'm not sure where it would be appropriate to put such a method. Anyway, here is the code for setting $this->notifications:
Code:
        // Convert an array of notification flags this user has into an array for true/false indexed by type
      $this->notifications = explode(',', $this->notifications);
      $validNotifications = array('PrivateMessage', 'GameMessage', 'Unfinalized', 'GameUpdate');
      $notifications = array();
      foreach($validNotifications as $notification)
      {
         if ( in_array($notification, $this->notifications) )
         {
            $notifications[$notification] = true;
         }
         else
         {
            $notifications[$notification] = false;
         }
      }
      $this->notifications = $notifications;

Then in function sendPM, between the two notice::send() calls when not muted, add:
Code:
            if ( !$this->notifications['PrivateMessage'] )
            {
                $DB->sql_put("UPDATE wD_Users SET notifications = CONCAT_WS(',',notifications,'PrivateMessage') WHERE id = ".$this->id);
                $this->notifications['PrivateMessage'] = true;
            }

And right after that function, add the new function:
Code:
    function clearPMNotification()
    {
      global $DB;

        if ( $this->notifications['PrivateMessage'] )
        {
             $DB->sql_put("UPDATE wD_Users SET notifications = REPLACE(notifications,'PrivateMessage','') WHERE id = ".$this->id);

            $this->notifications['PrivateMessage'] = false;
        }
    }
Note that the logic in clearPMNotification() could have just gone in index.php where it is called, but it seems better to me to have the database update code for a table located within the object class that corresponds to that table. Centralizes that logic for easier maintenance as well as potentially reducing redundancy and the inconsistencies that can happen with code redundancy.

In any case, that's it. It was pretty easy to do after looking at how the code was doing similar things.

If anyone else IS using the notifications field already for their own mod, I'd be happy to take a look at their code to help integrate my changes if they wanted them.


Top
 Profile  
 
PostPosted: Tue Dec 27, 2011 11:48 pm 
Offline

Joined: Sat Mar 28, 2009 7:13 am
Posts: 185
Oh, and by the way, on this part in lib/html.php
Alderian wrote:
Code:
        if ( $User->notifications['PrivateMessage'] and ! isset($_REQUEST['notices']))
        {
         $gameNotifyBlock .= '<span class=""><a href="index.php?notices=on">'.
                'PM <img src="images/icons/mail.png" alt="New private messages" title="New private messages!" />'.
             '</a></span> ';
        }
the purpose in checking ! isset($_REQUEST['notices']) is to avoid showing the PM notification tab when you on the index.php?notices=on page. But is there a way in lib/html.php to tell what page you are on, i.e. index.php, in addition to looking for $_REQUEST['notices']? Right now if there was another page that had ?notices=whatever then that page would also not show the PM tab when it should.


Top
 Profile  
 
PostPosted: Wed Dec 28, 2011 12:45 am 
Offline
Site Admin

Joined: Sat Jun 28, 2008 6:24 am
Posts: 892
Nicely done Alderian, would it be possible to get a link to see it in action, and to get it as a series of patches rather than as a manual list of changes? I think it would be best to get that part of the process down before things get out of hand with trying to merge constantly (and I can't really deploy code I've only seen on a forum page straight to the live website).


Looks v good though, nicely done!


Top
 Profile  
 
PostPosted: Wed Dec 28, 2011 3:52 am 
Offline

Joined: Sat Mar 28, 2009 7:13 am
Posts: 185
I'll work on getting it submitted via github. I'll have to look into making my PC accessible so you can preview it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group