diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/MailboxThread.vue | 14 | ||||
-rw-r--r-- | src/store/actions.js | 33 | ||||
-rw-r--r-- | src/tests/unit/util/priorityInbox.spec.js | 44 | ||||
-rw-r--r-- | src/util/priorityInbox.js | 43 |
4 files changed, 117 insertions, 17 deletions
diff --git a/src/components/MailboxThread.vue b/src/components/MailboxThread.vue index 3af61cc2c..01077651f 100644 --- a/src/components/MailboxThread.vue +++ b/src/components/MailboxThread.vue @@ -31,7 +31,7 @@ class="nameimportant" :account="unifiedAccount" :mailbox="unifiedInbox" - :search-query="appendToSearch('is:pi-important')" + :search-query="appendToSearch(priorityImportantQuery)" :paginate="'manual'" :is-priority-inbox="true" :initial-page-size="5" @@ -42,7 +42,7 @@ class="namestarred" :account="unifiedAccount" :mailbox="unifiedInbox" - :search-query="appendToSearch('is:pi-starred')" + :search-query="appendToSearch(priorityStarredQuery)" :paginate="'manual'" :is-priority-inbox="true" :initial-page-size="5" @@ -53,7 +53,7 @@ :account="unifiedAccount" :mailbox="unifiedInbox" :open-first="false" - :search-query="appendToSearch('is:pi-other')" + :search-query="appendToSearch(priorityOtherQuery)" :is-priority-inbox="true" :bus="bus" /> </template> @@ -84,6 +84,11 @@ import NoMessageSelected from './NoMessageSelected' import Thread from './Thread' import { UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID } from '../store/constants' import NewMessageModal from './NewMessageModal' +import { + priorityImportantQuery, + priorityOtherQuery, + priorityStarredQuery, +} from '../util/priorityInbox' export default { name: 'MailboxThread', @@ -127,6 +132,9 @@ export default { unseen: ['u'], }, showComposer: false, + priorityImportantQuery, + priorityStarredQuery, + priorityOtherQuery, } }, computed: { diff --git a/src/store/actions.js b/src/store/actions.js index c62bd8c4c..ee3d99032 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -81,6 +81,7 @@ import { wait } from '../util/wait' import { updateAccount as updateSieveAccount } from '../service/SieveService' import { PAGE_SIZE, UNIFIED_INBOX_ID } from './constants' import * as ThreadService from '../service/ThreadService' +import { getPrioritySearchQueries } from '../util/priorityInbox' const sliceToPage = slice(0, PAGE_SIZE) @@ -461,22 +462,26 @@ export default { ) } else if (mailbox.isPriorityInbox && query === undefined) { return Promise.all( - getters.accounts - .filter((account) => !account.isUnified) - .map((account) => - Promise.all( - getters - .getMailboxes(account.id) - .filter((mb) => mb.specialRole === mailbox.specialRole) - .map((mailbox) => - dispatch('syncEnvelopes', { - mailboxId: mailbox.databaseId, - query, - init, - }) + getPrioritySearchQueries().map((query) => { + return Promise.all( + getters.accounts + .filter((account) => !account.isUnified) + .map((account) => + Promise.all( + getters + .getMailboxes(account.id) + .filter((mb) => mb.specialRole === mailbox.specialRole) + .map((mailbox) => + dispatch('syncEnvelopes', { + mailboxId: mailbox.databaseId, + query, + init, + }) + ) ) - ) + ) ) + }) ) } diff --git a/src/tests/unit/util/priorityInbox.spec.js b/src/tests/unit/util/priorityInbox.spec.js new file mode 100644 index 000000000..35680fa97 --- /dev/null +++ b/src/tests/unit/util/priorityInbox.spec.js @@ -0,0 +1,44 @@ +/** + * @copyright Copyright (c) 2022 Richard Steinmetz <richard@steinmetz.cloud> + * + * @author Richard Steinmetz <richard@steinmetz.cloud> + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import { + getPrioritySearchQueries, + priorityImportantQuery, + priorityOtherQuery, + priorityStarredQuery, +} from '../../../util/priorityInbox' + +describe('priorityInbox', () => { + it('has correct query constants', () => { + expect(priorityImportantQuery).to.equal('is:pi-important') + expect(priorityStarredQuery).to.equal('is:pi-starred') + expect(priorityOtherQuery).to.equal('is:pi-other') + }) + + it('returns all queries', () => { + expect(getPrioritySearchQueries()).to.deep.equal([ + 'is:pi-important', + 'is:pi-starred', + 'is:pi-other', + ]) + }) +}) diff --git a/src/util/priorityInbox.js b/src/util/priorityInbox.js new file mode 100644 index 000000000..e9e5a8b3e --- /dev/null +++ b/src/util/priorityInbox.js @@ -0,0 +1,43 @@ +/** + * @copyright Copyright (c) 2022 Richard Steinmetz <richard@steinmetz.cloud> + * + * @author Richard Steinmetz <richard@steinmetz.cloud> + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** Search query for important and unread messages inside priority inbox */ +export const priorityImportantQuery = 'is:pi-important' + +/** Search query for starred messages inside priority inbox */ +export const priorityStarredQuery = 'is:pi-starred' + +/** Search query for other messages inside priority inbox */ +export const priorityOtherQuery = 'is:pi-other' + +/** + * Return an array of all search queries inside the priority inbox + * + * @returns {(string)[]} + */ +export function getPrioritySearchQueries() { + return [ + priorityImportantQuery, + priorityStarredQuery, + priorityOtherQuery, + ] +} |