diff options
author | Joas Schilling <coding@schilljs.com> | 2019-02-20 14:16:01 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-02-20 14:17:37 +0300 |
commit | 2f60aab4abcae62db6dddc594c86b28d199a74e0 (patch) | |
tree | 91dc79b5ebf8613eef77674cbc945a22c11fec8b /lib/Notification/Notifier.php | |
parent | f828ab9c9e96e59ddcf7c34d4c39eaf1f85753a5 (diff) |
Introduce a Message model for parsing which also allows to hide messages
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r-- | lib/Notification/Notifier.php | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 5209cc479..064bcdeed 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -24,8 +24,10 @@ namespace OCA\Spreed\Notification; use OCA\Spreed\Chat\MessageParser; +use OCA\Spreed\Exceptions\ParticipantNotFoundException; use OCA\Spreed\Exceptions\RoomNotFoundException; use OCA\Spreed\Manager; +use OCA\Spreed\Participant; use OCA\Spreed\Room; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; @@ -111,6 +113,13 @@ class Notifier implements INotifier { } } + try { + $participant = $room->getParticipant($notification->getUser()); + } catch (ParticipantNotFoundException $e) { + // Room does not exist + throw new \InvalidArgumentException('User is not part of the room anymore'); + } + $notification ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('spreed', 'app-dark.svg'))) ->setLink($this->url->linkToRouteAbsolute('spreed.pagecontroller.showCall', ['token' => $room->getToken()])); @@ -126,7 +135,7 @@ class Notifier implements INotifier { return $this->parseCall($notification, $room, $l); } if ($subject === 'mention' || $subject === 'chat') { - return $this->parseChatMessage($notification, $room, $l); + return $this->parseChatMessage($notification, $room, $participant, $l); } throw new \InvalidArgumentException('Unknown subject'); @@ -135,11 +144,12 @@ class Notifier implements INotifier { /** * @param INotification $notification * @param Room $room + * @param Participant $participant * @param IL10N $l * @return INotification * @throws \InvalidArgumentException */ - protected function parseChatMessage(INotification $notification, Room $room, IL10N $l): INotification { + protected function parseChatMessage(INotification $notification, Room $room, Participant $participant, IL10N $l): INotification { if ($notification->getObjectType() !== 'chat') { throw new \InvalidArgumentException('Unknown object type'); } @@ -181,11 +191,15 @@ class Notifier implements INotifier { throw new \InvalidArgumentException('Unknown comment'); } - $recipient = $this->userManager->get($notification->getUser()); - [$richMessage, $richMessageParameters] = $this->messageParser->parseMessage($room, $comment, $l, $recipient); + $message = MessageParser::createMessage($room, $participant, $comment, $l); + $this->messageParser->parseMessage($message); + + if (!$message->getVisibility()) { + throw new \InvalidArgumentException('Invisible comment'); + } $placeholders = $replacements = []; - foreach ($richMessageParameters as $placeholder => $parameter) { + foreach ($message->getMessageParameters() as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; if ($parameter['type'] === 'user') { $replacements[] = '@' . $parameter['name']; @@ -194,8 +208,8 @@ class Notifier implements INotifier { } } - $notification->setParsedMessage(str_replace($placeholders, $replacements, $richMessage)); - $notification->setRichMessage($richMessage, $richMessageParameters); + $notification->setParsedMessage(str_replace($placeholders, $replacements, $message->getMessage())); + $notification->setRichMessage($message->getMessage(), $message->getMessageParameters()); $richSubjectParameters = [ 'user' => $richSubjectUser, |