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 <213943+nickvergessen@users.noreply.github.com>2019-08-28 11:22:13 +0300
committerGitHub <noreply@github.com>2019-08-28 11:22:13 +0300
commit3ee86747256355cd26de5f193ad37780f1dad0f2 (patch)
tree5f42244083edf0e2a3d314fcfd2f2a72fe06e91a /lib
parentc9f390de4f3cfb4b903c62b1a38a21aad98d6022 (diff)
parent2caa0d2146631cfa4387116f412d10f57445ca06 (diff)
Merge pull request #1974 from nextcloud/feature/noid/guest-mentions
👤🏷️ Guest mentions
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/AutoComplete/SearchPlugin.php83
-rw-r--r--lib/Chat/Parser/UserMention.php26
-rw-r--r--lib/GuestManager.php6
-rw-r--r--lib/Manager.php11
4 files changed, 117 insertions, 9 deletions
diff --git a/lib/Chat/AutoComplete/SearchPlugin.php b/lib/Chat/AutoComplete/SearchPlugin.php
index ab1ca5316..8658dbd99 100644
--- a/lib/Chat/AutoComplete/SearchPlugin.php
+++ b/lib/Chat/AutoComplete/SearchPlugin.php
@@ -24,10 +24,13 @@ namespace OCA\Spreed\Chat\AutoComplete;
use OCA\Spreed\Files\Util;
+use OCA\Spreed\GuestManager;
use OCA\Spreed\Room;
+use OCA\Spreed\TalkSession;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
+use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
@@ -35,21 +38,32 @@ class SearchPlugin implements ISearchPlugin {
/** @var IUserManager */
protected $userManager;
+ /** @var GuestManager */
+ protected $guestManager;
+ /** @var TalkSession */
+ protected $talkSession;
/** @var Util */
protected $util;
-
/** @var string|null */
protected $userId;
+ /** @var IL10N */
+ protected $l;
/** @var Room */
protected $room;
public function __construct(IUserManager $userManager,
+ GuestManager $guestManager,
+ TalkSession $talkSession,
Util $util,
- ?string $userId) {
+ ?string $userId,
+ IL10N $l) {
$this->userManager = $userManager;
+ $this->guestManager = $guestManager;
+ $this->talkSession = $talkSession;
$this->util = $util;
$this->userId = $userId;
+ $this->l = $l;
}
public function setContext(array $context): void {
@@ -74,15 +88,24 @@ class SearchPlugin implements ISearchPlugin {
return false;
}
- $userIds = $this->room->getParticipantUserIds();
+ $userIds = $guestSessionHashes = [];
+ $participants = $this->room->getParticipants();
+ foreach ($participants as $participant) {
+ if ($participant->isGuest()) {
+ $guestSessionHashes[] = sha1($participant->getSessionId());
+ } else {
+ $userIds[] = $participant->getUser();
+ }
+ }
+
if ($this->room->getType() === Room::ONE_TO_ONE_CALL
&& $this->room->getName() !== '') {
// Add potential leavers of one-to-one rooms again.
$userIds[] = $this->room->getName();
}
- // FIXME Handle guests
$this->searchUsers($search, $userIds, $searchResult);
+ $this->searchGuests($search, $guestSessionHashes, $searchResult);
return false;
}
@@ -132,6 +155,48 @@ class SearchPlugin implements ISearchPlugin {
$searchResult->addResultSet($type, $matches, $exactMatches);
}
+ protected function searchGuests(string $search, array $guestSessionHashes, ISearchResult $searchResult): void {
+ if (empty($guestSessionHashes)) {
+ $type = new SearchResultType('guests');
+ $searchResult->addResultSet($type, [], []);
+ return;
+ }
+
+ $search = strtolower($search);
+ $displayNames = $this->guestManager->getNamesBySessionHashes($guestSessionHashes);
+ $currentSessionHash = null;
+ if (!$this->userId) {
+ $currentSessionHash = sha1($this->talkSession->getSessionForRoom($this->room->getToken()));
+ }
+
+ $matches = $exactMatches = [];
+ foreach ($guestSessionHashes as $guestSessionHash) {
+ if ($currentSessionHash === $guestSessionHash) {
+ // Do not suggest the current guest
+ continue;
+ }
+
+ $name = $displayNames[$guestSessionHash] ?? $this->l->t('Guest');
+ if ($search === '') {
+ $matches[] = $this->createGuestResult($guestSessionHash, $name);
+ continue;
+ }
+
+ if (strtolower($name) === $search) {
+ $exactMatches[] = $this->createGuestResult($guestSessionHash, $name);
+ continue;
+ }
+
+ if (stripos($name, $search) !== false) {
+ $matches[] = $this->createGuestResult($guestSessionHash, $name);
+ continue;
+ }
+ }
+
+ $type = new SearchResultType('guests');
+ $searchResult->addResultSet($type, $matches, $exactMatches);
+ }
+
protected function createResult(string $type, string $uid, string $name): array {
if ($type === 'user' && $name === '') {
$user = $this->userManager->get($uid);
@@ -150,4 +215,14 @@ class SearchPlugin implements ISearchPlugin {
],
];
}
+
+ protected function createGuestResult(string $uid, string $name): array {
+ return [
+ 'label' => $name,
+ 'value' => [
+ 'shareType' => 'guest',
+ 'shareWith' => 'guest/' . $uid,
+ ],
+ ];
+ }
}
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();
diff --git a/lib/Manager.php b/lib/Manager.php
index 36db22785..8933f3170 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -51,6 +51,8 @@ class Manager {
private $userManager;
/** @var CommentsManager */
private $commentsManager;
+ /** @var TalkSession */
+ private $talkSession;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var ITimeFactory */
@@ -65,6 +67,7 @@ class Manager {
ISecureRandom $secureRandom,
IUserManager $userManager,
CommentsManager $commentsManager,
+ TalkSession $talkSession,
EventDispatcherInterface $dispatcher,
ITimeFactory $timeFactory,
IHasher $hasher,
@@ -74,6 +77,7 @@ class Manager {
$this->secureRandom = $secureRandom;
$this->userManager = $userManager;
$this->commentsManager = $commentsManager;
+ $this->talkSession = $talkSession;
$this->dispatcher = $dispatcher;
$this->timeFactory = $timeFactory;
$this->hasher = $hasher;
@@ -702,7 +706,12 @@ class Manager {
}
try {
- $room->getParticipant($userId);
+ if ($userId === '') {
+ $sessionId = $this->talkSession->getSessionForRoom($room->getToken());
+ $room->getParticipantBySession($sessionId);
+ } else {
+ $room->getParticipant($userId);
+ }
} catch (ParticipantNotFoundException $e) {
// Do not leak the name of rooms the user is not a part of
return $this->l->t('Private conversation');