/** * Load conversation between users * * @return ResourceViewModel * @throws ForbiddenException * @throws NotFoundException */ public function loadAction() : ResourceViewModel { if (!$this->isGranted(UserMessagePermissions::START_CONVERSATION)) { throw new ForbiddenException(); } /* @var MessageUserInterface $target */ $target = $this->userRepository->findOneBy(['id' => $this->params()->fromQuery('target')]); if (!$target) { throw new NotFoundException('Target user not found'); } try { $conversation = $this->pmConversationRepository->getConversationBetween($this->identity(), $target); } catch (ConversationNotFound $e) { $conversation = $this->conversationService->createBetween($this->identity(), $target); } return new ResourceViewModel(['conversation' => $conversation], ['template' => 'conversations/conversation']); }