Skip to content

Commit

Permalink
fix(federation): Fix parsing of some system messages for federated users
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 29, 2024
1 parent 10e6562 commit 98ce1e3
Showing 1 changed file with 21 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

0 comments on commit 98ce1e3

Please sign in to comment.