get number of unread private messages

Permalink
Hi there, I'm a bit puzzled over this one...

I can get the total number of messages in someones mailbox by using:

$ui = UserInfo::getByID($loggedInUser->getUserID());
$inbox = UserPrivateMessageMailbox::get($ui, UserPrivateMessageMailbox::MBTYPE_INBOX);
$totalMessages =  $inbox->getTotalMessages(); echo $totalMessages;


but I'd really like to know how to display how many of those are unread or

$msg->getMessageStatus() // where status is 'New'


if you get my drift... I'd be really grateful if you could point me in the right direction

Cheers

Rob

rc255
 
rc255 replied on at Permalink Reply
rc255
Can anyone point me in the right direction with this? Thanks
hutman replied on at Permalink Reply
hutman
It doesn't look like this is a built in function, so you would have to override the core /src/User/PrivateMessageList class to add a filterByStatus function.
rc255 replied on at Permalink Reply
rc255
this sounds complicated... I thought there might be a way to look at the total of messages in the inbox and then 'count' how many were 'unread'...

how would I go about adding a filterByStatus function?

Thanks Hutman (again)
hutman replied on at Permalink Reply
hutman
You might be able to do that too, just do something like this

$ui = UserInfo::getByID($loggedInUser->getUserID());
$inbox = UserPrivateMessageMailbox::get($ui, UserPrivateMessageMailbox::MBTYPE_INBOX);
$messageList =  $inbox->getMessageList();
$unreadMessages = 0;
if(count($messageList) > 0){
   foreach($messageList as $message){
      if($message->getMessageStatus() === 'New' || $message->getMessageStatus() === 'Unread'){
         $unreadMessages++;
      }
   }
}
rc255 replied on at Permalink Reply
rc255
Couldn't get it to work, so instead, went straight into the database...
$UserID=$loggedInUser->getUserID(); //echo $UserID;
$countnew = mysql_query("SELECT COUNT(*) FROM UserPrivateMessagesTo WHERE msgIsUnread = 1 AND uID = '$UserID'");
$unreadMessages = mysql_result($countnew,0);
echo $unreadMessages;


Thanks for your help again Hutman :)