Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-08-07 18:48:21 +0300
committerJoas Schilling <coding@schilljs.com>2018-08-07 19:05:51 +0300
commit9b1dcc37bbba04d2a4f23690967d8bf109f02166 (patch)
treed8cfb09192817fde2a5f666af61b5135172c14e5 /lib/Notification/Notifier.php
parent28e082b969bdd30aa9e3a99706011c218c4c1c0f (diff)
Set the notification message to the full chat message with mentions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r--lib/Notification/Notifier.php48
1 files changed, 39 insertions, 9 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 927f643c0..4ca93281e 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -23,9 +23,12 @@ declare(strict_types=1);
namespace OCA\Spreed\Notification;
+use OCA\Spreed\Chat\RichMessageHelper;
use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
+use OCP\Comments\ICommentsManager;
+use OCP\Comments\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -49,14 +52,28 @@ class Notifier implements INotifier {
/** @var Manager */
protected $manager;
+ /** @var ICommentsManager */
+ protected $commentManager;
+
+ /** @var RichMessageHelper */
+ protected $richMessageHelper;
+
/** @var Definitions */
protected $definitions;
- public function __construct(IFactory $lFactory, IURLGenerator $url, IUserManager $userManager, Manager $manager, Definitions $definitions) {
+ public function __construct(IFactory $lFactory,
+ IURLGenerator $url,
+ IUserManager $userManager,
+ Manager $manager,
+ ICommentsManager $commentManager,
+ RichMessageHelper $richMessageHelper,
+ Definitions $definitions) {
$this->lFactory = $lFactory;
$this->url = $url;
$this->userManager = $userManager;
$this->manager = $manager;
+ $this->commentManager = $commentManager;
+ $this->richMessageHelper = $richMessageHelper;
$this->definitions = $definitions;
}
@@ -146,16 +163,29 @@ class Notifier implements INotifier {
}
$messageParameters = $notification->getMessageParameters();
+ if (!isset($messageParameters['commentId'])) {
+ throw new \InvalidArgumentException('Unknown comment');
+ }
- $parsedMessage = $notification->getMessage();
- if (\in_array('ellipsisStart', $messageParameters) && !\in_array('ellipsisEnd', $messageParameters)) {
- $parsedMessage = $l->t('… %s', $parsedMessage);
- } else if (!\in_array('ellipsisStart', $messageParameters) && \in_array('ellipsisEnd', $messageParameters)) {
- $parsedMessage = $l->t('%s …', $parsedMessage);
- } else if (\in_array('ellipsisStart', $messageParameters) && \in_array('ellipsisEnd', $messageParameters)) {
- $parsedMessage = $l->t('… %s …', $parsedMessage);
+ try {
+ $comment = $this->commentManager->get($messageParameters['commentId']);
+ } catch (NotFoundException $e) {
+ throw new \InvalidArgumentException('Unknown comment');
}
- $notification->setParsedMessage($parsedMessage);
+ list($richMessage, $richMessageParameters) = $this->richMessageHelper->getRichMessage($comment);
+
+ $placeholders = $replacements = [];
+ foreach ($richMessageParameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ if ($parameter['type'] === 'user') {
+ $replacements[] = '@' . $parameter['name'];
+ } else {
+ $replacements[] = $parameter['name'];
+ }
+ }
+
+ $notification->setParsedMessage(str_replace($placeholders, $replacements, $richMessage));
+ $notification->setRichMessage($richMessage, $richMessageParameters);
if ($notification->getSubject() === 'chat') {
$notification