You are here

public function OpignoMessageThread::getThreadUnreadMessagesCount in Opigno messaging 3.x

Get the amount of unread messages in the given thread.

Parameters

\Drupal\private_message\Entity\PrivateMessageThreadInterface $thread: The thread to get unread messages amount for.

Return value

int The number of unread messages in the given thread.

1 call to OpignoMessageThread::getThreadUnreadMessagesCount()
OpignoMessageThread::getThreadDisplayData in src/Services/OpignoMessageThread.php
Get the messages thread data: image, title, date, text.

File

src/Services/OpignoMessageThread.php, line 245

Class

OpignoMessageThread
The private messages manager service.

Namespace

Drupal\opigno_messaging\Services

Code

public function getThreadUnreadMessagesCount(PrivateMessageThreadInterface $thread) : int {
  $last_access = $thread
    ->getLastAccessTimestamp($this->account);
  $query = $this->database
    ->select('private_messages', 'pm');
  $query
    ->join('private_message_thread__private_messages', 't', 't.private_messages_target_id = pm.id');
  $query
    ->fields('pm', [
    'id',
  ])
    ->condition('t.entity_id', (int) $thread
    ->id())
    ->condition('pm.owner', (int) $this->account
    ->id(), '!=')
    ->condition('pm.created', $last_access, '>');
  $count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  return (int) $count;
}