diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 1907006ccd..aa240e9bf6 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -205,19 +205,19 @@ public function index(): TemplateResponse { ); $user = $this->userSession->getUser(); - $response = new TemplateResponse($this->appName, 'index', - [ - 'attachment-size-limit' => $this->config->getSystemValue('app.mail.attachment-size-limit', 0), - 'app-version' => $this->config->getAppValue('mail', 'installed_version'), - 'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'), - 'layout-mode' => $this->preferences->getPreference($this->currentUserId, 'layout-mode', 'vertical-split'), - 'reply-mode' => $this->preferences->getPreference($this->currentUserId, 'reply-mode', 'top'), - 'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'), - 'search-priority-body' => $this->preferences->getPreference($this->currentUserId, 'search-priority-body', 'false'), - 'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'), - 'tag-classified-messages' => $this->classificationSettingsService->isClassificationEnabled($this->currentUserId) ? 'true' : 'false', - 'follow-up-reminders' => $this->preferences->getPreference($this->currentUserId, 'follow-up-reminders', 'true'), - ]); + $response = new TemplateResponse($this->appName, 'index'); + $this->initialStateService->provideInitialState('preferences', [ + 'attachment-size-limit' => $this->config->getSystemValue('app.mail.attachment-size-limit', 0), + 'app-version' => $this->config->getAppValue('mail', 'installed_version'), + 'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'), + 'layout-mode' => $this->preferences->getPreference($this->currentUserId, 'layout-mode', 'vertical-split'), + 'reply-mode' => $this->preferences->getPreference($this->currentUserId, 'reply-mode', 'top'), + 'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'), + 'search-priority-body' => $this->preferences->getPreference($this->currentUserId, 'search-priority-body', 'false'), + 'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'), + 'tag-classified-messages' => $this->classificationSettingsService->isClassificationEnabled($this->currentUserId) ? 'true' : 'false', + 'follow-up-reminders' => $this->preferences->getPreference($this->currentUserId, 'follow-up-reminders', 'true'), + ]); $this->initialStateService->provideInitialState( 'prefill_displayName', $this->userManager->getDisplayName($this->currentUserId), diff --git a/src/init.js b/src/init.js index af4c0cd21a..5f31bf26ce 100644 --- a/src/init.js +++ b/src/init.js @@ -9,18 +9,12 @@ import { fetchAvailableLanguages } from './service/translationService.js' import useOutboxStore from './store/outboxStore.js' import useMainStore from './store/mainStore.js' -const getPreferenceFromPage = (key) => { - const elem = document.getElementById(key) - if (!elem) { - return - } - return elem.value -} - export default function initAfterAppCreation() { console.debug('Init after app creation') const mainStore = useMainStore() + const preferences = loadState('mail', 'preferences', []) + mainStore.savePreferenceMutation({ key: 'debug', value: loadState('mail', 'debug', false), @@ -37,32 +31,32 @@ export default function initAfterAppCreation() { mainStore.savePreferenceMutation({ key: 'attachment-size-limit', - value: Number.parseInt(getPreferenceFromPage('attachment-size-limit'), 10), + value: Number.parseInt(preferences['attachment-size-limit'], 10), }) mainStore.savePreferenceMutation({ key: 'version', - value: getPreferenceFromPage('config-installed-version'), + value: preferences['config-installed-version'], }) mainStore.savePreferenceMutation({ key: 'external-avatars', - value: getPreferenceFromPage('external-avatars'), + value: preferences['external-avatars'], }) mainStore.savePreferenceMutation({ key: 'collect-data', - value: getPreferenceFromPage('collect-data'), + value: preferences['collect-data'], }) mainStore.savePreferenceMutation({ key: 'search-priority-body', - value: getPreferenceFromPage('search-priority-body'), + value: preferences['search-priority-body'], }) - const startMailboxId = getPreferenceFromPage('start-mailbox-id') + const startMailboxId = preferences['start-mailbox-id'] mainStore.savePreferenceMutation({ key: 'start-mailbox-id', value: startMailboxId ? parseInt(startMailboxId, 10) : null, }) mainStore.savePreferenceMutation({ key: 'tag-classified-messages', - value: getPreferenceFromPage('tag-classified-messages'), + value: preferences['tag-classified-messages'], }) mainStore.savePreferenceMutation({ key: 'allow-new-accounts', @@ -74,11 +68,11 @@ export default function initAfterAppCreation() { }) mainStore.savePreferenceMutation({ key: 'layout-mode', - value: getPreferenceFromPage('layout-mode'), + value: preferences['layout-mode'], }) mainStore.savePreferenceMutation({ key: 'follow-up-reminders', - value: getPreferenceFromPage('follow-up-reminders'), + value: preferences['follow-up-reminders'], }) mainStore.savePreferenceMutation({ key: 'internal-addresses', diff --git a/templates/index.php b/templates/index.php index e5ea418de2..0dbbf94c63 100644 --- a/templates/index.php +++ b/templates/index.php @@ -5,15 +5,3 @@ * SPDX-License-Identifier: AGPL-3.0-only */ script('mail', 'mail'); -?> - - - - - - - - - - - diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index c5245a74d4..9bcf5d5df5 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -299,7 +299,7 @@ public function testIndex(): void { ->method('getLoginCredentials') ->willReturn($loginCredentials); - $this->initialState->expects($this->exactly(20)) + $this->initialState->expects($this->exactly(21)) ->method('provideInitialState') ->withConsecutive( ['debug', true], @@ -311,6 +311,18 @@ public function testIndex(): void { ['internal-addresses', false], ['sort-order', 'newest'], ['password-is-unavailable', true], + ['preferences', [ + 'attachment-size-limit' => 123, + 'external-avatars' => 'true', + 'reply-mode' => 'bottom', + 'app-version' => '1.2.3', + 'collect-data' => 'true', + 'start-mailbox-id' => '123', + 'tag-classified-messages' => 'false', + 'search-priority-body' => 'false', + 'layout-mode' => 'vertical-split', + 'follow-up-reminders' => 'true', + ]], ['prefill_displayName', 'Jane Doe'], ['prefill_email', 'jane@doe.cz'], ['outbox-messages', []], @@ -324,18 +336,7 @@ public function testIndex(): void { ['smime-certificates', []], ); - $expected = new TemplateResponse($this->appName, 'index', [ - 'attachment-size-limit' => 123, - 'external-avatars' => 'true', - 'reply-mode' => 'bottom', - 'app-version' => '1.2.3', - 'collect-data' => 'true', - 'start-mailbox-id' => '123', - 'tag-classified-messages' => 'false', - 'search-priority-body' => 'false', - 'layout-mode' => 'vertical-split', - 'follow-up-reminders' => 'true', - ]); + $expected = new TemplateResponse($this->appName, 'index'); $csp = new ContentSecurityPolicy(); $csp->addAllowedFrameDomain('\'self\''); $expected->setContentSecurityPolicy($csp);