Skip to content

Commit

Permalink
fix(snooze): create snooze mailbox on first snooze
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Merkel <mail@johannesgge.de>
  • Loading branch information
JohannesGGE committed Aug 17, 2023
1 parent 5969aa8 commit 4fc009a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/components/Envelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions src/components/MenuEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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 4fc009a

Please sign in to comment.