You are here

public function SocialPrivateMessageService::updateUnreadCount in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  2. 8.2 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  3. 8.3 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  4. 8.4 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  5. 8.5 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  6. 8.6 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  7. 8.7 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  8. 8.8 modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  9. 10.3.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  10. 10.0.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  11. 10.1.x modules/social_features/social_private_message/src/Service/SocialPrivateMessageService.php \Drupal\social_private_message\Service\SocialPrivateMessageService::updateUnreadCount()
  12. 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 70

Class

SocialPrivateMessageService
Class SocialPrivateMessageService.

Namespace

Drupal\social_private_message\Service

Code

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;
}