Hello.
First to have access to the functionality you have 2 steps.
1- enable public profiles here: /dashboard/system/registration/profiles
2- make each user edit their profile by checking the box "I would like to receive private messages
Once that’s done you should have a new item in your menu (provided your theme didn’t override it) called “members” and a sub entry called “directory”
Alternatively you can navigate to /members/directory
There you can click on any user and if they have enabled private messages in step 2 above, you can send them a message.
users can check their messages by going to their profile /members/profile, click on the “edit” button and then go to “private messages”
Alternatively they can navigate directly to /account/messages
Now to programmatically check the number of unread private messages
You will need the Mailbox class to get the user’s inbox (class concrete\src\User\PrivateMessage\Mailbox.php)
you will first use the get($user, $msgMailboxID) method where $user is an object of type Concrete\Core\User\User.
To get the logged in user you could simple do
$user = new \Concrete\Core\User\User();
And $msgMailboxID would be Mailbox::MBTYPE_INBOX
From that object you can get a list of messages using getMessageList()
This will give you an object of type PrivateMessageList (class concrete\src\User\PrivateMessage\PrivateMessageList.php)
Using this object’s get() method you’ll get an array of all the messages. Each message is an object of type privateMessage (class concrete\src\User\PrivateMessage\PrivateMessage.php)
So you loop through the array and for each message you call the method isMessageUnread() which will let you filter your list.
An example code would be
use Concrete\Core\User\PrivateMessage\Mailbox;
use Concrete\Core\User\User;
$msgMailboxID = Mailbox::MBTYPE_INBOX;
$user = new User();
$messageCount = 0;
if ($user->isRegistered()) {
$inbox = Mailbox::get($user, $msgMailboxID);
$messageList = $inbox->getMessageList()->get();
if (count($messageList)) {
foreach ($messageList as $message) {
$messageCount += (int) $message->isMessageUnread();
}
}
}
$messageCount will tell you how many unread messages the user has in their inbox.
You should probably also check whether the user has enabled private messages by checking on the proper user attribute.
Hope this helps.