public function testRemoveNotExistingTag() { $person = Mockery::mock('FOS\\Message\\Model\\PersonInterface'); $conversation = Mockery::mock('FOS\\Message\\Model\\ConversationInterface'); $tag = Mockery::mock('FOS\\Message\\Model\\TagInterface'); $conversationPerson = Mockery::mock('FOS\\Message\\Model\\ConversationPersonInterface'); $conversationPerson->shouldReceive('hasTag')->with($tag)->once()->andReturn(false); $this->repository->shouldReceive('getConversationPerson')->once()->with($conversation, $person)->andReturn($conversationPerson); $this->assertFalse($this->tagger->removeTag($conversation, $person, $tag)); }
public function countUnread(PersonInterface $person) { $conversations = $this->repository->getPersonConversations($person); $count = 0; foreach ($conversations as $conversation) { if ($conversation->getFirstUnreadMessage($person)) { $count++; } } return $count; }
/** * Stores the object in the request. * * @param Request $request The request * @param ParamConverter $configuration Contains the name, class and options of the object * * @return bool True if the object has been successfully set, else false */ public function apply(Request $request, ParamConverter $configuration) { if (!$request->attributes->has($configuration->getName())) { return false; } $id = $request->attributes->get($configuration->getName()); $conversation = $this->repository->getConversation($id); if (!$conversation) { throw new NotFoundHttpException(); } $request->attributes->set($configuration->getName(), $conversation); return true; }
/** * {@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; }
/** * @ApiDoc( * section="Messaging", * description="Get a list of messages for a Conversation", * resource=true, * output={ * "class" = "array<FOS\Message\Model\Message>", * "groups" = { "message_list" }, * }, * ) * @Method("GET") * @Route * @View(serializerGroups={"message_list"}) * @param ConversationInterface $conversation * @param ParamFetcherInterface $paramFetcher * @QueryParam(name="limit", requirements="\d+", default="10", description="Limit Results") * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset Results") * @ParamConverter(name="conversation", converter="message_bundle.conversation") * @return OffsetRepresentation|MessageInterface[] */ public function messagesAction(ConversationInterface $conversation, ParamFetcherInterface $paramFetcher) { return new OffsetRepresentation(new CollectionRepresentation($this->repository->getMessages($conversation, (int) $paramFetcher->get('offset'), (int) $paramFetcher->get('limit')), 'message:message', 'message'), 'message_message_messages', ['conversation' => $conversation->getId()], (int) $paramFetcher->get('offset'), (int) $paramFetcher->get('limit'), null, 'offset', 'limit'); }
/** * @ApiDoc( * section="Messaging", * description="List all conversations o a user", * resource=true, * output={ * "class" = "array<FOS\Message\Model\Conversation>", * "groups" = { "conversation_list" } * }, * statusCodes={ * 200 = "Loaded List", * }, * ) * @Route("/users/{user}/conversations") * @param PersonInterface $user * @ParamConverter(name="user", class="UserBundle:User", converter="doctrine.orm") * @Method("GET") * @View(serializerGroups={"conversation_list"}) * @return CollectionRepresentation|ConversationInterface[] */ public function listAction(PersonInterface $user) { return new CollectionRepresentation($this->repository->getPersonConversations($user), 'message:conversation', 'conversation'); }