Loading src/Mapper/PrivateMessageMapper.php +36 −0 Original line number Diff line number Diff line Loading @@ -291,6 +291,42 @@ class PrivateMessageMapper implements PrivateMessageMapperInterface { )->fetchField(); } /** * {@inheritdoc} */ public function getUnreadMessageCount($uid, $lastCheckTimestamp) { $query = $this->database->select('private_messages', 'message'); $query->join( 'private_message_thread__private_messages', 'thread_message', 'message.id = thread_message.private_messages_target_id' ); $query->join( 'private_message_threads', 'thread', 'thread_message.entity_id = thread.id' ); $query->join( 'pm_thread_history', 'thread_history', 'thread_history.thread_id = thread.id AND thread_history.uid = :uid', [':uid' => $uid] ); $query->join( 'private_message_thread__members', 'thread_member', 'thread_member.entity_id = thread.id AND thread_member.members_target_id = :uid', [':uid' => $uid] ); $query ->condition('thread.updated ', $lastCheckTimestamp, '>') ->condition('message.created', $lastCheckTimestamp, '>') ->condition('message.owner', $uid, '<>') ->where('thread_history.access_timestamp < thread.updated'); $query = $query->countQuery(); return $query->execute()->fetchField(); } /** * {@inheritdoc} */ Loading src/Mapper/PrivateMessageMapperInterface.php +16 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,22 @@ interface PrivateMessageMapperInterface { */ public function getUnreadThreadCount($uid, $lastCheckTimestamp); /** * Get the current user's unread message count. * * Retrieves the number of the current user's messages that have been updated * since the last time this number was checked. * * @param int $uid * The user ID of the user whose count should be retrieved. * @param int $lastCheckTimestamp * A UNIX timestamp indicating the time after which to check. * * @return int * The number of threads updated since the given timestamp */ public function getUnreadMessageCount($uid, $lastCheckTimestamp); /** * Load the thread id of the thread that a private message belongs to. * Loading src/Service/PrivateMessageService.php +11 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,17 @@ class PrivateMessageService implements PrivateMessageServiceInterface { return (int) $this->mapper->getUnreadThreadCount($uid, $last_check_timestamp); } /** * {@inheritdoc} */ public function getUnreadMessageCount() { $uid = $this->currentUser->id(); $last_check_timestamp = $this->userData->get(self::MODULE_KEY, $uid, self::LAST_CHECK_KEY); $last_check_timestamp = is_numeric($last_check_timestamp) ? $last_check_timestamp : 0; return (int) $this->mapper->getUnreadMessageCount($uid, $last_check_timestamp); } /** * {@inheritdoc} */ Loading src/Service/PrivateMessageServiceInterface.php +8 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,14 @@ interface PrivateMessageServiceInterface { */ public function getUnreadThreadCount(); /** * Get the current user's unread messages count. * * @return int * The number of updated threads */ public function getUnreadMessageCount(); /** * Marks a timestamp at which all threads are considered read. */ Loading Loading
src/Mapper/PrivateMessageMapper.php +36 −0 Original line number Diff line number Diff line Loading @@ -291,6 +291,42 @@ class PrivateMessageMapper implements PrivateMessageMapperInterface { )->fetchField(); } /** * {@inheritdoc} */ public function getUnreadMessageCount($uid, $lastCheckTimestamp) { $query = $this->database->select('private_messages', 'message'); $query->join( 'private_message_thread__private_messages', 'thread_message', 'message.id = thread_message.private_messages_target_id' ); $query->join( 'private_message_threads', 'thread', 'thread_message.entity_id = thread.id' ); $query->join( 'pm_thread_history', 'thread_history', 'thread_history.thread_id = thread.id AND thread_history.uid = :uid', [':uid' => $uid] ); $query->join( 'private_message_thread__members', 'thread_member', 'thread_member.entity_id = thread.id AND thread_member.members_target_id = :uid', [':uid' => $uid] ); $query ->condition('thread.updated ', $lastCheckTimestamp, '>') ->condition('message.created', $lastCheckTimestamp, '>') ->condition('message.owner', $uid, '<>') ->where('thread_history.access_timestamp < thread.updated'); $query = $query->countQuery(); return $query->execute()->fetchField(); } /** * {@inheritdoc} */ Loading
src/Mapper/PrivateMessageMapperInterface.php +16 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,22 @@ interface PrivateMessageMapperInterface { */ public function getUnreadThreadCount($uid, $lastCheckTimestamp); /** * Get the current user's unread message count. * * Retrieves the number of the current user's messages that have been updated * since the last time this number was checked. * * @param int $uid * The user ID of the user whose count should be retrieved. * @param int $lastCheckTimestamp * A UNIX timestamp indicating the time after which to check. * * @return int * The number of threads updated since the given timestamp */ public function getUnreadMessageCount($uid, $lastCheckTimestamp); /** * Load the thread id of the thread that a private message belongs to. * Loading
src/Service/PrivateMessageService.php +11 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,17 @@ class PrivateMessageService implements PrivateMessageServiceInterface { return (int) $this->mapper->getUnreadThreadCount($uid, $last_check_timestamp); } /** * {@inheritdoc} */ public function getUnreadMessageCount() { $uid = $this->currentUser->id(); $last_check_timestamp = $this->userData->get(self::MODULE_KEY, $uid, self::LAST_CHECK_KEY); $last_check_timestamp = is_numeric($last_check_timestamp) ? $last_check_timestamp : 0; return (int) $this->mapper->getUnreadMessageCount($uid, $last_check_timestamp); } /** * {@inheritdoc} */ Loading
src/Service/PrivateMessageServiceInterface.php +8 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,14 @@ interface PrivateMessageServiceInterface { */ public function getUnreadThreadCount(); /** * Get the current user's unread messages count. * * @return int * The number of updated threads */ public function getUnreadMessageCount(); /** * Marks a timestamp at which all threads are considered read. */ Loading