Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chat): Team mentions #12161

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/Chat/AutoComplete/SearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$userIds = [];
/** @var array<string, string> $groupIds */
$groupIds = [];
/** @var array<string, string> $teams */
$teams = [];
/** @var array<string, string> $cloudIds */
$cloudIds = [];
/** @var list<Attendee> $guestAttendees */
Expand All @@ -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);

Expand Down Expand Up @@ -268,6 +273,44 @@ protected function searchGroups(string $search, array $groups, ISearchResult $se
$searchResult->addResultSet($type, $matches, $exactMatches);
}

/**
* @param array<array-key, string> $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<Attendee> $attendees
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions lib/Chat/Parser/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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);
Expand Down Expand Up @@ -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']);
Expand Down
Loading