Skip to content

Commit

Permalink
Merge pull request #13545 from nextcloud/feat/noid/end-call-0-guests
Browse files Browse the repository at this point in the history
fix: omit 'with 0 guests' in system messages when call ends
  • Loading branch information
nickvergessen authored Oct 14, 2024
2 parents 24ebe11 + 7defd0b commit 2fa9f94
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
65 changes: 41 additions & 24 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,39 +1112,56 @@ 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']
);
} 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) {
// 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 {
$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 ($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})',
$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']
);
}
}
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})');
} elseif ($message === 'call_ended') {
$subject = $this->l->t('Call with {user1} and {user2} ended (Duration {duration})');
} else {
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})');
} elseif ($message === 'call_ended') {
$subject = $this->l->t('Call with {user1} ended (Duration {duration})');
} else {
$subject = $this->l->t('{actor} ended the call with {user1} (Duration {duration})');
}
} else {
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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 2fa9f94

Please sign in to comment.