diff options
author | Joas Schilling <coding@schilljs.com> | 2019-07-10 16:25:33 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-07-25 17:39:51 +0300 |
commit | e85173e4cb76e288cafac2564499c8137ab86c23 (patch) | |
tree | 56e77ce6fcf371fd6e7f16172aabf0020afcaf85 /lib/Chat | |
parent | 4b392495dcf06a1ab0de977bfa21a01cb1098f58 (diff) |
Also parse mentions of guests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Chat')
-rw-r--r-- | lib/Chat/Parser/UserMention.php | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php index f21ec4372..25216030f 100644 --- a/lib/Chat/Parser/UserMention.php +++ b/lib/Chat/Parser/UserMention.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace OCA\Spreed\Chat\Parser; +use OCA\Spreed\Exceptions\ParticipantNotFoundException; +use OCA\Spreed\GuestManager; use OCA\Spreed\Model\Message; use OCA\Spreed\Room; use OCP\Comments\ICommentsManager; @@ -37,18 +39,20 @@ class UserMention { /** @var ICommentsManager */ private $commentsManager; - /** @var IUserManager */ private $userManager; - + /** @var GuestManager */ + private $guestManager; /** @var IL10N */ private $l; public function __construct(ICommentsManager $commentsManager, IUserManager $userManager, + GuestManager $guestManager, IL10N $l) { $this->commentsManager = $commentsManager; $this->userManager = $userManager; + $this->guestManager = $guestManager; $this->l = $l; } @@ -96,7 +100,11 @@ class UserMention { // index of the mentions of that type. $mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']]; - $placeholder = strpos($mention['id'], ' ') !== false ? ('@"' . $mention['id'] . '"') : ('@' . $mention['id']); + if (strpos($mention['id'], ' ') !== false || strpos($mention['id'], 'guest/') === 0) { + $placeholder = '@"' . $mention['id'] . '"'; + } else { + $placeholder = '@' . $mention['id']; + } $message = str_replace($placeholder, '{' . $mentionParameterId . '}', $message); if ($mention['type'] === 'call') { @@ -106,6 +114,18 @@ class UserMention { 'name' => $chatMessage->getRoom()->getDisplayName($chatMessage->getParticipant()->getUser()), 'call-type' => $this->getRoomType($chatMessage->getRoom()), ]; + } else if ($mention['type'] === 'guest') { + try { + $displayName = $this->guestManager->getNameBySessionHash(substr($mention['id'], strlen('guest/'))); + } catch (ParticipantNotFoundException $e) { + $displayName = $this->l->t('Guest'); + } + + $messageParameters[$mentionParameterId] = [ + 'type' => $mention['type'], + 'id' => $mention['id'], + 'name' => $displayName, + ]; } else { try { $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |