/** * {@inheritdoc} */ public function removeTag(ConversationInterface $conversation, PersonInterface $person, TagInterface $tag) { $conversationPerson = $this->repository->getConversationPerson($conversation, $person); if (!$conversationPerson instanceof ConversationPersonInterface) { throw new \LogicException(sprintf('Link between conversation %s and person %s was not found in %s', $conversation->getId(), $person->getId(), __METHOD__)); } if (!$conversationPerson->hasTag($tag)) { return false; } $conversationPerson->removeTag($tag); $this->driver->persistConversationPerson($conversationPerson); $this->driver->flush(); return true; }
/** * {@inheritdoc} */ public function sendMessage(ConversationInterface $conversation, PersonInterface $sender, $body) { Assert::string($body, '$body expected a string in Sender::sendMessage(). Got: %s'); // Create the message $message = $this->createAndPersistMessage($conversation, $sender, $body); // Add the conversation persons links foreach ($conversation->getConversationPersons() as $conversationPerson) { $person = $conversationPerson->getPerson(); $this->createAndPersistMessagePerson($message, $person, $person->getId() === $sender->getId()); } // Flush the previously persisted entities $this->driver->flush(); // Dispatch the event $this->dispatchMessageEvent($message); return $message; }
public function testFindMessagesLimit() { $conversation = $this->driver->createConversationModel(); $conversation->setSubject('Subject'); $this->driver->persistConversation($conversation); $firstMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body1'); $this->driver->persistMessage($firstMessage); $secondMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body2'); $this->driver->persistMessage($secondMessage); $thirdMessage = $this->driver->createMessageModel($conversation, $this->createPerson(), 'Body3'); $this->driver->persistMessage($thirdMessage); $this->driver->flush(); $fetched = $this->driver->findMessages($conversation, 0, 2, 'ASC'); $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $fetched); $this->assertCount(2, $fetched); $this->assertMessagesEquals($firstMessage, $fetched[0]); $this->assertMessagesEquals($secondMessage, $fetched[1]); $fetched = $this->driver->findMessages($conversation, 1, 2, 'ASC'); $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $fetched); $this->assertCount(2, $fetched); $this->assertMessagesEquals($secondMessage, $fetched[0]); $this->assertMessagesEquals($thirdMessage, $fetched[1]); }