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:
authorJoas Schilling <coding@schilljs.com>2019-07-10 16:25:33 +0300
committerJoas Schilling <coding@schilljs.com>2019-07-25 17:39:51 +0300
commite85173e4cb76e288cafac2564499c8137ab86c23 (patch)
tree56e77ce6fcf371fd6e7f16172aabf0020afcaf85 /lib
parent4b392495dcf06a1ab0de977bfa21a01cb1098f58 (diff)
Also parse mentions of guests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/Parser/UserMention.php26
-rw-r--r--lib/GuestManager.php6
2 files changed, 28 insertions, 4 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']);
diff --git a/lib/GuestManager.php b/lib/GuestManager.php
index d93dfcbbb..f1f98e0b1 100644
--- a/lib/GuestManager.php
+++ b/lib/GuestManager.php
@@ -128,7 +128,7 @@ class GuestManager {
$row = $result->fetch();
$result->closeCursor();
- if (isset($row['display_name'])) {
+ if (isset($row['display_name']) && $row['display_name'] !== '') {
return $row['display_name'];
}
@@ -150,6 +150,10 @@ class GuestManager {
$map = [];
while ($row = $result->fetch()) {
+ if ($row['display_name'] === '') {
+ continue;
+ }
+
$map[$row['session_hash']] = $row['display_name'];
}
$result->closeCursor();