You are here

public function PrivateMessageService::getNewMessages in Private Message 8.2

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

Retrieve a users private messages created after the given ID.

Parameters

int $threadId: The ID of the thread from which messages should be retrieved.

int $messageId: The ID after which messages should be retrieved.

Return value

array An array containing any new messages that the user has permission to view

Overrides PrivateMessageServiceInterface::getNewMessages

File

src/Service/PrivateMessageService.php, line 179

Class

PrivateMessageService
The Private Message service for the private message module.

Namespace

Drupal\private_message\Service

Code

public function getNewMessages($threadId, $messageId) {
  $response = [];
  $private_message_thread = $this->pmThreadManager
    ->load($threadId);
  if ($private_message_thread && $private_message_thread
    ->isMember($this->currentUser
    ->id())) {
    $messages = $private_message_thread
      ->getMessages();
    $from_index = FALSE;
    foreach ($messages as $index => $message) {
      if ($message
        ->id() > $messageId) {
        $from_index = $index;
        break;
      }
    }
    if ($from_index !== FALSE) {
      $response = array_splice($messages, $from_index);
    }
  }
  return $response;
}