chatMapper = $chatMapper; $this->matrixService = $matrixService; $this->logger = $logger; } /** * @param $ticket MatrixTicket Support ticket * @throws RoomNotFoundException */ public function getOrCreateChatRoom(MatrixTicket $ticket): MatrixChat { try { return $this->chatMapper->findCurrent($ticket->getId()); } catch (DoesNotExistException $e) { if ($ticket->getMatrixHelperUser() == null) { $this->logger->debug("No helper assigned to ticket " . $ticket->getId() . ". Not creating chat room"); throw new RoomNotFoundException(); } $this->logger->debug("Chat room for ticket " . $ticket->getId() . " does not exist. Creating room.."); $roomId = $this->matrixService->createRoom(); $startDate = new \DateTime('now', new \DateTimeZone("utc")); $matrixChat = new MatrixChat(); $matrixChat->setTicketId($ticket->getId()); $matrixChat->setMatrixRoomId($roomId); $matrixChat->setMatrixHelperUser($ticket->getMatrixHelperUser()); $matrixChat->setDateStart($this->chatMapper->convertDateTimeTz($startDate)); $matrixChat->setVersion(1); $this->matrixService->inviteUser($roomId, $ticket->getMatrixHelperUser()); $this->matrixService->inviteUser($roomId, $ticket->getMatrixAssistedUser()); return $this->chatMapper->insert($matrixChat); } } }