From 98ce1e30f72d179ae40240b9795c8adffcff6dfb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 29 Feb 2024 18:09:52 +0100 Subject: [PATCH 1/2] fix(federation): Fix parsing of some system messages for federated users Signed-off-by: Joas Schilling --- lib/Chat/Parser/SystemMessage.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 03faf1658e3..3f57f0ebc64 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -138,6 +138,7 @@ protected function parseMessage(Message $chatMessage): void { $participant = $chatMessage->getParticipant(); if ($participant === null) { + $currentActorType = null; $currentActorId = null; $currentUserIsActor = false; } elseif ($this->federationAuthenticator->isFederationRequest()) { @@ -149,16 +150,20 @@ protected function parseMessage(Message $chatMessage): void { ]; } + $currentActorType = $participant->getAttendee()->getActorType(); + $currentActorId = $participant->getAttendee()->getActorId(); $currentUserIsActor = isset($parsedParameters['actor']['server']) && $parsedParameters['actor']['type'] === 'user' && $this->currentFederatedUserDetails['user'] === $parsedParameters['actor']['id'] && $this->currentFederatedUserDetails['server'] === $parsedParameters['actor']['server']; } elseif (!$participant->isGuest()) { + $currentActorType = $participant->getAttendee()->getActorType(); $currentActorId = $participant->getAttendee()->getActorId(); $currentUserIsActor = $parsedParameters['actor']['type'] === 'user' && $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS && $currentActorId === $parsedParameters['actor']['id']; } else { + $currentActorType = $participant->getAttendee()->getActorType(); $currentActorId = $participant->getAttendee()->getActorId(); $currentUserIsActor = $parsedParameters['actor']['type'] === 'guest' && $participant->getAttendee()->getActorType() === 'guest' && @@ -227,7 +232,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('You left the call'); } } elseif ($message === 'call_missed') { - [$parsedMessage, $parsedParameters, $message] = $this->parseMissedCall($room, $parameters, $currentActorId); + [$parsedMessage, $parsedParameters, $message] = $this->parseMissedCall($room, $parameters, $currentActorType === Attendee::ACTOR_FEDERATED_USERS ? null : $currentActorId); } elseif ($message === 'call_ended' || $message === 'call_ended_everyone') { [$parsedMessage, $parsedParameters] = $this->parseCall($message, $parameters, $parsedParameters); } elseif ($message === 'read_only_off') { @@ -326,7 +331,7 @@ protected function parseMessage(Message $chatMessage): void { } } elseif ($currentUserIsActor) { $parsedMessage = $this->l->t('You added {user}'); - } elseif ($participant && !$participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} added you'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator added you'); @@ -346,7 +351,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('{actor} removed {user}'); if ($currentUserIsActor) { $parsedMessage = $this->l->t('You removed {user}'); - } elseif ($participant && !$participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} removed you'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator removed you'); @@ -431,7 +436,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('{actor} promoted {user} to moderator'); if ($currentUserIsActor) { $parsedMessage = $this->l->t('You promoted {user} to moderator'); - } elseif ($participant && !$participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} promoted you to moderator'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator promoted you to moderator'); @@ -444,7 +449,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('{actor} demoted {user} from moderator'); if ($currentUserIsActor) { $parsedMessage = $this->l->t('You demoted {user} from moderator'); - } elseif ($participant && !$participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} demoted you from moderator'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator demoted you from moderator'); @@ -457,7 +462,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('{actor} promoted {user} to moderator'); if ($currentUserIsActor) { $parsedMessage = $this->l->t('You promoted {user} to moderator'); - } elseif ($participant && $participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} promoted you to moderator'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator promoted you to moderator'); @@ -470,7 +475,7 @@ protected function parseMessage(Message $chatMessage): void { $parsedMessage = $this->l->t('{actor} demoted {user} from moderator'); if ($currentUserIsActor) { $parsedMessage = $this->l->t('You demoted {user} from moderator'); - } elseif ($participant && $participant->isGuest() && $currentActorId === $parsedParameters['user']['id']) { + } elseif ($this->isCurrentParticipantChangedUser($currentActorType, $currentActorId, $parsedParameters['user'])) { $parsedMessage = $this->l->t('{actor} demoted you from moderator'); if ($cliIsActor) { $parsedMessage = $this->l->t('An administrator demoted you from moderator'); @@ -819,6 +824,15 @@ protected function getFileFromShare(?Participant $participant, string $shareId): return $data; } + protected function isCurrentParticipantChangedUser(?string $currentActorType, ?string $currentActorId, array $parameter): bool { + if (isset($parameter['server']) && $currentActorType === Attendee::ACTOR_FEDERATED_USERS) { + return $this->currentFederatedUserDetails['user'] === $parameter['id'] + && $this->currentFederatedUserDetails['server'] === $parameter['server']; + } + + return $currentActorType === Attendee::ACTOR_USERS && $currentActorId === $parameter['id']; + } + protected function getActorFromComment(Room $room, IComment $comment): array { return $this->getActor($room, $comment->getActorType(), $comment->getActorId()); } From ce6b67d9214f21c55119f434887ff06c3685b827 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 29 Feb 2024 18:43:24 +0100 Subject: [PATCH 2/2] fix(federation): Translate the token for the iOS app Signed-off-by: Joas Schilling --- lib/Federation/Proxy/TalkV1/UserConverter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Federation/Proxy/TalkV1/UserConverter.php b/lib/Federation/Proxy/TalkV1/UserConverter.php index 7ae2ff7e299..392380d39ba 100644 --- a/lib/Federation/Proxy/TalkV1/UserConverter.php +++ b/lib/Federation/Proxy/TalkV1/UserConverter.php @@ -106,6 +106,8 @@ public function convertMessage(Room $room, array $message): array { $message = $this->convertAttendee($room, $message, 'actorType', 'actorId', 'actorDisplayName'); $message = $this->convertAttendee($room, $message, 'lastEditActorType', 'lastEditActorId', 'lastEditActorDisplayName'); $message = $this->convertMessageParameters($room, $message); + $message['token'] = $room->getToken(); + if (isset($message['parent'])) { $message['parent'] = $this->convertMessage($room, $message['parent']); }