diff --git a/src/components/Envelope.vue b/src/components/Envelope.vue index 51481e6b71..8382d31064 100644 --- a/src/components/Envelope.vue +++ b/src/components/Envelope.vue @@ -790,6 +790,38 @@ export default { // Remove from selection first this.setSelected(false) + if (!this.account.snoozeMailboxId) { + const name = 'Snoozed' + let snoozeMailboxId + + await this.$store + .dispatch('createMailbox', { account: this.account, name }) + .then((response) => { + logger.info(`mailbox ${name} created as ${response.databaseId}`) + snoozeMailboxId = response.databaseId + }) + .catch((error) => { + logger.error('could not create mailbox', { error }) + }) + + if (snoozeMailboxId === undefined) { + snoozeMailboxId = this.$store.getters.findMailboxByName(this.account.id, name).databaseId + } + + if (snoozeMailboxId === undefined) { + logger.error('Could not create snooze mailbox') + showError(t('mail', 'Could not create snooze mailbox')) + return + } + + await this.$store.dispatch('patchAccount', { + account: this.account, + data: { + snoozeMailboxId, + }, + }) + } + try { await this.$store.dispatch('snoozeThread', { envelope: this.data, diff --git a/src/components/MenuEnvelope.vue b/src/components/MenuEnvelope.vue index c0a60d6834..aed3b42279 100644 --- a/src/components/MenuEnvelope.vue +++ b/src/components/MenuEnvelope.vue @@ -498,6 +498,38 @@ export default { logger.info(`snoozing message ${this.envelope.databaseId}`) + if (!this.account.snoozeMailboxId) { + const name = 'Snoozed' + let snoozeMailboxId + + await this.$store + .dispatch('createMailbox', { account: this.account, name }) + .then((response) => { + logger.info(`mailbox ${name} created as ${response.databaseId}`) + snoozeMailboxId = response.databaseId + }) + .catch((error) => { + logger.error('could not create mailbox', { error }) + }) + + if (snoozeMailboxId === undefined) { + snoozeMailboxId = this.$store.getters.findMailboxByName(this.account.id, name).databaseId + } + + if (snoozeMailboxId === undefined) { + logger.error('Could not create snooze mailbox') + showError(t('mail', 'Could not create snooze mailbox')) + return + } + + await this.$store.dispatch('patchAccount', { + account: this.account, + data: { + snoozeMailboxId, + }, + }) + } + try { await this.$store.dispatch('snoozeMessage', { id: this.envelope.databaseId, 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') },