/** * Sends the message by persisting it to the message manager and undeletes * the thread for all participants. * * @param MessageInterface $message */ public function send(MessageInterface $message) { $this->threadManager->saveThread($message->getThread(), false); $this->messageManager->saveMessage($message, false); /* Note: Thread::setIsDeleted() depends on metadata existing for all * thread and message participants, so both objects must be saved first. * We can avoid flushing the object manager, since we must save once * again after undeleting the thread. */ $message->getThread()->setIsDeleted(false); $this->messageManager->saveMessage($message); $this->dispatcher->dispatch(FOSMessageEvents::POST_SEND, new MessageEvent($message)); }
/** * Gets a thread by its ID * Performs authorization checks * Marks the thread as read * * @return ThreadInterface */ public function getThread($threadId) { $thread = $this->threadManager->findThreadById($threadId); if (!$thread) { throw new NotFoundHttpException('There is no such thread'); } if (!$this->authorizer->canSeeThread($thread)) { throw new AccessDeniedException('You are not allowed to see this thread'); } // Load the thread messages before marking them as read // because we want to see the unread messages $thread->getMessages(); $this->threadReader->markAsRead($thread); return $thread; }
/** * Starts composing a message, starting a new thread * * @return NewThreadMessageBuilder */ public function newThread() { $thread = $this->threadManager->createThread(); $message = $this->messageManager->createMessage(); return new NewThreadMessageBuilder($message, $thread); }
/** * Finds threads of a participant, matching a given query * * @param Query $query * @return mixed a query builder suitable for pagination */ public function getQueryBuilder(Query $query) { return $this->threadManager->getParticipantThreadsBySearchQueryBuilder($this->getAuthenticatedParticipant(), $query->getEscaped()); }