From a47189e1c2b4efd332d61c54434fcbc72849a540 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Oct 2024 17:39:42 +0200 Subject: [PATCH] fix(calls): End calls without falling back to a user when killing via background job Signed-off-by: Joas Schilling --- lib/Activity/Listener.php | 4 +- lib/Chat/Parser/SystemMessage.php | 41 +++++++++++---------- tests/php/Chat/Parser/SystemMessageTest.php | 33 +++++++++++------ 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index d6bbfcead98..ada80a15ff8 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -82,8 +82,8 @@ protected function generateCallActivity(ACallEndedEvent $event): void { $actorId = $actor->getAttendee()->getActorId(); $actorType = $actor->getAttendee()->getActorType(); } else { - $actorId = $userIds[0] ?? 'guests-only'; - $actorType = $actorId !== 'guests-only' ? Attendee::ACTOR_USERS : Attendee::ACTOR_GUESTS; + $actorType = Attendee::ACTOR_GUESTS; + $actorId = Attendee::ACTOR_ID_SYSTEM; } $this->chatManager->addSystemMessage($room, $actorType, $actorId, json_encode([ 'message' => $message, diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index adf3616cff1..2499bbc2466 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -1088,13 +1088,14 @@ protected function parseMissedCall(Room $room, array $parameters, ?string $curre protected function parseCall(Room $room, string $message, array $parameters, array $params): array { + $actorIsSystem = $params['actor']['type'] === 'guest' && $params['actor']['id'] === 'guest/' . Attendee::ACTOR_ID_SYSTEM; if ($message === 'call_ended_everyone') { if ($params['actor']['type'] === 'user') { $entry = array_keys($parameters['users'], $params['actor']['id'], true); foreach ($entry as $i) { unset($parameters['users'][$i]); } - } else { + } elseif (!$actorIsSystem) { $parameters['guests']--; } } @@ -1111,10 +1112,10 @@ protected function parseCall(Room $room, string $message, array $parameters, arr switch ($numUsers) { case 0: - if ($message === 'call_ended') { + if ($message === 'call_ended' || $actorIsSystem) { $subject = $this->l->n( - 'Call with %n guest (Duration {duration})', - 'Call with %n guests (Duration {duration})', + 'Call with %n guest ended (Duration {duration})', + 'Call with %n guests ended (Duration {duration})', $parameters['guests'] ); } else { @@ -1126,8 +1127,8 @@ protected function parseCall(Room $room, string $message, array $parameters, arr } break; case 1: - if ($message === 'call_ended') { - $subject = $this->l->t('Call with {user1} and {user2} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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})'); @@ -1139,14 +1140,14 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 2: if ($parameters['guests'] === 0) { - if ($message === 'call_ended') { - $subject = $this->l->t('Call with {user1} and {user2} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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') { - $subject = $this->l->t('Call with {user1}, {user2} and {user3} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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})'); } @@ -1155,14 +1156,14 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 3: if ($parameters['guests'] === 0) { - if ($message === 'call_ended') { - $subject = $this->l->t('Call with {user1}, {user2} and {user3} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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') { - $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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})'); } @@ -1171,14 +1172,14 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 4: if ($parameters['guests'] === 0) { - if ($message === 'call_ended') { - $subject = $this->l->t('Call with {user1}, {user2}, {user3} and {user4} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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') { - $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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})'); } @@ -1187,8 +1188,8 @@ protected function parseCall(Room $room, string $message, array $parameters, arr break; case 5: default: - if ($message === 'call_ended') { - $subject = $this->l->t('Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration {duration})'); + if ($message === 'call_ended' || $actorIsSystem) { + $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 57797c64e6a..24c58ddfee5 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -1305,7 +1305,7 @@ public static function dataParseCall(): array { ['users' => ['user1'], 'guests' => 3, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1} and 3 guests (Duration "duration")', + 'Call with {user1} and 3 guests ended (Duration "duration")', ['user1' => ['data' => 'user1']], ], ], @@ -1314,7 +1314,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2'], 'guests' => 0, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1} and {user2} (Duration "duration")', + 'Call with {user1} and {user2} ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2']], ], ], @@ -1323,7 +1323,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2'], 'guests' => 1, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2} and 1 guest (Duration "duration")', + 'Call with {user1}, {user2} and 1 guest ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2']], ], ], @@ -1332,7 +1332,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3'], 'guests' => 0, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2} and {user3} (Duration "duration")', + 'Call with {user1}, {user2} and {user3} ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3']], ], ], @@ -1341,7 +1341,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3'], 'guests' => 22, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3} and 22 guests (Duration "duration")', + 'Call with {user1}, {user2}, {user3} and 22 guests ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3']], ], ], @@ -1350,7 +1350,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4'], 'guests' => 0, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3} and {user4} (Duration "duration")', + 'Call with {user1}, {user2}, {user3} and {user4} ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ], @@ -1359,7 +1359,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4'], 'guests' => 4, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and 4 guests (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and 4 guests ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ], @@ -1368,7 +1368,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4', 'user5'], 'guests' => 0, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and {user5} ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4'], 'user5' => ['data' => 'user5']], ], ], @@ -1377,7 +1377,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4', 'user5'], 'guests' => 1, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and 2 others (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and 2 others ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ], @@ -1386,7 +1386,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4', 'user5', 'user6'], 'guests' => 0, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and 2 others (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and 2 others ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ], @@ -1395,7 +1395,7 @@ public static function dataParseCall(): array { ['users' => ['user1', 'user2', 'user3', 'user4', 'user5', 'user6'], 'guests' => 2, 'duration' => 42], ['type' => 'user', 'id' => 'admin', 'name' => 'Admin'], [ - 'Call with {user1}, {user2}, {user3}, {user4} and 4 others (Duration "duration")', + 'Call with {user1}, {user2}, {user3}, {user4} and 4 others ended (Duration "duration")', ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], ], ], @@ -1527,6 +1527,17 @@ public static function dataParseCall(): array { ['user1' => ['data' => '234'], 'user2' => ['data' => '345'], 'user3' => ['data' => '456'], 'user4' => ['data' => '576']], ], ], + + // Automatically ended by background job (max_call_duration reached) + 'max_call_duration cleanup' => [ + 'call_ended_everyone', + ['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")', + ['user1' => ['data' => 'user1'], 'user2' => ['data' => 'user2'], 'user3' => ['data' => 'user3'], 'user4' => ['data' => 'user4']], + ], + ], ]; }