At the privatemsg 5.x - 3.0 module it shows some new messages at menu ("Inbox (xxx)") even though there's no unread messages in the Inbox. It does count of messages by the whole privatemsg table at line 2101:

function _privatemsg_get_new_messages($uid = 0) {
...
    $cache[$uid] = (int)db_result(db_query('SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND newmsg = 1 AND recipient_del = 0', $uid));
...
}

but it looks for unread messages only for users that are exist at line 713:

function privatemsg_list($uid = NULL) {
...
  $sql1 = "SELECT id, subject, p.timestamp, u.uid, u.name, newmsg, type FROM {privatemsg} p INNER JOIN {users} u ON ";
...
}

( INNER JOIN {users} there ).

But if some users were deleted already, there are some unread messages from deleted users and these messages aren't shown at folders.

Can you fix this please?

Comments

vito_a’s picture

StatusFileSize
new3.5 KB

Attached a patch here.

I've checked it locally, it just does "INNER JOIN {users} u ON p.author = u.uid" so it's just messages from deleted users woudn't be counted at Inbox (these aren't shown in the module already).

Can someone be so kind to test it against 5.x-3.0 please?

vito_a’s picture

StatusFileSize
new594 bytes

Seems that the previous one was a bit wrong.

Can you please test this against 3.0 not the above one.

It just seems I can't just delete and reattach my previous one attached to the comment. Can someone with corresponding permissions do that?

naheemsays’s picture

if I remember correctly, 5.x-3.x would also count new messages that were deleted before being read in its unread count... is that still the case?

EDIT - looking at the patch, that has been fixed previously, or I was misremembering.

berdir’s picture

Status: Active » Closed (won't fix)

I'm closing old issues since Privatemsg for Drupal 5 is not maintained anymore. I suggest you switch to Drupal 6 if possible, many of the reported issues are probably already resolved there and if not, you're welcome to open a new issue.

Gabriel R.’s picture

Version: 5.x-3.0 » 6.x-1.5
Status: Closed (won't fix) » Active

This is an issue with Drupal 6 as well. Using 1.5 here and seeing a counter with 2 unread messages while the Inbox is empty.

ptmkenny’s picture

Status: Active » Postponed (maintainer needs more info)

If you're still experiencing this problem, please provide steps on how to reproduce the error from a new install of Drupal 6 with Privatemsg 1.5.

ptmkenny’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
druvision’s picture

Version: 6.x-1.5 » 7.x-1.4
Issue summary: View changes
Status: Closed (cannot reproduce) » Active

This issue also exists in Drupal 7.x versions. The count of unread messages displayed on menu (and page title) on my dev site is bigger then the actual number of unread messages.

ptmkenny’s picture

@Druvision Ok, thanks for confirming this still exists. As per comment #6, could you please provide detailed steps on how to reproduce this error?

oneblankspace’s picture

StatusFileSize
new59.55 KB
oneblankspace’s picture

I am getting pages where the message count does not update in the page title, although it displays correctly on other parts of the page.

ptmkenny’s picture

@oneblankspace Could you please provide detailed steps for how to reproduce this error?

oneblankspace’s picture

Log in when user has 2 new messages.
Click on messages when there are 2 new messages.
Read messages.
Title of page does not update.
The salient screenshot is in comment #10.

SirenMaya’s picture

If I have several new messages and archive some of them without marking them as read the message count shows the number for all the unread messages (both from Inbox and archived) which can be really confusing for users.

dgtlmoon’s picture

Does the last patch in #2449325: Off by one bug - message reply not displayed in thread solve it?

And what is your variable "privatemsg_view_max_amount" set to? is it the default 30?

dgtlmoon’s picture

@SirenMaya Yes, I can see that behaviour too - Archived messages are counted as INBOX

In privatemsg_sql_unread_count()

try joining to the pm_tags table and adding the isNotNull, this will fix the issue but only because 'Archiving' removes the Inbox tag , does the following replacement help?

 function privatemsg_sql_unread_count($account) {
  $query=db_select('pm_index','pmi');
  $query->leftJoin('pm_tags_index', 'tags', 'tags.thread_id = pmi.thread_id');
  $query->addExpression('COUNT(DISTINCT pmi.thread_id)', 'unread_count');
   return $query
     ->condition('pmi.deleted', 0)
     ->condition('pmi.is_new', 1)
    ->isNotNull('tags.tag_id')
     ->condition('pmi.recipient', $account->uid)
     ->condition('pmi.type', array('hidden', 'user'));
 }

any other thoughts on how to fix this?

dgtlmoon’s picture

Version: 7.x-1.4 » 7.x-2.x-dev

Can confirm in 2.x also

ivnish’s picture

Status: Active » Closed (outdated)