diff options
author | Joas Schilling <coding@schilljs.com> | 2024-05-10 16:06:37 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-05-13 11:57:08 +0200 |
commit | 1310b64ceba2391f5cea79134533284120d901c5 (patch) | |
tree | 4a41ff74ecb16ba6f30327d45c0a9616df1b6a9a | |
parent | 371852bf9c54762d34fa76d74de171d80102665f (diff) |
fix(polls): Remove actor info from system message
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 2 | ||||
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 14 | ||||
-rw-r--r-- | tests/integration/features/chat-2/poll.feature | 86 |
3 files changed, 94 insertions, 8 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index ddea3bd34..8d7ae3288 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -645,6 +645,8 @@ class SystemMessage implements IEventListener { $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, Attendee::ACTOR_ID_SYSTEM, ''); } else { throw new \OutOfBoundsException('Unknown subject'); } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 0fbe80097..a446c54a0 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2867,7 +2867,16 @@ class FeatureContext implements Context, SnippetAcceptingContext { 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:' . "\n" . json_encode($messages, JSON_PRETTY_PRINT)); Assert::assertEquals($expected, array_map(function ($message, $expected) { @@ -2888,6 +2897,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { if (isset($expected['messageParameters'])) { $data['messageParameters'] = json_encode($message['messageParameters']); + if ($expected['messageParameters'] === '"IGNORE"') { + $data['messageParameters'] = '"IGNORE"'; + } } if (isset($expected['silent'])) { diff --git a/tests/integration/features/chat-2/poll.feature b/tests/integration/features/chat-2/poll.feature index 7389cd568..e17749048 100644 --- a/tests/integration/features/chat-2/poll.feature +++ b/tests/integration/features/chat-2/poll.feature @@ -96,6 +96,12 @@ Feature: chat-2/poll | status | closed | | votedSelf | not voted | | details | [{"actorType":"users","actorId":"participant1","actorDisplayName":"participant1-displayname","optionId":1}] | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | poll_closed | You ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Participants can update their votes but only while open Given user "participant1" creates room "room" (v4) @@ -147,6 +153,12 @@ Feature: chat-2/poll | votedSelf | [1] | | details | [{"actorType":"users","actorId":"participant1","actorDisplayName":"participant1-displayname","optionId":1}] | Then user "participant1" votes for options "[0]" on poll "What is the question?" in room "room" with 400 + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | poll_closed | You ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Participants can only vote for valid options Given user "participant1" creates room "room" (v4) @@ -159,6 +171,9 @@ Feature: chat-2/poll | maxVotes | unlimited | Then user "participant1" votes for options "[-1]" on poll "What is the question?" in room "room" with 400 Then user "participant1" votes for options "[2]" on poll "What is the question?" in room "room" with 400 + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Participants can not exceed the maxVotes Given user "participant1" creates room "room" (v4) @@ -170,6 +185,9 @@ Feature: chat-2/poll | resultMode | public | | maxVotes | 1 | Then user "participant1" votes for options "[0,1]" on poll "What is the question?" in room "room" with 400 + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Participants can vote for multiple options Given user "participant1" creates room "room" (v4) @@ -193,6 +211,10 @@ Feature: chat-2/poll | actorDisplayName | participant1-displayname | | status | open | | votedSelf | [0,1] | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Participants can not vote for the same option multiple times Given user "participant1" creates room "room" (v4) @@ -204,6 +226,9 @@ Feature: chat-2/poll | resultMode | public | | maxVotes | unlimited | Then user "participant1" votes for options "[1,1]" on poll "What is the question?" in room "room" with 400 + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Non-moderators can also create polls and close it themselves Given user "participant1" creates room "room" (v4) @@ -232,6 +257,11 @@ Feature: chat-2/poll | status | closed | | votedSelf | not voted | | details | {} | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant2 | poll_closed | {actor} ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant2","name":"participant2-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Non-moderators can not create polls without chat permission Given user "participant1" creates room "room" (v4) @@ -270,6 +300,11 @@ Feature: chat-2/poll | status | closed | | votedSelf | not voted | | details | {} | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | poll_closed | You ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: There are system messages for opening, voting and closing on public polls Given user "participant1" creates room "room" (v4) @@ -322,17 +357,16 @@ Feature: chat-2/poll | votedSelf | [0] | | details | [{"actorType":"users","actorId":"participant1","actorDisplayName":"participant1-displayname","optionId":0},{"actorType":"users","actorId":"participant2","actorDisplayName":"participant2-displayname","optionId":1}] | Then user "participant1" sees the following system messages in room "room" with 200 (v1) - | room | actorType | actorId | actorDisplayName | systemMessage | - | room | users | participant1 | participant1-displayname | poll_closed | - | room | users | participant2 | participant2-displayname | poll_voted | - | room | users | participant1 | participant1-displayname | poll_voted | - | room | users | participant1 | participant1-displayname | user_added | - | room | users | participant1 | participant1-displayname | conversation_created | + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | poll_closed | You ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Then user "participant1" sees the following messages in room "room" with 200 (v1) | room | actorType | actorId | actorDisplayName | message | messageParameters | | room | users | participant1 | participant1-displayname | {object} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"object":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | - Scenario: There are only system messages for opening and closing on hidden polls Given user "participant1" creates room "room" (v4) | roomType | 2 | @@ -469,6 +503,11 @@ Feature: chat-2/poll | actorDisplayName | participant1-displayname | | status | closed | | votedSelf | not voted | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | poll_closed | You ended the poll {poll} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Number of voters and votes are restricted to the very same poll Given user "participant1" creates room "room" (v4) @@ -524,6 +563,12 @@ Feature: chat-2/poll | actorDisplayName | participant2-displayname | | status | open | | votedSelf | [1] | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(Another one ...),"name":"Another one ..."}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Remove all votes Given user "participant1" creates room "room" (v4) @@ -574,6 +619,12 @@ Feature: chat-2/poll | actorDisplayName | participant1-displayname | | status | open | | votedSelf | [] | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Empty question and options Given user "participant1" creates room "room" (v4) @@ -652,6 +703,13 @@ Feature: chat-2/poll | status | closed | | votedSelf | [] | | details | [{"actorType":"deleted_users","actorId":"deleted_users","actorDisplayName":"","optionId":0}] | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | admin | user_removed | {actor} removed {user} | !ISSET | "IGNORE" | + | room | deleted_users | deleted_users | poll_closed | {actor} ended the poll {poll} | !ISSET | {"actor":{"type":"highlight","id":"deleted_users","name":"Deleted user"},"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | guests | system | poll_voted | Someone voted on the poll {poll} | !ISSET | {"poll":{"type":"talk-poll","id":POLL_ID(What is the question?),"name":"What is the question?"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"highlight","id":"deleted_users","name":"Deleted user"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Deleting the poll message removes all details Given user "participant1" creates room "room" (v4) @@ -676,6 +734,11 @@ Feature: chat-2/poll And user "participant1" sees the following messages in room "room" with 200 (v1) | room | actorType | actorId | actorDisplayName | message | messageParameters | | room | users | participant2 | participant2-displayname | Message deleted by you | "IGNORE" | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | message_deleted | You deleted a message | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Deleting a closed poll message removes also the close message Given user "participant1" creates room "room" (v4) @@ -715,6 +778,12 @@ Feature: chat-2/poll | room | actorType | actorId | actorDisplayName | message | messageParameters | | room | users | participant2 | participant2-displayname | Message deleted by you | "IGNORE" | | room | users | participant2 | participant2-displayname | Message deleted by you | "IGNORE" | + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | message_deleted | You deleted a message | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant1 | message_deleted | You deleted a message | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + | room | users | participant1 | user_added | You added {user} | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} | + | room | users | participant1 | conversation_created | You created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | Scenario: Deleting the chat history also deletes polls Given user "participant1" creates room "room" (v4) @@ -733,3 +802,6 @@ Feature: chat-2/poll Then user "participant1" sees poll "What is the question?" in room "room" with 404 Then user "participant2" sees poll "What is the question?" in room "room" with 404 And user "participant1" sees the following messages in room "room" with 200 (v1) + Then user "participant1" sees the following system messages in room "room" with 200 (v1) + | room | actorType | actorId | systemMessage | message | silent | messageParameters | + | room | users | participant1 | history_cleared | You cleared the history of the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | |