diff --git a/lib/Chat/AutoComplete/SearchPlugin.php b/lib/Chat/AutoComplete/SearchPlugin.php index 7baf24b332d..0bf0ca2ca28 100644 --- a/lib/Chat/AutoComplete/SearchPlugin.php +++ b/lib/Chat/AutoComplete/SearchPlugin.php @@ -80,6 +80,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b $userIds = []; /** @var array $groupIds */ $groupIds = []; + /** @var array $teams */ + $teams = []; /** @var array $cloudIds */ $cloudIds = []; /** @var list $guestAttendees */ @@ -103,12 +105,15 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b $cloudIds[$attendee->getActorId()] = $attendee->getDisplayName(); } elseif ($attendee->getActorType() === Attendee::ACTOR_GROUPS) { $groupIds[$attendee->getActorId()] = $attendee->getDisplayName(); + } elseif ($attendee->getActorType() === Attendee::ACTOR_CIRCLES) { + $teams[$attendee->getActorId()] = $attendee->getDisplayName(); } } } $this->searchUsers($search, $userIds, $searchResult); $this->searchGroups($search, $groupIds, $searchResult); + $this->searchTeams($search, $teams, $searchResult); $this->searchGuests($search, $guestAttendees, $searchResult); $this->searchFederatedUsers($search, $cloudIds, $searchResult); @@ -268,6 +273,44 @@ protected function searchGroups(string $search, array $groups, ISearchResult $se $searchResult->addResultSet($type, $matches, $exactMatches); } + /** + * @param array $teams + */ + protected function searchTeams(string $search, array $teams, ISearchResult $searchResult): void { + $search = strtolower($search); + + $type = new SearchResultType('groups'); + + $matches = $exactMatches = []; + foreach ($teams as $id => $displayName) { + if ($displayName === '') { + continue; + } + + $id = (string) $id; + if ($searchResult->hasResult($type, $id)) { + continue; + } + + if ($search === '') { + $matches[] = $this->createTeamResult($id, $displayName); + continue; + } + + if (strtolower($displayName) === $search) { + $exactMatches[] = $this->createTeamResult($id, $displayName); + continue; + } + + if (stripos($displayName, $search) !== false) { + $matches[] = $this->createTeamResult($id, $displayName); + continue; + } + } + + $searchResult->addResultSet($type, $matches, $exactMatches); + } + /** * @param string $search * @param list $attendees @@ -339,6 +382,16 @@ protected function createGroupResult(string $groupId, string $name): array { ]; } + protected function createTeamResult(string $teamId, string $name): array { + return [ + 'label' => $name, + 'value' => [ + 'shareType' => 'team', + 'shareWith' => 'team/' . $teamId, + ], + ]; + } + protected function createGuestResult(string $actorId, string $name): array { return [ 'label' => $name, diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php index 1b241088ea9..15a51a3556b 100644 --- a/lib/Chat/Parser/UserMention.php +++ b/lib/Chat/Parser/UserMention.php @@ -130,7 +130,7 @@ protected function parseMessage(Message $chatMessage): void { if ( $mention['type'] === 'group' || // $mention['type'] === 'federated_group' || - // $mention['type'] === 'team' || + $mention['type'] === 'team' || // $mention['type'] === 'federated_team' || $mention['type'] === 'federated_user') { $search = $mention['type'] . '/' . $mention['id']; @@ -147,7 +147,7 @@ protected function parseMessage(Message $chatMessage): void { && !str_starts_with($search, 'guest/') && !str_starts_with($search, 'group/') // && !str_starts_with($search, 'federated_group/') - // && !str_starts_with($search, 'team/') + && !str_starts_with($search, 'team/') // && !str_starts_with($search, 'federated_team/') && !str_starts_with($search, 'federated_user/')) { $message = str_replace('@' . $search, '{' . $mentionParameterId . '}', $message); @@ -212,6 +212,12 @@ protected function parseMessage(Message $chatMessage): void { 'id' => $mention['id'], 'name' => $displayName, ]; + } elseif ($mention['type'] === 'team') { + $messageParameters[$mentionParameterId] = [ + 'type' => 'circle', + 'id' => $mention['id'], + 'name' => $mention['id'], + ]; } else { try { $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);