Skip to content

Commit

Permalink
Merge pull request #11688 from nextcloud/bugfix/noid/fix-parsing-syst…
Browse files Browse the repository at this point in the history
…em-messages-for-federated-users

fix(federation): Fix parsing system messages for federated users
  • Loading branch information
nickvergessen authored Feb 29, 2024
2 parents 10e6562 + ce6b67d commit a91b44b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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' &&
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Federation/Proxy/TalkV1/UserConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down

0 comments on commit a91b44b

Please sign in to comment.