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

[stable30] feat(email): Recognize guests invited via email #13617

Merged
merged 14 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(email): Allow mentioning email guests
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Oct 23, 2024
commit 94982d3bf0722f6a4b027a81d55a1a25913e72c2
62 changes: 62 additions & 0 deletions lib/Chat/AutoComplete/SearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$groupIds = [];
/** @var array<string, string> $cloudIds */
$cloudIds = [];
/** @var array<string, string> $emailAttendees */
$emailAttendees = [];
/** @var list<Attendee> $guestAttendees */
$guestAttendees = [];

Expand All @@ -82,6 +84,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$attendee = $participant->getAttendee();
if ($attendee->getActorType() === Attendee::ACTOR_GUESTS) {
$guestAttendees[] = $attendee;
} elseif ($attendee->getActorType() === Attendee::ACTOR_EMAILS) {
$emailAttendees[$attendee->getActorId()] = $attendee->getDisplayName();
} elseif ($attendee->getActorType() === Attendee::ACTOR_USERS) {
$userIds[$attendee->getActorId()] = $attendee->getDisplayName();
} elseif ($attendee->getActorType() === Attendee::ACTOR_FEDERATED_USERS) {
Expand All @@ -95,6 +99,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$this->searchUsers($search, $userIds, $searchResult);
$this->searchGroups($search, $groupIds, $searchResult);
$this->searchGuests($search, $guestAttendees, $searchResult);
$this->searchEmails($search, $emailAttendees, $searchResult);
$this->searchFederatedUsers($search, $cloudIds, $searchResult);

return false;
Expand Down Expand Up @@ -300,6 +305,53 @@ protected function searchGuests(string $search, array $attendees, ISearchResult
$searchResult->addResultSet($type, $matches, $exactMatches);
}

/**
* @param string $search
* @param array<string, string> $attendees
* @param ISearchResult $searchResult
*/
protected function searchEmails(string $search, array $attendees, ISearchResult $searchResult): void {
if (empty($attendees)) {
$type = new SearchResultType('emails');
$searchResult->addResultSet($type, [], []);
return;
}

$search = strtolower($search);
$currentSessionHash = null;
if (!$this->userId) {
// Best effort: Might not work on guests that reloaded but not worth too much performance impact atm.
$currentSessionHash = false; // FIXME sha1($this->talkSession->getSessionForRoom($this->room->getToken()));
}

$matches = $exactMatches = [];
foreach ($attendees as $actorId => $displayName) {
if ($currentSessionHash === $actorId) {
// Do not suggest the current guest
continue;
}

$displayName = $displayName ?: $this->l->t('Guest');
if ($search === '') {
$matches[] = $this->createEmailResult($actorId, $displayName);
continue;
}

if (strtolower($displayName) === $search) {
$exactMatches[] = $this->createEmailResult($actorId, $displayName);
continue;
}

if (stripos($displayName, $search) !== false) {
$matches[] = $this->createEmailResult($actorId, $displayName);
continue;
}
}

$type = new SearchResultType('emails');
$searchResult->addResultSet($type, $matches, $exactMatches);
}

protected function createResult(string $type, string $uid, string $name): array {
if ($type === 'user' && $name === '') {
$name = $this->userManager->getDisplayName($uid) ?? $uid;
Expand Down Expand Up @@ -333,4 +385,14 @@ protected function createGuestResult(string $actorId, string $name): array {
],
];
}

protected function createEmailResult(string $actorId, string $name): array {
return [
'label' => $name,
'value' => [
'shareType' => 'email',
'shareWith' => 'email/' . $actorId,
],
];
}
}
15 changes: 15 additions & 0 deletions lib/Chat/Parser/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected function parseMessage(Message $chatMessage): void {

$search = $mention['id'];
if (
$mention['type'] === 'email' ||
$mention['type'] === 'group' ||
// $mention['type'] === 'federated_group' ||
// $mention['type'] === 'team' ||
Expand All @@ -131,6 +132,7 @@ protected function parseMessage(Message $chatMessage): void {
$message = str_replace('@"' . $search . '"', '{' . $mentionParameterId . '}', $message);
if (!str_contains($search, ' ')
&& !str_starts_with($search, 'guest/')
&& !str_starts_with($search, 'email/')
&& !str_starts_with($search, 'group/')
// && !str_starts_with($search, 'federated_group/')
// && !str_starts_with($search, 'team/')
Expand Down Expand Up @@ -160,6 +162,19 @@ protected function parseMessage(Message $chatMessage): void {
$displayName = $this->l->t('Guest');
}

$messageParameters[$mentionParameterId] = [
'type' => $mention['type'],
'id' => $mention['id'],
'name' => $displayName,
];
} elseif ($mention['type'] === 'email') {
try {
$participant = $this->participantService->getParticipantByActor($chatMessage->getRoom(), Attendee::ACTOR_EMAILS, $mention['id']);
$displayName = $participant->getAttendee()->getDisplayName() ?: $this->l->t('Guest');
} catch (ParticipantNotFoundException) {
$displayName = $this->l->t('Guest');
}

$messageParameters[$mentionParameterId] = [
'type' => $mention['type'],
'id' => $mention['id'],
Expand Down