From 5b1845e0e6d33557e7c81f1530c0b3aa739adb86 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Mon, 14 Oct 2024 14:51:24 +0200 Subject: [PATCH 1/2] fix: omit 'with 0 guests' in system messages when call ends Signed-off-by: Maksim Sukharev --- lib/Chat/Parser/SystemMessage.php | 54 ++++++++++++++------- tests/php/Chat/Parser/SystemMessageTest.php | 18 +++++++ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 71204f19dab..b046594836b 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -1113,30 +1113,50 @@ protected function parseCall(Room $room, string $message, array $parameters, arr switch ($numUsers) { case 0: 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'] - ); + if ($parameters['guests'] === 0) { + $subject = $this->l->t('Call was ended, as it reached the maximum call duration (Duration {duration})'); + } else { + $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})', - $parameters['guests'] - ); + if ($parameters['guests'] === 0) { + $subject = $this->l->t('Call ended (Duration {duration})'); + } else { + $subject = $this->l->n( + 'Call with %n guest ended (Duration {duration})', + 'Call with %n guests ended (Duration {duration})', + $parameters['guests'] + ); + } } else { - $subject = $this->l->n( - '{actor} ended the call with %n guest (Duration {duration})', - '{actor} ended the call with %n guests (Duration {duration})', - $parameters['guests'] - ); + if ($parameters['guests'] === 0) { + $subject = $this->l->t('{actor} ended the call (Duration {duration})'); + } else { + $subject = $this->l->n( + '{actor} ended the call with %n guest (Duration {duration})', + '{actor} ended the call with %n guests (Duration {duration})', + $parameters['guests'] + ); + } } break; case 1: if ($actorIsSystem) { - $subject = $this->l->t('Call with {user1} and {user2} was ended, as it reached the maximum call duration (Duration {duration})'); + if ($parameters['guests'] === 0) { + $subject = $this->l->t('Call with {user1} was ended, as it reached the maximum call duration (Duration {duration})'); + } else { + $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})'); + if ($parameters['guests'] === 0) { + $subject = $this->l->t('Call with {user1} ended (Duration {duration})'); + } else { + $subject = $this->l->t('Call with {user1} and {user2} ended (Duration {duration})'); + } } else { if ($parameters['guests'] === 0) { $subject = $this->l->t('{actor} ended the call with {user1} (Duration {duration})'); diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 6885e335a3d..ea5ef646ffa 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -1300,6 +1300,15 @@ public function testGetGuestNameThrows(): void { public static function dataParseCall(): array { return [ + '1 user' => [ + 'call_ended', + ['users' => ['user1'], 'guests' => 0, 'duration' => 42], + ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], + [ + 'Call with {user1} ended (Duration "duration")', + ['user1' => ['data' => 'user1']], + ], + ], '1 user + guests' => [ 'call_ended', ['users' => ['user1'], 'guests' => 3, 'duration' => 42], @@ -1419,6 +1428,15 @@ public static function dataParseCall(): array { ['user1' => ['data' => 'user2']], ], ], + 'meeting 1 user' => [ + 'call_ended_everyone', + ['users' => ['user1'], 'guests' => 0, 'duration' => 42], + ['type' => 'user', 'id' => 'user1', 'name' => 'user1'], + [ + '{actor} ended the call (Duration "duration")', + [], + ], + ], 'meeting 1 user + guests' => [ 'call_ended_everyone', ['users' => ['user1'], 'guests' => 3, 'duration' => 42], From 7defd0be694f233c0228ca321c160171495b61ac Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Oct 2024 16:58:13 +0200 Subject: [PATCH 2/2] fix(call): Structure the blocks same way as 2+ users Signed-off-by: Joas Schilling --- lib/Chat/Parser/SystemMessage.php | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index b046594836b..4d46806f1a9 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -1112,29 +1112,28 @@ protected function parseCall(Room $room, string $message, array $parameters, arr switch ($numUsers) { case 0: - if ($actorIsSystem) { - if ($parameters['guests'] === 0) { + if ($parameters['guests'] === 0) { + // Call without users and guests + if ($actorIsSystem) { $subject = $this->l->t('Call was ended, as it reached the maximum call duration (Duration {duration})'); + } elseif ($message === 'call_ended') { + $subject = $this->l->t('Call ended (Duration {duration})'); } else { + $subject = $this->l->t('{actor} ended the call (Duration {duration})'); + } + } else { + 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') { - if ($parameters['guests'] === 0) { - $subject = $this->l->t('Call ended (Duration {duration})'); - } else { + } elseif ($message === 'call_ended') { $subject = $this->l->n( 'Call with %n guest ended (Duration {duration})', 'Call with %n guests ended (Duration {duration})', $parameters['guests'] ); - } - } else { - if ($parameters['guests'] === 0) { - $subject = $this->l->t('{actor} ended the call (Duration {duration})'); } else { $subject = $this->l->n( '{actor} ended the call with %n guest (Duration {duration})', @@ -1145,26 +1144,24 @@ protected function parseCall(Room $room, string $message, array $parameters, arr } break; case 1: - if ($actorIsSystem) { - if ($parameters['guests'] === 0) { + if ($parameters['guests'] === 0) { + if ($actorIsSystem) { $subject = $this->l->t('Call with {user1} was ended, as it reached the maximum call duration (Duration {duration})'); - } else { - $subject = $this->l->t('Call with {user1} and {user2} was ended, as it reached the maximum call duration (Duration {duration})'); - } - } elseif ($message === 'call_ended') { - if ($parameters['guests'] === 0) { + } elseif ($message === 'call_ended') { $subject = $this->l->t('Call with {user1} ended (Duration {duration})'); } else { - $subject = $this->l->t('Call with {user1} and {user2} ended (Duration {duration})'); + $subject = $this->l->t('{actor} ended the call with {user1} (Duration {duration})'); } } else { - if ($parameters['guests'] === 0) { - $subject = $this->l->t('{actor} ended the call with {user1} (Duration {duration})'); + 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})'); } + $subject = str_replace('{user2}', $this->l->n('%n guest', '%n guests', $parameters['guests']), $subject); } - $subject = str_replace('{user2}', $this->l->n('%n guest', '%n guests', $parameters['guests']), $subject); break; case 2: if ($parameters['guests'] === 0) {