Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(calls): End calls without falling back to a user when killing via… #13464

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 21 additions & 20 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']--;
}
}
Expand All @@ -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 {
Expand All @@ -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})');
Expand All @@ -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})');
}
Expand All @@ -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})');
}
Expand All @@ -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})');
}
Expand All @@ -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})');
}
Expand Down
33 changes: 22 additions & 11 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand All @@ -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']],
],
],
Expand Down Expand Up @@ -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']],
],
],
];
}

Expand Down
Loading