Skip to content

Commit

Permalink
Merge pull request #8771 from nextcloud/fix/8742/create-snooze-on-fir…
Browse files Browse the repository at this point in the history
…st-snooze

fix(snooze): create snooze mailbox on first snooze
  • Loading branch information
JohannesGGE authored Aug 18, 2023
2 parents 4e6c7eb + d38e426 commit 71a082d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/Envelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 30 additions & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
})
},
}
3 changes: 3 additions & 0 deletions src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
},
Expand Down

0 comments on commit 71a082d

Please sign in to comment.