diff --git a/lib/Controller/PublicViewController.php b/lib/Controller/PublicViewController.php index d40cd9b2e..fed0b5d32 100644 --- a/lib/Controller/PublicViewController.php +++ b/lib/Controller/PublicViewController.php @@ -139,6 +139,7 @@ class PublicViewController extends Controller { $this->initialStateService->provideInitialState($this->appName, 'show_week_numbers', ($defaultWeekNumbers === 'yes')); $this->initialStateService->provideInitialState($this->appName, 'skip_popover', ($defaultSkipPopover === 'yes')); $this->initialStateService->provideInitialState($this->appName, 'talk_enabled', false); + $this->initialStateService->provideInitialState($this->appName, 'talk_api_version', 'v1'); $this->initialStateService->provideInitialState($this->appName, 'timezone', $defaultTimezone); $this->initialStateService->provideInitialState($this->appName, 'slot_duration', $defaultSlotDuration); $this->initialStateService->provideInitialState($this->appName, 'default_reminder', $defaultDefaultReminder); diff --git a/lib/Controller/ViewController.php b/lib/Controller/ViewController.php index c7be99155..affb65bb4 100644 --- a/lib/Controller/ViewController.php +++ b/lib/Controller/ViewController.php @@ -110,6 +110,7 @@ class ViewController extends Controller { $showTasks = $this->config->getUserValue($this->userId, $this->appName, 'showTasks', $defaultShowTasks) === 'yes'; $talkEnabled = $this->appManager->isEnabledForUser('spreed'); + $talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1'; $tasksEnabled = $this->appManager->isEnabledForUser('tasks'); $this->initialStateService->provideInitialState($this->appName, 'app_version', $appVersion); @@ -120,6 +121,7 @@ class ViewController extends Controller { $this->initialStateService->provideInitialState($this->appName, 'show_week_numbers', $showWeekNumbers); $this->initialStateService->provideInitialState($this->appName, 'skip_popover', $skipPopover); $this->initialStateService->provideInitialState($this->appName, 'talk_enabled', $talkEnabled); + $this->initialStateService->provideInitialState($this->appName, 'talk_api_version', $talkApiVersion); $this->initialStateService->provideInitialState($this->appName, 'timezone', $timezone); $this->initialStateService->provideInitialState($this->appName, 'slot_duration', $slotDuration); $this->initialStateService->provideInitialState($this->appName, 'default_reminder', $defaultReminder); diff --git a/src/services/talkService.js b/src/services/talkService.js index a35cb9521..4bd2c4de4 100644 --- a/src/services/talkService.js +++ b/src/services/talkService.js @@ -23,6 +23,7 @@ import HTTPClient from '@nextcloud/axios' import { translate as t } from '@nextcloud/l10n' import { generateUrl, generateOcsUrl } from '@nextcloud/router' +import { loadState } from '@nextcloud/initial-state' /** * Creates a new public talk room @@ -31,9 +32,10 @@ import { generateUrl, generateOcsUrl } from '@nextcloud/router' * @returns {Promise} */ export async function createTalkRoom(eventTitle = null) { + const apiVersion = loadState('calendar', 'talk_api_version') let response try { - response = await HTTPClient.post(generateOcsUrl('apps/spreed/api/v1/', 2) + 'room', { + response = await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room', { roomType: 3, roomName: eventTitle || t('calendar', 'Chat room for event'), }) diff --git a/tests/php/unit/Controller/PublicViewControllerTest.php b/tests/php/unit/Controller/PublicViewControllerTest.php index 17dd2b502..4245a331c 100644 --- a/tests/php/unit/Controller/PublicViewControllerTest.php +++ b/tests/php/unit/Controller/PublicViewControllerTest.php @@ -101,7 +101,7 @@ class PublicViewControllerTest extends TestCase { ->with('imagePath456') ->willReturn('absoluteImagePath456'); - $this->initialStateService->expects(self::exactly(13)) + $this->initialStateService ->method('provideInitialState') ->withConsecutive( ['calendar', 'app_version', '1.0.0'], @@ -112,6 +112,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'show_week_numbers', true], ['calendar', 'skip_popover', true], ['calendar', 'talk_enabled', false], + ['calendar', 'talk_api_version', 'v1'], ['calendar', 'timezone', 'defaultTimezone'], ['calendar', 'slot_duration', 'defaultSlotDuration'], ['calendar', 'default_reminder', 'defaultDefaultReminder'], @@ -177,7 +178,7 @@ class PublicViewControllerTest extends TestCase { ->with('imagePath456') ->willReturn('absoluteImagePath456'); - $this->initialStateService->expects(self::exactly(13)) + $this->initialStateService ->method('provideInitialState') ->withConsecutive( ['calendar', 'app_version', '1.0.0'], @@ -188,6 +189,7 @@ class PublicViewControllerTest extends TestCase { ['calendar', 'show_week_numbers', true], ['calendar', 'skip_popover', true], ['calendar', 'talk_enabled', false], + ['calendar', 'talk_api_version', 'v1'], ['calendar', 'timezone', 'defaultTimezone'], ['calendar', 'slot_duration', 'defaultSlotDuration'], ['calendar', 'default_reminder', 'defaultDefaultReminder'], diff --git a/tests/php/unit/Controller/ViewControllerTest.php b/tests/php/unit/Controller/ViewControllerTest.php index 10ea3fcdf..09cdc70fb 100755 --- a/tests/php/unit/Controller/ViewControllerTest.php +++ b/tests/php/unit/Controller/ViewControllerTest.php @@ -102,6 +102,11 @@ class ViewControllerTest extends TestCase { ['spreed', null, true], ['tasks', null, true] ]); + $this->appManager + ->method('getAppVersion') + ->willReturnMap([ + ['spreed', true, '12.0.0'], + ]); $this->initialStateService ->method('provideInitialState') @@ -114,6 +119,7 @@ class ViewControllerTest extends TestCase { ['calendar', 'show_week_numbers', true], ['calendar', 'skip_popover', true], ['calendar', 'talk_enabled', true], + ['calendar', 'talk_api_version', 'v4'], ['calendar', 'timezone', 'Europe/Berlin'], ['calendar', 'slot_duration', '00:15:00'], ['calendar', 'default_reminder', '00:10:00'], @@ -167,9 +173,14 @@ class ViewControllerTest extends TestCase { $this->appManager ->method('isEnabledForUser') ->willReturnMap([ - ['spreed', null, true], + ['spreed', null, false], ['tasks', null, false] ]); + $this->appManager + ->method('getAppVersion') + ->willReturnMap([ + ['spreed', true, '11.3.0'], + ]); $this->initialStateService ->method('provideInitialState') @@ -181,7 +192,8 @@ class ViewControllerTest extends TestCase { ['calendar', 'show_weekends', true], ['calendar', 'show_week_numbers', true], ['calendar', 'skip_popover', true], - ['calendar', 'talk_enabled', true], + ['calendar', 'talk_enabled', false], + ['calendar', 'talk_api_version', 'v1'], ['calendar', 'timezone', 'Europe/Berlin'], ['calendar', 'slot_duration', '00:15:00'], ['calendar', 'default_reminder', '00:10:00'],