Just something I played around with but have not tested:
in Pmgrowl.module, replace with pmgrowl_json()
function pmgrowl_json() {
global $user;
global $baseurl;
if (variable_get() == 'message content') {
$data = pmgrowl_message_contents($user, $baseurl);
}
else {
$data = pmgrowl_message_count($user, $baseurl);
}
drupal_json($data);
}
function pmgrowl_message_contents($account, $baseurl) {
$query = 'SELECT * FROM {pm_index} i LEFT JOIN {pm_message} m ON m.mid = i.mid WHERE (i.uid = %d AND i.is_new = 1) ORDER BY m.timestamp DESC';
$result = db_query($query, $account->uid);
$data = array();
while ($row = db_fetch_object($result)) {
$row->body = truncate_utf8($row->body, 300, FALSE, TRUE);
$row->body .= '<p><a href="'.$base_url. '/messages/view/' + entry['thread_id'] + '">Open & Reply</a>';
$row->body .= ' | <a href="'.$base_url.'/messages">View All.</a></p>';
$data[] = $row;
}
return $data
}
function pmgrowl_message_count($account, $baseurl) {
$unread = array()
$unread['count'] = privatemsg_unread_count($account);
if ($unread['count'] <> 0 && ($unread['count'] <> $_COOKIE["privatemsg_unread_count"])) {
$unread['subject'] = 'You have Mail!';
$unread['body'] = 'You have <a href="'.$base_url.'/messages">'.$unread['count'].' unread messages</a>.';
setcookie ('privatemsg_unread_count', $unread['count'], time()+60*60, '/', )
}
$data[] = $unread;
return $data;
}
I have not made the changes to pmgrowl.js, but with the above, you can replace
$.jGrowl(entry['body'] + '<p><a href="' + Drupal.settings.basePath + 'messages/view/' + entry['thread_id'] + '">Open & Reply</a>' +
' | <a href="' + Drupal.settings.basePath + 'messages">View All.</a></p>'with just
$.jGrowl(entry['body']
Comments
Comment #1
Dave.Ingram commentedOK. Again, agreed that bringing more logic into PHP is better. So I've taken what you suggested here and reworked it quite a bit. Also, with the addition of the database table, I'm now just marking messages as closed once an alert goes out. This should eliminate the need to track messages in a cookie. It's now all handled server side, but the result should be the same. Please test it out and see if it works well for you now.
Comment #2
Dave.Ingram commentedmarking closed