diff options
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/actions.js | 38 | ||||
-rw-r--r-- | src/store/getters.js | 6 | ||||
-rw-r--r-- | src/store/mutations.js | 14 |
3 files changed, 35 insertions, 23 deletions
diff --git a/src/store/actions.js b/src/store/actions.js index 76da406e6..4a5c441a4 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -227,24 +227,23 @@ export default { updated, }) }, - fetchEnvelope({ commit, getters }, id) { + async fetchEnvelope({ commit, getters }, id) { const cached = getters.getEnvelope(id) if (cached) { logger.debug(`using cached value for envelope ${id}`) return cached } - return fetchEnvelope(id).then((envelope) => { - // Only commit if not undefined (not found) - if (envelope) { - commit('addEnvelope', { - envelope, - }) - } + const envelope = await fetchEnvelope(id) + // Only commit if not undefined (not found) + if (envelope) { + commit('addEnvelope', { + envelope, + }) + } - // Always use the object from the store - return getters.getEnvelope(id) - }) + // Always use the object from the store + return getters.getEnvelope(id) }, fetchEnvelopes({ state, commit, getters, dispatch }, { mailboxId, query }) { const mailbox = getters.getMailbox(mailboxId) @@ -392,7 +391,6 @@ export default { }) }, syncEnvelopes({ commit, getters, dispatch }, { mailboxId, query, init = false }) { - // TODO: use mailboxId const mailbox = getters.getMailbox(mailboxId) if (mailbox.isUnified) { @@ -438,6 +436,8 @@ export default { const ids = getters.getEnvelopes(mailboxId, query).map((env) => env.databaseId) return syncEnvelopes(mailbox.accountId, mailboxId, ids, query, init) .then((syncData) => { + logger.info(`mailbox ${mailboxId} synchronized, ${syncData.newMessages.length} new, ${syncData.changedMessages.length} changed and ${syncData.vanishedMessages.length} vanished messages`) + const unifiedMailbox = getters.getUnifiedMailbox(mailbox.specialRole) syncData.newMessages.forEach((envelope) => { @@ -654,6 +654,14 @@ export default { }) }) }, + async fetchThread({ getters, commit }, id) { + const thread = await fetchThread(id) + commit('addEnvelopeThread', { + id, + thread, + }) + return thread + }, async fetchMessage({ getters, commit }, id) { const message = await fetchMessage(id) // Only commit if not undefined (not found) @@ -661,12 +669,6 @@ export default { commit('addMessage', { message, }) - - const thread = await fetchThread(message.databaseId) - commit('addMessageThread', { - message, - thread, - }) } return message }, diff --git a/src/store/getters.js b/src/store/getters.js index cad479d03..99bb27e3c 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -61,7 +61,9 @@ export const getters = { getMessage: (state) => (id) => { return state.messages[id] }, - getMessageThread: (state) => (id) => { - return sortBy(prop('dateInt'), state.messages[id]?.thread ?? []) + getEnvelopeThread: (state) => (id) => { + const thread = state.envelopes[id]?.thread ?? [] + const envelopes = thread.map(id => state.envelopes[id]) + return sortBy(prop('dateInt'), envelopes) }, } diff --git a/src/store/mutations.js b/src/store/mutations.js index 0e893d0f9..69d2e15ee 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -32,7 +32,7 @@ import { UNIFIED_ACCOUNT_ID } from './constants' const addMailboxToState = curry((state, account, mailbox) => { mailbox.accountId = account.id mailbox.mailboxes = [] - mailbox.envelopeLists = {} + Vue.set(mailbox, 'envelopeLists', {}) // Add all mailboxes (including submailboxes to state, but only toplevel to account const nameWithoutPrefix = account.personalNamespace @@ -216,8 +216,16 @@ export default { addMessage(state, { message }) { Vue.set(state.messages, message.databaseId, message) }, - addMessageThread(state, { message, thread }) { - Vue.set(message, 'thread', thread) + addEnvelopeThread(state, { id, thread }) { + // Store the envelopes, merge into any existing object if one exists + thread.map(e => { + const mailbox = state.mailboxes[e.mailboxId] + Vue.set(e, 'accountId', mailbox.accountId) + Vue.set(state.envelopes, e.databaseId, Object.assign({}, state.envelopes[e.databaseId] || {}, e)) + }) + + // Store the references + Vue.set(state.envelopes[id], 'thread', thread.map(e => e.databaseId)) }, removeMessage(state, { id }) { Vue.delete(state.messages, id) |