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">< 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.