public function testProcessWhenMessageWithReference()
 {
     $message = new Message(self::DUMMY_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_SUBJECT, self::DUMMY_CONTENT, $this->getDummyFrom(), self::DUMMY_MESSAGE_TO, self::DUMMY_REFERENCE);
     $diamanteUser = $this->getReporter(1);
     $this->userService->expects($this->once())->method('getUserByEmail')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue($diamanteUser));
     $reporter = $this->getReporter($diamanteUser->getId());
     $this->messageReferenceService->expects($this->once())->method('createCommentForTicket')->with($this->equalTo($message->getContent()), $reporter, $message->getReference());
     $this->ticketStrategy->process($message);
 }
 /**
  * @param Message $message
  */
 public function process(Message $message)
 {
     $diamanteUser = $this->diamanteUserService->getUserByEmail($message->getFrom()->getEmail());
     if (is_null($diamanteUser) || !$diamanteUser->isDiamanteUser()) {
         $id = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommand($message));
         $diamanteUser = new User($id, User::TYPE_DIAMANTE);
     }
     $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(), (string) $diamanteUser, $assigneeId, $attachments);
     } else {
         $ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), (string) $diamanteUser, $message->getReference(), $attachments);
     }
     $this->processWatchers($message, $ticket);
 }
 /**
  * @param Message $message
  */
 public function process(Message $message)
 {
     $diamanteUser = $this->diamanteUserService->getUserByEmail($message->getFrom()->getEmail());
     if (is_null($diamanteUser) || !$diamanteUser->isDiamanteUser()) {
         $id = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommand($message->getFrom()));
         $diamanteUser = new User($id, User::TYPE_DIAMANTE);
     }
     $attachments = $message->getAttachments();
     if (!$message->getReference()) {
         $defaultBranch = (int) $this->configManager->get('diamante_desk.default_branch');
         if (is_null($defaultBranch)) {
             throw new \RuntimeException("Invalid configuration, default branch should be configured");
         }
         $branch = $this->branchService->getBranch($defaultBranch);
         $assigneeId = $branch->getDefaultAssigneeId() ? $branch->getDefaultAssigneeId() : null;
         $ticket = $this->messageReferenceService->createTicket($message, $defaultBranch, (string) $diamanteUser, $assigneeId, $attachments);
     } else {
         $ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), (string) $diamanteUser, $message->getReference(), $attachments);
     }
     $this->processWatchers($message, $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);
 }