/** * Update the dates of last message written by other participants */ protected function doDatesOfLastMessageWrittenByOtherParticipant(ThreadInterface $thread) { foreach ($thread->getAllMetadata() as $meta) { $participantId = $meta->getParticipant()->getId(); $timestamp = 0; foreach ($thread->getMessages() as $message) { if ($participantId != $message->getSender()->getId()) { $timestamp = max($timestamp, $message->getTimestamp()); } } if ($timestamp) { $date = new \DateTime(); $date->setTimestamp($timestamp); $meta->setLastMessageDate($date); } } }
/** * @param ParticipantInterface $sender * @return AbstractMessageBuilder (fluent interface) */ public function setSender(ParticipantInterface $sender) { $this->message->setSender($sender); $this->thread->addParticipant($sender); return $this; }
/** * Checks if the participant has marked the thread as deleted * * @param ThreadInterface $thread * * @return boolean true if participant has marked the thread as deleted, false otherwise */ public function isThreadDeletedByParticipant(ThreadInterface $thread) { return $thread->isDeletedByParticipant($this->getAuthenticatedParticipant()); }
/** * Tells if the current participant is allowed * to see this thread * * @param ThreadInterface $thread * @return boolean */ public function canSeeThread(ThreadInterface $thread) { return $this->getAuthenticatedParticipant() && $thread->isParticipant($this->getAuthenticatedParticipant()); }
/** * Marks all messages of this thread as read by this participant * * @param ThreadInterface $thread * @param ParticipantInterface $participant * @param boolean $isRead */ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead) { foreach ($thread->getMessages() as $message) { $this->markIsReadByParticipant($message, $participant, $isRead); } }
/** * Marks all messages of this thread as read by this participant * * @param ThreadInterface $thread * @param ParticipantInterface $participant * @param boolean $isRead */ public function markIsReadByThreadAndParticipant(ThreadInterface $thread, ParticipantInterface $participant, $isRead) { $this->markIsReadByCondition($participant, $isRead, function (Builder $queryBuilder) use($thread) { $queryBuilder->field('thread.$id')->equals(new \MongoId($thread->getId())); }); }