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
path: root/lib
diff options
context:
space:
mode:
authorIvan Sein <ivan@nextcloud.com>2019-08-27 17:29:34 +0300
committerGitHub <noreply@github.com>2019-08-27 17:29:34 +0300
commit8bc457a7ad79ccbdc132f0d8229acc396cc83900 (patch)
treef9e1ef56728cd852cb9177fe8c7b1ff1c6d6f2d3 /lib
parent25c978e1bc6022584de89c31d37ad58747d4fe92 (diff)
parenta9c123e17453a1b4d73b21b52b8dea6f0a9a85ae (diff)
Merge pull request #2104 from nextcloud/feature/2074/guest-name-in-notifications
Use the guest name in notifications if it was provided
Diffstat (limited to 'lib')
-rw-r--r--lib/Notification/Notifier.php44
1 files changed, 41 insertions, 3 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 0b54a40af..599fdd694 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -27,6 +27,7 @@ use OCA\Spreed\Chat\MessageParser;
use OCA\Spreed\Config;
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCA\Spreed\Exceptions\RoomNotFoundException;
+use OCA\Spreed\GuestManager;
use OCA\Spreed\Manager;
use OCA\Spreed\Participant;
use OCA\Spreed\Room;
@@ -57,6 +58,8 @@ class Notifier implements INotifier {
protected $config;
/** @var IUserManager */
protected $userManager;
+ /** @var GuestManager */
+ protected $guestManager;
/** @var IShareManager */
private $shareManager;
/** @var Manager */
@@ -74,6 +77,7 @@ class Notifier implements INotifier {
IURLGenerator $url,
Config $config,
IUserManager $userManager,
+ GuestManager $guestManager,
IShareManager $shareManager,
Manager $manager,
INotificationManager $notificationManager,
@@ -84,6 +88,7 @@ class Notifier implements INotifier {
$this->url = $url;
$this->config = $config;
$this->userManager = $userManager;
+ $this->guestManager = $guestManager;
$this->shareManager = $shareManager;
$this->manager = $manager;
$this->notificationManager = $notificationManager;
@@ -256,7 +261,12 @@ class Notifier implements INotifier {
} else if (!$isGuest) {
$subject = $l->t('A deleted user sent a message in conversation {call}');
} else {
- $subject = $l->t('A guest sent a message in conversation {call}');
+ try {
+ $richSubjectParameters['guest'] = $this->getGuestParameter($comment->getActorId());
+ $subject = $l->t('{guest} (guest) sent a message in conversation {call}');
+ } catch (ParticipantNotFoundException $e) {
+ $subject = $l->t('A guest sent a message in conversation {call}');
+ }
}
} else if ($notification->getSubject() === 'reply') {
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
@@ -266,7 +276,12 @@ class Notifier implements INotifier {
} else if (!$isGuest) {
$subject = $l->t('A deleted user replied to your message in conversation {call}');
} else {
- $subject = $l->t('A guest replied to your message in conversation {call}');
+ try {
+ $richSubjectParameters['guest'] = $this->getGuestParameter($comment->getActorId());
+ $subject = $l->t('{guest} (guest) replied to your message in conversation {call}');
+ } catch (ParticipantNotFoundException $e) {
+ $subject = $l->t('A guest replied to your message in conversation {call}');
+ }
}
} else if ($room->getType() === Room::ONE_TO_ONE_CALL) {
$subject = $l->t('{user} mentioned you in a private conversation');
@@ -275,7 +290,12 @@ class Notifier implements INotifier {
} else if (!$isGuest) {
$subject = $l->t('A deleted user mentioned you in conversation {call}');
} else {
- $subject = $l->t('A guest mentioned you in conversation {call}');
+ try {
+ $richSubjectParameters['guest'] = $this->getGuestParameter($comment->getActorId());
+ $subject = $l->t('{guest} (guest) mentioned you in conversation {call}');
+ } catch (ParticipantNotFoundException $e) {
+ $subject = $l->t('A guest mentioned you in conversation {call}');
+ }
}
$notification = $this->addActionButton($notification, $l->t('View chat'), false);
@@ -296,6 +316,24 @@ class Notifier implements INotifier {
}
/**
+ * @param string $actorId
+ * @return array
+ * @throws ParticipantNotFoundException
+ */
+ protected function getGuestParameter(string $actorId): array {
+ $name = $this->guestManager->getNameBySessionHash($actorId);
+ if (trim($name) === '') {
+ throw new ParticipantNotFoundException('Empty name');
+ }
+
+ return [
+ 'type' => 'highlight',
+ 'id' => $actorId,
+ 'name' => $name,
+ ];
+ }
+
+ /**
* @param Room $room
* @return string
* @throws \InvalidArgumentException