public function SocialPrivateMessageService::updateUnreadCount in Open Social 8.2
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.3 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
- 8.4 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 66
Class
- SocialPrivateMessageService
- Class SocialPrivateMessageService.
Namespace
Drupal\social_private_message\ServiceCode
public function updateUnreadCount() {
// Get the user.
$uid = $this->currentUser
->id();
// Get all the thread id's for this user.
$thread_info = $this
->getAllThreadIdsForUser($uid);
// Load these threads.
$threads = PrivateMessageThread::loadMultiple($thread_info);
$unread = 0;
/* @var PrivateMessageThread $thread */
foreach ($threads as $thread) {
// Check if the user has a timestamp on the thread and.
$thread_last_check_user = $this->userData
->get('private_message', $uid, 'private_message_thread:' . $thread
->id());
// Check the last time someone other than the current user added
// something to this thread.
$thread_last_message = $this
->getLastMessageFromOtherUser($uid, $thread
->id());
// Compare those two.
if ($thread_last_message > $thread_last_check_user) {
$unread++;
}
}
return $unread;
}