public function handleCommentContent(BaseComment $comment) { $content = $this->escape($comment->getCommentBody()); $replacements = []; $users = []; $mentions = Tags::parseMentionTags($content); foreach ($mentions as $username) { $tag = '@' . $username; if (!isset($replacements[$tag])) { $user = $this->userRepo->findOneByUsername($username); if ($user) { $users[$username] = $user; $replacements[$tag] = "<a data-user-id=\"{$user->getId()}\">{$tag}</a>"; } } } $content = UrlConverter::wrapLinks($content); $content = Tags::replaceMentionTags($content, $replacements); $content = Tags::wrapHashTags($content); $comment->setCommentBodyHtml($content); return $users; }
public function noticeCommentMentioned(BaseComment $comment, $recipients) { $group = null; if ($comment instanceof MicropetitionComment) { $micropetition = $comment->getPetition(); $group = $micropetition->getGroup(); $target = ['id' => $micropetition->getId(), 'preview' => $this->preparePreview($comment->getCommentBody()), 'type' => $micropetition->getType(), 'label' => $micropetition->getType() === $micropetition::TYPE_QUORUM ? 'post' : 'petition']; } else { if ($comment instanceof Comment) { $question = $comment->getQuestion(); $target = ['id' => $question->getId(), 'type' => $question->getType()]; $target['label'] = $this->getLabelByPoll($question); $group = $question->getUser(); } } if ($comment->getParentComment()->getUser()) { $target['comment_id'] = $comment->getId(); } $user = $comment->getUser(); $target['user_id'] = $user->getId(); $target['first_name'] = $user->getFirstName(); $target['last_name'] = $user->getLastName(); foreach ($recipients as $recipient) { if ($group instanceof Group && $this->em->getRepository(UserGroup::class)->isJoinedUser($group, $recipient)) { $socialActivity = (new SocialActivity(SocialActivity::TYPE_COMMENT_MENTIONED, null, $group))->setTarget($target)->setRecipient($recipient); $this->em->persist($socialActivity); $this->em->flush($socialActivity); $this->pt->addToQueue('sendSocialActivity', [$socialActivity->getId()]); } else { if ($this->em->getRepository(UserFollow::class)->findActiveFollower($user, $recipient)) { $socialActivity = (new SocialActivity(SocialActivity::TYPE_COMMENT_MENTIONED, $user, null))->setTarget($target)->setRecipient($recipient); $this->em->persist($socialActivity); $this->em->flush($socialActivity); $this->pt->addToQueue('sendSocialActivity', [$socialActivity->getId()]); } } } }
public function getCommentBody() { $this->__load(); return parent::getCommentBody(); }