From a56f68d9ba55a5986d2f0d3e865dff7f3115aeab Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 31 Aug 2021 17:42:11 +0200 Subject: Add getEnvelopesByThreadRootId to select messages from store by thread root id Difference to getEnvelopeThread is that store.envelopes is used instead of the threads list inside a given envelope. Signed-off-by: Daniel Kesselberg --- src/components/Thread.vue | 9 +++-- src/store/getters.js | 8 ++++- src/tests/unit/store/getters.spec.js | 65 ++++++++++++++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/Thread.vue b/src/components/Thread.vue index 5bbfea372..15dea0cdb 100644 --- a/src/components/Thread.vue +++ b/src/components/Thread.vue @@ -91,13 +91,16 @@ export default { return parseInt(this.$route.params.threadId, 10) }, thread() { - const envelopes = this.$store.getters.getEnvelopeThread(this.threadId) - const envelope = envelopes.find(envelope => envelope.databaseId === this.threadId) - + const envelope = this.$store.getters.getEnvelope(this.threadId) if (envelope === undefined) { return [] } + const envelopes = this.$store.getters.getEnvelopesByThreadRootId(envelope.accountId, envelope.threadRootId) + if (envelopes.length === 0) { + return [] + } + const currentMailbox = this.$store.getters.getMailbox(envelope.mailboxId) const trashMailbox = this.$store.getters.getMailboxes(currentMailbox.accountId).find(mailbox => mailbox.specialRole === 'trash') diff --git a/src/store/getters.js b/src/store/getters.js index 9e4e59518..6d5204fd6 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -import { defaultTo, head, sortBy, prop } from 'ramda' +import { defaultTo, head, prop, sortBy } from 'ramda' import { UNIFIED_ACCOUNT_ID } from './constants' import { normalizedEnvelopeListId } from './normalization' @@ -70,6 +70,12 @@ export const getters = { const list = getters.getMailbox(mailboxId).envelopeLists[normalizedEnvelopeListId(query)] || [] return list.map((msgId) => state.envelopes[msgId]) }, + getEnvelopesByThreadRootId: (state) => (accountId, threadRootId) => { + return sortBy( + prop('dateInt'), + Object.values(state.envelopes).filter(envelope => envelope.accountId === accountId && envelope.threadRootId === threadRootId) + ) + }, getMessage: (state) => (id) => { return state.messages[id] }, diff --git a/src/tests/unit/store/getters.spec.js b/src/tests/unit/store/getters.spec.js index 3d6d70493..bc9798c1a 100644 --- a/src/tests/unit/store/getters.spec.js +++ b/src/tests/unit/store/getters.spec.js @@ -91,7 +91,7 @@ describe('Vuex store getters', () => { 1, 2, 3, - ] + ], } state.envelopes[2] = { databaseId: 1, @@ -117,7 +117,7 @@ describe('Vuex store getters', () => { 1, 2, 3, - ] + ], }, { databaseId: 1, @@ -131,4 +131,65 @@ describe('Vuex store getters', () => { }, ]) }) + + it('return envelopes by thread root id', () => { + state.envelopes[0] = { + accountId: 1, + databaseId: 1, + uid: 101, + mailboxId: 13, + threadRootId: '123-456-789', + } + state.envelopes[1] = { + accountId: 1, + databaseId: 2, + uid: 102, + mailboxId: 13, + threadRootId: '123-456-789', + } + state.envelopes[2] = { + accountId: 1, + databaseId: 3, + uid: 103, + mailboxId: 13, + threadRootId: '234-567-890', + } + state.envelopes[3] = { + accountId: 1, + databaseId: 4, + uid: 104, + mailboxId: 13, + threadRootId: '234-567-890', + } + state.envelopes[4] = { + accountId: 2, + databaseId: 5, + uid: 105, + mailboxId: 23, + threadRootId: '123-456-789', + } + const getters = bindGetters() + + const envelopesA = getters.getEnvelopesByThreadRootId(1, '123-456-789') + expect(envelopesA).to.be.length(2) + expect(envelopesA).to.deep.equal([ + { + accountId: 1, + databaseId: 1, + uid: 101, + mailboxId: 13, + threadRootId: '123-456-789', + }, + { + accountId: 1, + databaseId: 2, + uid: 102, + mailboxId: 13, + threadRootId: '123-456-789', + }, + ]) + + const envelopesB = getters.getEnvelopesByThreadRootId('345-678-901') + expect(envelopesB).to.be.empty + }) }) -- cgit v1.2.3