From d38e4265d6de3f9d38fc386bedfc08cd8be4b733 Mon Sep 17 00:00:00 2001 From: Johannes Merkel Date: Thu, 17 Aug 2023 18:19:02 +0200 Subject: [PATCH] fix(snooze): create snooze mailbox on first snooze Signed-off-by: Johannes Merkel --- src/components/Envelope.vue | 4 ++++ src/components/MenuEnvelope.vue | 4 ++++ src/store/actions.js | 31 ++++++++++++++++++++++++++++++- src/store/getters.js | 3 +++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/components/Envelope.vue b/src/components/Envelope.vue index 51481e6b71..3be3ed41dd 100644 --- a/src/components/Envelope.vue +++ b/src/components/Envelope.vue @@ -790,6 +790,10 @@ export default { // Remove from selection first this.setSelected(false) + if (!this.account.snoozeMailboxId) { + await this.$store.dispatch('createAndSetSnoozeMailbox', this.account) + } + try { await this.$store.dispatch('snoozeThread', { envelope: this.data, diff --git a/src/components/MenuEnvelope.vue b/src/components/MenuEnvelope.vue index c0a60d6834..c1d2651fe9 100644 --- a/src/components/MenuEnvelope.vue +++ b/src/components/MenuEnvelope.vue @@ -498,6 +498,10 @@ export default { logger.info(`snoozing message ${this.envelope.databaseId}`) + if (!this.account.snoozeMailboxId) { + await this.$store.dispatch('createAndSetSnoozeMailbox', this.account) + } + try { await this.$store.dispatch('snoozeMessage', { id: this.envelope.databaseId, diff --git a/src/store/actions.js b/src/store/actions.js index 546d59f0b6..3aa026f703 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -104,7 +104,7 @@ import { html, plain, toPlain } from '../util/text' import Axios from '@nextcloud/axios' import { generateUrl } from '@nextcloud/router' import { handleHttpAuthErrors } from '../http/sessionExpiryHandler' -import { showWarning } from '@nextcloud/dialogs' +import { showError, showWarning } from '@nextcloud/dialogs' import { translate as t } from '@nextcloud/l10n' import { buildForwardSubject, @@ -1418,4 +1418,33 @@ export default { // move message to inbox return envelope.mailboxId !== inbox.databaseId }, + async createAndSetSnoozeMailbox({ getters, dispatch }, account) { + const name = 'Snoozed' + let snoozeMailboxId + + try { + const createMailboxResponse = await dispatch('createMailbox', { account, name }) + snoozeMailboxId = createMailboxResponse.databaseId + logger.info(`mailbox ${name} created as ${snoozeMailboxId}`) + } catch (e) { + logger.error('could not create mailbox', { e }) + } + + if (snoozeMailboxId === undefined) { + snoozeMailboxId = getters.findMailboxByName(account.id, name).databaseId + } + + if (snoozeMailboxId === undefined) { + logger.error('Could not create snooze mailbox') + showError(t('mail', 'Could not create snooze mailbox')) + return + } + + await dispatch('patchAccount', { + account, + data: { + snoozeMailboxId, + }, + }) + }, } diff --git a/src/store/getters.js b/src/store/getters.js index a53109802e..7dcb79621d 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -148,6 +148,9 @@ export const getters = { findMailboxBySpecialRole: (state, getters) => (accountId, specialRole) => { return getters.getMailboxes(accountId).find(mailbox => mailbox.specialRole === specialRole) }, + findMailboxByName: (state, getters) => (accountId, name) => { + return getters.getMailboxes(accountId).find(mailbox => mailbox.name === name) + }, getInbox: (state, getters) => (accountId) => { return getters.findMailboxBySpecialRole(accountId, 'inbox') },