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): Treat email guests like normal guests in some cases
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Oct 23, 2024
commit 2a3abc2f69d7c359e708b2865547e098bde3c5a4
11 changes: 6 additions & 5 deletions lib/Chat/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,18 @@ protected function getActorInformation(Message $message, string $actorType, stri
} elseif ($actorType === Attendee::ACTOR_BRIDGED) {
$displayName = $actorId;
$actorId = MatterbridgeManager::BRIDGE_BOT_USERID;
} elseif ($actorType === Attendee::ACTOR_GUESTS
} elseif (($actorType === Attendee::ACTOR_GUESTS || $actorType === Attendee::ACTOR_EMAILS)
&& !in_array($actorId, [Attendee::ACTOR_ID_CLI, Attendee::ACTOR_ID_CHANGELOG], true)) {
if (isset($this->guestNames[$actorId])) {
$displayName = $this->guestNames[$actorId];
$cacheKey = $actorType . '/' . $actorId;
if (isset($this->guestNames[$cacheKey])) {
$displayName = $this->guestNames[$cacheKey];
} else {
try {
$participant = $this->participantService->getParticipantByActor($message->getRoom(), str_contains($actorId, '@') ? Attendee::ACTOR_EMAILS : Attendee::ACTOR_GUESTS, $actorId);
$participant = $this->participantService->getParticipantByActor($message->getRoom(), $actorType, $actorId);
$displayName = $participant->getAttendee()->getDisplayName();
} catch (ParticipantNotFoundException) {
}
$this->guestNames[$actorId] = $displayName;
$this->guestNames[$cacheKey] = $displayName;
}
} elseif ($actorType === Attendee::ACTOR_BOTS) {
$displayName = $actorId . '-bot';
Expand Down
6 changes: 5 additions & 1 deletion lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ public function sendSystemMessageAboutPromoteOrDemoteModerator(ParticipantModifi
$room = $event->getRoom();
$attendee = $event->getParticipant()->getAttendee();

if ($attendee->getActorType() !== Attendee::ACTOR_USERS && $attendee->getActorType() !== Attendee::ACTOR_GUESTS) {
if (!in_array($attendee->getActorType(), [
Attendee::ACTOR_USERS,
Attendee::ACTOR_EMAILS,
Attendee::ACTOR_GUESTS,
], true)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Collaboration/Reference/TalkReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function fetchReference(Reference $reference): void {
}

$displayName = $message->getActorDisplayName();
if ($message->getActorType() === Attendee::ACTOR_GUESTS) {
if (in_array($message->getActorType(), [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
if ($displayName === '') {
$displayName = $this->l->t('Guest');
} else {
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ protected function getActorInfo(string $actorDisplayName = ''): array {
if ($actorDisplayName) {
$this->guestManager->updateName($this->room, $this->participant, $actorDisplayName);
}
return [Attendee::ACTOR_GUESTS, $this->participant->getAttendee()->getActorId()];
/** @var Attendee::ACTOR_GUESTS|Attendee::ACTOR_EMAILS $actorType */
$actorType = $this->participant->getAttendee()->getActorType();
return [$actorType, $this->participant->getAttendee()->getActorId()];
}

if ($this->userId === MatterbridgeManager::BRIDGE_BOT_USERID && $actorDisplayName) {
Expand Down
1 change: 1 addition & 0 deletions lib/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function isReplyable(): bool {
Attendee::ACTOR_USERS,
Attendee::ACTOR_FEDERATED_USERS,
Attendee::ACTOR_GUESTS,
Attendee::ACTOR_EMAILS,
Attendee::ACTOR_BOTS,
], true);
}
Expand Down
25 changes: 15 additions & 10 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('Reminder: Deleted user in {call}') . "\n{message}";
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
// TRANSLATORS Reminder for a message from a guest in conversation {call}
$subject = $l->t('Reminder: {guest} (guest) in {call}') . "\n{message}";
} catch (ParticipantNotFoundException $e) {
Expand All @@ -658,7 +658,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('Deleted user reacted with {reaction} in {call}') . "\n{message}";
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('{guest} (guest) reacted with {reaction} in {call}') . "\n{message}";
} catch (ParticipantNotFoundException $e) {
$subject = $l->t('Guest reacted with {reaction} in {call}') . "\n{message}";
Expand All @@ -673,7 +673,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('Deleted user in {call}') . "\n{message}";
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('{guest} (guest) in {call}') . "\n{message}";
} catch (ParticipantNotFoundException $e) {
$subject = $l->t('Guest in {call}') . "\n{message}";
Expand All @@ -689,7 +689,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('A deleted user sent a message in conversation {call}');
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('{guest} (guest) sent a message in conversation {call}');
} catch (ParticipantNotFoundException $e) {
$subject = $l->t('A guest sent a message in conversation {call}');
Expand All @@ -704,7 +704,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('A deleted user replied to your message in conversation {call}');
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('{guest} (guest) replied to your message in conversation {call}');
} catch (ParticipantNotFoundException $e) {
$subject = $l->t('A guest replied to your message in conversation {call}');
Expand All @@ -729,7 +729,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('Reminder: A deleted user in conversation {call}');
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('Reminder: {guest} (guest) in conversation {call}');
} catch (ParticipantNotFoundException) {
$subject = $l->t('Reminder: A guest in conversation {call}');
Expand All @@ -750,7 +750,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$subject = $l->t('A deleted user reacted with {reaction} to your message in conversation {call}');
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
$subject = $l->t('{guest} (guest) reacted with {reaction} to your message in conversation {call}');
} catch (ParticipantNotFoundException $e) {
$subject = $l->t('A guest reacted with {reaction} to your message in conversation {call}');
Expand Down Expand Up @@ -790,7 +790,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
}
} else {
try {
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorId());
$richSubjectParameters['guest'] = $this->getGuestParameter($room, $message->getActorType(), $message->getActorId());
if ($notification->getSubject() === 'mention_group') {
$groupName = $this->groupManager->getDisplayName($subjectParameters['sourceId']) ?? $subjectParameters['sourceId'];
$richSubjectParameters['group'] = [
Expand Down Expand Up @@ -864,12 +864,17 @@ protected function parseChatMessage(INotification $notification, Room $room, Par

/**
* @param Room $room
* @param Attendee::ACTOR_* $actorType
* @param string $actorId
* @return array
* @throws ParticipantNotFoundException
*/
protected function getGuestParameter(Room $room, string $actorId): array {
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_GUESTS, $actorId);
protected function getGuestParameter(Room $room, string $actorType, string $actorId): array {
if (!in_array($actorType, [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
throw new ParticipantNotFoundException('Not a guest actor type');
}

$participant = $this->participantService->getParticipantByActor($room, $actorType, $actorId);
$name = $participant->getAttendee()->getDisplayName();
if (trim($name) === '') {
throw new ParticipantNotFoundException('Empty name');
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/MessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected function commentToSearchResultEntry(Room $room, IUser $user, IComment
}

$displayName = $message->getActorDisplayName();
if ($message->getActorType() === Attendee::ACTOR_GUESTS) {
if (in_array($message->getActorType(), [Attendee::ACTOR_GUESTS, Attendee::ACTOR_EMAILS], true)) {
if ($displayName === '') {
$displayName = $this->l->t('Guest');
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/Signaling/BackendNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public function participantsModified(Room $room, array $sessionIds): void {
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== Attendee::ACTOR_USERS
&& $attendee->getActorType() !== Attendee::ACTOR_GUESTS
&& $attendee->getActorType() !== Attendee::ACTOR_EMAILS
&& $attendee->getActorType() !== Attendee::ACTOR_FEDERATED_USERS) {
continue;
}
Expand Down Expand Up @@ -418,6 +419,7 @@ public function roomInCallChanged(Room $room, int $flags, array $sessionIds, boo
$attendee = $participant->getAttendee();
if ($attendee->getActorType() !== Attendee::ACTOR_USERS
&& $attendee->getActorType() !== Attendee::ACTOR_GUESTS
&& $attendee->getActorType() !== Attendee::ACTOR_EMAILS
&& $attendee->getActorType() !== Attendee::ACTOR_FEDERATED_USERS) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Chat/SystemMessage/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function testAfterUsersAdd(int $roomType, string $objectType, array $part
public static function dataParticipantTypeChange(): array {
return [
[
Attendee::ACTOR_EMAILS,
Attendee::ACTOR_GROUPS,
Participant::USER,
Participant::MODERATOR,
[],
Expand Down
11 changes: 9 additions & 2 deletions tests/php/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,22 +921,26 @@ public function testPrepareChatMessage(string $subject, int $roomType, array $su
$comment->expects($this->any())
->method('getActorId')
->willReturn('random-hash');
$comment->expects($this->any())
->method('getActorType')
->willReturn(Attendee::ACTOR_GUESTS);
$this->commentsManager->expects($this->once())
->method('get')
->with('23')
->willReturn($comment);

if (is_string($guestName)) {
$participant2 = $this->createMock(Participant::class);
$this->participantService->method('getParticipantByActor')
->with($room, Attendee::ACTOR_GUESTS, 'random-hash')
->willReturn($participant);
->willReturn($participant2);

$attendee = Attendee::fromRow([
'actor_type' => 'guests',
'actor_id' => 'random-hash',
'display_name' => $guestName,
]);
$participant->method('getAttendee')
$participant2->method('getAttendee')
->willReturn($attendee);
} else {
$this->participantService->method('getParticipantByActor')
Expand Down Expand Up @@ -968,6 +972,9 @@ public function testPrepareChatMessage(string $subject, int $roomType, array $su
$chatMessage->expects($this->any())
->method('getActorId')
->willReturn('random-hash');
$chatMessage->expects($this->any())
->method('getActorType')
->willReturn(Attendee::ACTOR_GUESTS);

$this->messageParser->expects($this->once())
->method('createMessage')
Expand Down