public function SocialPrivateMessageService::updateUnreadCount in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.2 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.3 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.5 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.6 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.7 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.8 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 10.3.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 10.0.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 10.1.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 10.2.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
Update the unread thread count.
Return value
int The number of unread threads.
File
- modules/
social_features/ social_private_message/ src/ Service/ SocialPrivateMessageService.php, line 65
Class
- SocialPrivateMessageService
- Class SocialPrivateMessageService.
Namespace
Drupal\social_private_message\ServiceCode
public function updateUnreadCount() {
$unread = 0;
// Get the user.
$uid = $this->currentUser
->id();
// Get all the thread id's for this user.
$threads = $this
->getAllThreadIdsForUser($uid);
if (empty($threads)) {
return $unread;
}
// Check the last time someone other than the current user added
// something to the threads.
$thread_last_messages = $this
->getLastMessagesFromOtherUsers($uid, $threads);
if (empty($thread_last_messages)) {
return $unread;
}
foreach ($thread_last_messages as $thread_id => $last_message) {
// Check if the user has a timestamp on the thread.
$thread_last_check = $this->userData
->get('private_message', $uid, 'private_message_thread:' . $thread_id);
if ($thread_last_check === NULL) {
$thread_last_check = 0;
}
// Check if someone send a message after your last check.
if ($last_message > $thread_last_check) {
$unread++;
}
}
return $unread;
}