From cc616c18b0a970ffa9cd245eba42902b944be5eb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 8 Oct 2024 10:13:29 +0200 Subject: [PATCH] feat(max-duration): Use a specific end message Signed-off-by: Joas Schilling --- lib/Chat/Parser/SystemMessage.php | 40 ++++++++++++++++----- tests/php/Chat/Parser/SystemMessageTest.php | 2 +- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 2499bbc2466..71204f19dab 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -1112,7 +1112,13 @@ protected function parseCall(Room $room, string $message, array $parameters, arr switch ($numUsers) { case 0: - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->n( + 'Call with %n guest was ended, as it reached the maximum call duration (Duration {duration})', + 'Call with %n guests was ended, as it reached the maximum call duration (Duration {duration})', + $parameters['guests'] + ); + } elseif ($message === 'call_ended') { $subject = $this->l->n( 'Call with %n guest ended (Duration {duration})', 'Call with %n guests ended (Duration {duration})', @@ -1127,7 +1133,9 @@ protected function parseCall(Room $room, string $message, array $parameters, arr } break; case 1: - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1} and {user2} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1} and {user2} ended (Duration {duration})'); } else { if ($parameters['guests'] === 0) { @@ -1140,13 +1148,17 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 2: if ($parameters['guests'] === 0) { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1} and {user2} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1} and {user2} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1} and {user2} (Duration {duration})'); } } else { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2} and {user3} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2} and {user3} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2} and {user3} (Duration {duration})'); @@ -1156,13 +1168,17 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 3: if ($parameters['guests'] === 0) { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2} and {user3} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2} and {user3} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2} and {user3} (Duration {duration})'); } } else { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2}, {user3} and {user4} (Duration {duration})'); @@ -1172,13 +1188,17 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 4: if ($parameters['guests'] === 0) { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2}, {user3} and {user4} (Duration {duration})'); } } else { - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration {duration})'); @@ -1188,7 +1208,9 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 5: default: - if ($message === 'call_ended' || $actorIsSystem) { + if ($actorIsSystem) { + $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} ended (Duration {duration})'); } else { $subject = $this->l->t('{actor} ended the call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration {duration})'); diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 24c58ddfee5..6885e335a3d 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -1534,7 +1534,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4'], 'guests' => 4, 'duration' => 42], ['type' => 'guest', 'id' => 'guest/system', 'name' => 'system'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and 4 guests ended (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and 4 guests was ended, as it reached the maximum call duration (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ],