Skip to content

Commit

Permalink
Merge pull request #14030 from nextcloud/bugfix/noid/fix-incorrect-ma…
Browse files Browse the repository at this point in the history
…x-duration-on-reload

fix(call): Fix call summary when the connection was interrupted
  • Loading branch information
nickvergessen authored Dec 19, 2024
2 parents 77842ae + 71a0fe0 commit 494ec1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 16 additions & 11 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Share\Helper\FilesMetadataCache;
use OCA\Talk\Share\RoomShareProvider;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\Event;
Expand Down Expand Up @@ -67,6 +68,7 @@ class SystemMessage implements IEventListener {
protected array $currentFederatedUserDetails = [];

public function __construct(
protected IAppConfig $appConfig,
protected IUserManager $userManager,
protected IGroupManager $groupManager,
protected GuestManager $guestManager,
Expand Down Expand Up @@ -1108,6 +1110,9 @@ 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;
$maxDuration = $this->appConfig->getAppValueInt('max_call_duration');
$maxDurationWasReached = $message === 'call_ended_everyone' && $actorIsSystem && $maxDuration > 0 && $parameters['duration'] > $maxDuration;

if ($message === 'call_ended_everyone') {
if ($params['actor']['type'] === 'user') {
$entry = array_keys($parameters['users'], $params['actor']['id'], true);
Expand All @@ -1133,15 +1138,15 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
case 0:
if ($parameters['guests'] === 0) {
// Call without users and guests
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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) {
if ($maxDurationWasReached) {
$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})',
Expand All @@ -1164,15 +1169,15 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
break;
case 1:
if ($parameters['guests'] === 0) {
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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) {
if ($maxDurationWasReached) {
$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})');
Expand All @@ -1184,15 +1189,15 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
break;
case 2:
if ($parameters['guests'] === 0) {
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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 ($actorIsSystem) {
if ($maxDurationWasReached) {
$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})');
Expand All @@ -1204,15 +1209,15 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
break;
case 3:
if ($parameters['guests'] === 0) {
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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 ($actorIsSystem) {
if ($maxDurationWasReached) {
$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})');
Expand All @@ -1224,15 +1229,15 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
break;
case 4:
if ($parameters['guests'] === 0) {
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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 ($actorIsSystem) {
if ($maxDurationWasReached) {
$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})');
Expand All @@ -1244,7 +1249,7 @@ protected function parseCall(Room $room, string $message, array $parameters, arr
break;
case 5:
default:
if ($actorIsSystem) {
if ($maxDurationWasReached) {
$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})');
Expand Down
13 changes: 11 additions & 2 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Share\Helper\FilesMetadataCache;
use OCA\Talk\Share\RoomShareProvider;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Comments\IComment;
use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
Expand All @@ -45,6 +46,7 @@
* @group DB
*/
class SystemMessageTest extends TestCase {
protected IAppConfig&MockObject $appConfig;
protected IUserManager&MockObject $userManager;
protected IGroupManager&MockObject $groupManager;
protected GuestManager&MockObject $guestManager;
Expand All @@ -62,6 +64,7 @@ class SystemMessageTest extends TestCase {
public function setUp(): void {
parent::setUp();

$this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->guestManager = $this->createMock(GuestManager::class);
Expand Down Expand Up @@ -94,6 +97,7 @@ protected function getParser(array $methods = []): SystemMessage {
if (!empty($methods)) {
$mock = $this->getMockBuilder(SystemMessage::class)
->setConstructorArgs([
$this->appConfig,
$this->userManager,
$this->groupManager,
$this->guestManager,
Expand All @@ -113,6 +117,7 @@ protected function getParser(array $methods = []): SystemMessage {
return $mock;
}
return new SystemMessage(
$this->appConfig,
$this->userManager,
$this->groupManager,
$this->guestManager,
Expand Down Expand Up @@ -1549,7 +1554,7 @@ public static function dataParseCall(): array {
// 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],
['users' => ['user1', 'user2', 'user3', 'user4'], 'guests' => 4, 'duration' => 90],
['type' => 'guest', 'id' => 'guest/system', 'name' => 'system'],
[
'Call with {user1}, {user2}, {user3}, {user4} and 4 guests was ended, as it reached the maximum call duration (Duration "duration")',
Expand All @@ -1567,9 +1572,13 @@ public function testParseCall(string $message, array $parameters, array $actor,
$parser = $this->getParser(['getDuration', 'getUser']);
$parser->expects($this->once())
->method('getDuration')
->with(42)
->with($parameters['duration'])
->willReturn('"duration"');

$this->appConfig->method('getAppValueInt')
->with('max_call_duration')
->willReturn(60);

$parser->expects($this->any())
->method('getUser')
->willReturnCallback(function ($user) {
Expand Down

0 comments on commit 494ec1c

Please sign in to comment.