diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-03-25 12:15:28 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-03-25 12:15:28 +0300 |
commit | 4e4f85d8f29946fedaaa3fa532cf3b1ab38a0def (patch) | |
tree | 1a3449996aa6a5b62cae180ee9361d0bc0b39c66 /src | |
parent | 9707fea568543401fd226841b1df07f5de284f87 (diff) | |
parent | ecdae8bdd670a149b626e821be798f01b443a97f (diff) |
Merge remote-tracking branch 'origin/main' into chore/update-feature-outbox-II
Diffstat (limited to 'src')
-rw-r--r-- | src/components/EnvelopeList.vue | 93 | ||||
-rw-r--r-- | src/components/Mailbox.vue | 2 |
2 files changed, 52 insertions, 43 deletions
diff --git a/src/components/EnvelopeList.vue b/src/components/EnvelopeList.vue index 35ac3d823..c903e1a0d 100644 --- a/src/components/EnvelopeList.vue +++ b/src/components/EnvelopeList.vue @@ -341,54 +341,63 @@ export default { this.unselectAll() }, async deleteAllSelected() { - for (const envelope of this.selectedEnvelopes) { - // Navigate if the message being deleted is the one currently viewed - // Shouldn't we simply use $emit here? - // Would be better to navigate after all messages have been deleted - if (envelope.databaseId === this.$route.params.threadId) { - const index = this.envelopes.indexOf(envelope) - let next - if (index === 0) { - next = this.envelopes[index + 1] - } else { - next = this.envelopes[index - 1] - } + let nextEnvelopeToNavigate + let isAllSelected - if (next) { - this.$router.push({ - name: 'message', - params: { - mailboxId: this.$route.params.mailboxId, - threadId: next.databaseId, - }, - }) - } - } - logger.info(`deleting thread ${envelope.threadRootId}`) - try { - await this.$store.dispatch('deleteThread', { - envelope, - }) - } catch (error) { - showError(await matchError(error, { - [NoTrashMailboxConfiguredError.getName()]() { - return t('mail', 'No trash mailbox configured') - }, - default(error) { - logger.error('could not delete message', error) - return t('mail', 'Could not delete message') - }, - })) + if (this.selectedEnvelopes.length === this.envelopes.length) { + isAllSelected = true + } else { + const indexSelectedEnvelope = this.selectedEnvelopes.findIndex((selectedEnvelope) => + selectedEnvelope.databaseId === this.$route.params.threadId) + + // one of threads is selected + if (indexSelectedEnvelope !== -1) { + const lastSelectedEnvelope = this.selectedEnvelopes[this.selectedEnvelopes.length - 1] + const diff = this.envelopes.filter(envelope => envelope === lastSelectedEnvelope || !this.selectedEnvelopes.includes(envelope)) + const lastIndex = diff.indexOf(lastSelectedEnvelope) + nextEnvelopeToNavigate = diff[lastIndex === 0 ? 1 : lastIndex - 1] } } - // Get new messages - this.$store.dispatch('fetchNextEnvelopes', { - mailboxId: this.mailbox.databaseId, - query: this.searchQuery, - quantity: this.selectedEnvelopes.length, + await Promise.all(this.selectedEnvelopes.map(async(envelope) => { + logger.info(`deleting thread ${envelope.threadRootId}`) + await this.$store.dispatch('deleteThread', { + envelope, + }) + })).catch(async error => { + showError(await matchError(error, { + [NoTrashMailboxConfiguredError.getName()]() { + return t('mail', 'No trash mailbox configured') + }, + default(error) { + logger.error('could not delete message', error) + return t('mail', 'Could not delete message') + }, + })) }) + if (nextEnvelopeToNavigate) { + await this.$router.push({ + name: 'message', + params: { + mailboxId: this.$route.params.mailboxId, + threadId: nextEnvelopeToNavigate.databaseId, + }, + }) + // Get new messages + await this.$store.dispatch('fetchNextEnvelopes', { + mailboxId: this.mailbox.databaseId, + query: this.searchQuery, + quantity: this.selectedEnvelopes.length, + }) + } else if (isAllSelected) { + await this.$router.push({ + name: 'mailbox', + params: { + mailboxId: this.$route.params.mailboxId, + }, + }) + } this.unselectAll() }, setEnvelopeSelected(envelope, selected) { diff --git a/src/components/Mailbox.vue b/src/components/Mailbox.vue index c39f3ff03..0ba38e3c5 100644 --- a/src/components/Mailbox.vue +++ b/src/components/Mailbox.vue @@ -449,7 +449,7 @@ export default { return } - const next = this.envelopes[idx === 0 ? idx : idx - 1] + const next = this.envelopes[idx === 0 ? 1 : idx - 1] if (!next) { logger.debug('no next/previous envelope, not navigating') return |