/**
  * Creates Ticket and Message Reference fot it
  *
  * @param Message $message
  * @param $branchId
  * @param $reporter
  * @param $assigneeId
  * @param array|null $attachments
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  * @throws \RuntimeException if unable to load required branch, reporter, assignee
  */
 public function createTicket(Message $message, $branchId, $reporter, $assigneeId, array $attachments = null)
 {
     $subject = $message->getSubject();
     if (empty($message->getSubject())) {
         $subject = self::EMPTY_SUBJECT_PLACEHOLDER;
     }
     $command = new CreateTicketCommand();
     $command->subject = $subject;
     $command->description = $message->getContent();
     $command->branch = $branchId;
     $command->reporter = $reporter;
     $command->assignee = $assigneeId;
     $command->source = Source::EMAIL;
     $command->attachmentsInput = $this->convertAttachments($attachments);
     $command->priority = Priority::PRIORITY_LOW;
     $command->status = Status::NEW_ONE;
     $ticket = $this->ticketService->createTicket($command);
     $this->createMessageReference($message->getMessageId(), $ticket, $message->getTo());
     return $ticket;
 }
 /**
  * @param Message $message
  */
 public function process(Message $message)
 {
     $email = $message->getFrom()->getEmail();
     $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email);
     $type = User::TYPE_DIAMANTE;
     if (is_null($diamanteUser)) {
         $sender = $message->getFrom();
         $diamanteUser = $this->diamanteUserFactory->create($email, $sender->getFirstName(), $sender->getLastName());
         $this->diamanteUserRepository->store($diamanteUser);
     }
     $reporterId = $diamanteUser->getId();
     $reporter = new User($reporterId, $type);
     $attachments = $message->getAttachments();
     if (!$message->getReference()) {
         $branchId = $this->getAppropriateBranch($message->getFrom()->getEmail(), $message->getTo());
         $assigneeId = $this->branchEmailConfigurationService->getBranchDefaultAssignee($branchId);
         $ticket = $this->messageReferenceService->createTicket($message->getMessageId(), $branchId, $message->getSubject(), $message->getContent(), $reporter, $assigneeId, $attachments);
     } else {
         $this->eventDispatcher->removeListener('commentWasAddedToTicket', array($this->ticketNotificationsSubscriber, 'processEvent'));
         $ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), $reporter, $message->getReference(), $attachments);
     }
     $this->processWatchers($message, $ticket);
 }