Skip to content

Commit

Permalink
Merge pull request #12342 from nextcloud/backport/12341/stable27
Browse files Browse the repository at this point in the history
[stable27] fix(polls): Remove actor info from system message
  • Loading branch information
nickvergessen authored May 16, 2024
2 parents cfd55b9 + 5d6a666 commit d70e2cb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ public function parseMessage(Message $chatMessage): void {
$parsedParameters['poll']['id'] = (string) $parsedParameters['poll']['id'];
$parsedMessage = $this->l->t('Someone voted on the poll {poll}');
unset($parsedParameters['actor']);

$chatMessage->setActor(Attendee::ACTOR_GUESTS, 'system', '');
} else {
throw new \OutOfBoundsException('Unknown subject');
}
Expand Down
16 changes: 14 additions & 2 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2490,14 +2490,23 @@ public function userSeesTheFollowingSystemMessagesInRoom($user, $identifier, $st
return;
}

$expected = $formData->getHash();
$expected = array_map(static function (array $message) {
if (isset($message['messageParameters'])) {
$result = preg_match('/POLL_ID\(([^)]+)\)/', $message['messageParameters'], $matches);
if ($result) {
$message['messageParameters'] = str_replace($matches[0], '"' . self::$questionToPollId[$matches[1]] . '"', $message['messageParameters']);
}
}
return $message;
}, $formData->getHash());


Assert::assertCount(count($expected), $messages, 'Message count does not match');
Assert::assertEquals($expected, array_map(function ($message, $expected) {
$data = [
'room' => self::$tokenToIdentifier[$message['token']],
'actorType' => (string) $message['actorType'],
'actorId' => ($message['actorType'] === 'guests') ? self::$sessionIdToUser[$message['actorId']] : (string) $message['actorId'],
'actorId' => ($message['actorType'] === 'guests' && $message['actorId'] !== 'system') ? self::$sessionIdToUser[$message['actorId']] : (string) $message['actorId'],
'systemMessage' => (string) $message['systemMessage'],
];

Expand All @@ -2511,6 +2520,9 @@ public function userSeesTheFollowingSystemMessagesInRoom($user, $identifier, $st

if (isset($expected['messageParameters'])) {
$data['messageParameters'] = json_encode($message['messageParameters']);
if ($expected['messageParameters'] === '"IGNORE"') {
$data['messageParameters'] = '"IGNORE"';
}
}

return $data;
Expand Down
Loading

0 comments on commit d70e2cb

Please sign in to comment.