You are here

public function PrivateMessageService::getThreadsForUser in Private Message 8.2

Same name and namespace in other branches
  1. 8 src/Service/PrivateMessageService.php \Drupal\private_message\Service\PrivateMessageService::getThreadsForUser()

Retrieve private message threads for a given user.

Parameters

int $count: The number of threads to retrieve.

int $timestamp: A timestamp relative to which only threads with an earlier timestamp should be returned.

Return value

array An array with two keys:

Overrides PrivateMessageServiceInterface::getThreadsForUser

File

src/Service/PrivateMessageService.php, line 146

Class

PrivateMessageService
The Private Message service for the private message module.

Namespace

Drupal\private_message\Service

Code

public function getThreadsForUser($count, $timestamp = FALSE) {
  $return = [
    'threads' => [],
    'next_exists' => FALSE,
  ];
  $user = $this->userManager
    ->load($this->currentUser
    ->id());
  $thread_ids = $this->mapper
    ->getThreadIdsForUser($user, $count, $timestamp);
  if (count($thread_ids)) {
    $threads = $this->pmThreadManager
      ->loadMultiple($thread_ids);
    if (count($threads)) {
      $last_thread = end($threads);
      $last_timestamp = $last_thread
        ->get('updated')->value;
      $return['next_exists'] = $this->mapper
        ->checkForNextThread($user, $last_timestamp);
      $return['threads'] = $threads;
    }
  }
  return $return;
}