diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2022-09-02 17:44:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 17:44:39 +0300 |
commit | d2fb77da66832c130602db87ba547d6c6be7c7d9 (patch) | |
tree | 565c1e8ddd6b2f9c8230933432308498df446429 | |
parent | 451fd46ca9001e2a8a8ddf07ed0ba078e6f5c132 (diff) | |
parent | a0893d82a474d507d6a3ee984cf321e6e25aa5fc (diff) |
Merge pull request #7133 from nextcloud/enhancement/remember-start-mailbox
Remember last/start mailbox
-rw-r--r-- | lib/Controller/PageController.php | 1 | ||||
-rw-r--r-- | src/components/MailboxThread.vue | 33 | ||||
-rw-r--r-- | src/main.js | 5 | ||||
-rw-r--r-- | src/views/Home.vue | 15 | ||||
-rw-r--r-- | templates/index.php | 1 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 4 |
6 files changed, 57 insertions, 2 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 4a02c246c..67adeeb5d 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -165,6 +165,7 @@ class PageController extends Controller { 'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'), 'reply-mode' => $this->preferences->getPreference($this->currentUserId, 'reply-mode', 'top'), 'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'), + 'start-mailbox-id' => $this->preferences->getPreference($this->currentUserId, 'start-mailbox-id'), 'tag-classified-messages' => $this->preferences->getPreference($this->currentUserId, 'tag-classified-messages', 'true'), ]); $this->initialStateService->provideInitialState( diff --git a/src/components/MailboxThread.vue b/src/components/MailboxThread.vue index c2b7f510b..7af2c7543 100644 --- a/src/components/MailboxThread.vue +++ b/src/components/MailboxThread.vue @@ -88,6 +88,8 @@ import { } from '../util/priorityInbox' import { detect, html } from '../util/text' +const START_MAILBOX_DEBOUNCE = 5 * 1000 + export default { name: 'MailboxThread', directives: { @@ -132,6 +134,7 @@ export default { }, priorityImportantQuery, priorityOtherQuery, + startMailboxTimer: undefined, } }, computed: { @@ -164,10 +167,20 @@ export default { $route() { this.handleMailto() }, + mailbox() { + clearTimeout(this.startMailboxTimer) + setTimeout(this.saveStartMailbox, START_MAILBOX_DEBOUNCE) + }, }, created() { this.handleMailto() }, + mounted() { + setTimeout(this.saveStartMailbox, START_MAILBOX_DEBOUNCE) + }, + beforeUnmount() { + clearTimeout(this.startMailboxTimer) + }, methods: { deleteMessage(id) { this.bus.$emit('delete', id) @@ -213,6 +226,26 @@ export default { }) } }, + async saveStartMailbox() { + const currentStartMailboxId = this.$store.getters.getPreference('start-mailbox-id') + if (currentStartMailboxId === this.mailbox.databaseId) { + return + } + logger.debug(`Saving mailbox ${this.mailbox.databaseId} as start mailbox`) + + try { + await this.$store + .dispatch('savePreference', { + key: 'start-mailbox-id', + value: this.mailbox.databaseId, + }) + } catch (error) { + // Catch and log. This is not critical. + logger.warn('Could not update start mailbox id', { + error, + }) + } + }, stringToRecipients(str) { if (str === undefined) { return [] diff --git a/src/main.js b/src/main.js index 978cd8fd7..9d980dd44 100644 --- a/src/main.js +++ b/src/main.js @@ -78,6 +78,11 @@ store.commit('savePreference', { key: 'collect-data', value: getPreferenceFromPage('collect-data'), }) +const startMailboxId = getPreferenceFromPage('start-mailbox-id') +store.commit('savePreference', { + key: 'start-mailbox-id', + value: startMailboxId ? parseInt(startMailboxId, 10) : null, +}) store.commit('savePreference', { key: 'tag-classified-messages', value: getPreferenceFromPage('tag-classified-messages'), diff --git a/src/views/Home.vue b/src/views/Home.vue index a0328d18a..9cc2afd89 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -44,8 +44,21 @@ export default { }, created() { const accounts = this.$store.getters.accounts + let startMailboxId = this.$store.getters.getPreference('start-mailbox-id') + if (startMailboxId && !this.$store.getters.getMailbox(startMailboxId)) { + // The start ID is set but the mailbox doesn't exist anymore + startMailboxId = null + } - if (this.$route.name === 'home' && accounts.length > 1) { + if (this.$route.name === 'home' && accounts.length > 1 && startMailboxId) { + logger.debug('Loading start mailbox', { id: startMailboxId }) + this.$router.replace({ + name: 'mailbox', + params: { + mailboxId: startMailboxId, + }, + }) + } else if (this.$route.name === 'home' && accounts.length > 1) { // Show first account const firstAccount = accounts[0] // FIXME: this assumes that there's at least one mailbox diff --git a/templates/index.php b/templates/index.php index c4edb35c3..c2c4dd31e 100644 --- a/templates/index.php +++ b/templates/index.php @@ -32,4 +32,5 @@ script('mail', 'mail'); <input type="hidden" id="config-installed-version" value="<?php p($_['app-version']); ?>"> <input type="hidden" id="external-avatars" value="<?php p($_['external-avatars']); ?>"> <input type="hidden" id="collect-data" value="<?php p($_['collect-data']); ?>"> +<input type="hidden" id="start-mailbox-id" value="<?php p($_['start-mailbox-id']); ?>"> <input type="hidden" id="tag-classified-messages" value="<?php p($_['tag-classified-messages']); ?>"> diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 2557cd4f6..d8013d9e1 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -132,13 +132,14 @@ class PageControllerTest extends TestCase { $account1 = $this->createMock(Account::class); $account2 = $this->createMock(Account::class); $mailbox = $this->createMock(Mailbox::class); - $this->preferences->expects($this->exactly(5)) + $this->preferences->expects($this->exactly(6)) ->method('getPreference') ->willReturnMap([ [$this->userId, 'account-settings', '[]', json_encode([])], [$this->userId, 'external-avatars', 'true', 'true'], [$this->userId, 'reply-mode', 'top', 'bottom'], [$this->userId, 'collect-data', 'true', 'true'], + [$this->userId, 'start-mailbox-id', null, '123'], [$this->userId, 'tag-classified-messages', 'true', 'true'], ]); $this->accountService->expects($this->once()) @@ -250,6 +251,7 @@ class PageControllerTest extends TestCase { 'reply-mode' => 'bottom', 'app-version' => '1.2.3', 'collect-data' => 'true', + 'start-mailbox-id' => '123', 'tag-classified-messages' => 'true', ]); $csp = new ContentSecurityPolicy(); |