diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-03-06 17:03:54 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-03-06 17:03:54 +0300 |
commit | c924dbfd92575fbc1c2885af889e0531cec6bdab (patch) | |
tree | 82fb076f2e4178ae3ca877fbca52ec93cbc77579 /src/store | |
parent | 5531b41a17713965b1ecc9be07337f3615355e18 (diff) |
Apply lint:autofix on store modules
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/actions.js | 352 | ||||
-rw-r--r-- | src/store/index.js | 39 | ||||
-rw-r--r-- | src/store/mutations.js | 80 |
3 files changed, 210 insertions, 261 deletions
diff --git a/src/store/actions.js b/src/store/actions.js index 856575512..b2b9bf308 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -19,66 +19,57 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import _ from "lodash"; +import _ from 'lodash' -import {savePreference} from "../service/PreferenceService"; +import {savePreference} from '../service/PreferenceService' import { create as createAccount, update as updateAccount, deleteAccount, fetch as fetchAccount, - fetchAll as fetchAllAccounts -} from "../service/AccountService"; -import {fetchAll as fetchAllFolders} from "../service/FolderService"; -import { - deleteMessage, - fetchEnvelopes, - fetchMessage, - setEnvelopeFlag, - syncEnvelopes -} from "../service/MessageService"; -import {showNewMessagesNotification} from "../service/NotificationService"; -import {parseUid} from "../util/EnvelopeUidParser"; + fetchAll as fetchAllAccounts, +} from '../service/AccountService' +import {fetchAll as fetchAllFolders} from '../service/FolderService' +import {deleteMessage, fetchEnvelopes, fetchMessage, setEnvelopeFlag, syncEnvelopes} from '../service/MessageService' +import {showNewMessagesNotification} from '../service/NotificationService' +import {parseUid} from '../util/EnvelopeUidParser' export default { - savePreference ({commit, getters}, {key, value}) { - return savePreference(key, value) - .then(({value}) => { - commit('savePreference', { - key, - value, - }) + savePreference({commit, getters}, {key, value}) { + return savePreference(key, value).then(({value}) => { + commit('savePreference', { + key, + value, }) + }) }, - fetchAccounts ({commit, getters}) { + fetchAccounts({commit, getters}) { return fetchAllAccounts().then(accounts => { accounts.forEach(account => commit('addAccount', account)) return getters.getAccounts() }) }, - fetchAccount ({commit}, id) { + fetchAccount({commit}, id) { return fetchAccount(id).then(account => { commit('addAccount', account) return account }) }, - createAccount ({commit}, config) { - return createAccount(config) - .then(account => { - console.debug('account created', account) - commit('addAccount', account) - return account - }) + createAccount({commit}, config) { + return createAccount(config).then(account => { + console.debug('account created', account) + commit('addAccount', account) + return account + }) }, - updateAccount ({commit}, config) { - return updateAccount(config) - .then(account => { - console.debug('account updated', account) - commit('editAccount', account) - return account - }) + updateAccount({commit}, config) { + return updateAccount(config).then(account => { + console.debug('account updated', account) + commit('editAccount', account) + return account + }) }, - deleteAccount ({commit}, account) { + deleteAccount({commit}, account) { return deleteAccount(account.id) .then(account => { console.debug('account deleted') @@ -89,7 +80,7 @@ export default { throw err }) }, - fetchFolders ({commit, getters}, {accountId}) { + fetchFolders({commit, getters}, {accountId}) { if (getters.getAccount(accountId).isUnified) { return Promise.resolve(getters.getFolders(accountId)) } @@ -100,13 +91,13 @@ export default { folders.forEach(folder => { commit('addFolder', { account, - folder + folder, }) }) return folders }) }, - fetchEnvelopes ({state, commit, getters, dispatch}, {accountId, folderId, query}) { + fetchEnvelopes({state, commit, getters, dispatch}, {accountId, folderId, query}) { const folder = getters.getFolder(accountId, folderId) const isSearch = !_.isUndefined(query) if (folder.isUnified) { @@ -118,25 +109,27 @@ export default { // // TODO: handle short/ending streams and show their last element as well return Promise.all( - getters.getAccounts() + getters + .getAccounts() .filter(account => !account.isUnified) - .map(account => Promise.all( - getters.getFolders(account.id) - .filter(f => f.specialRole === folder.specialRole) - .map(folder => dispatch('fetchEnvelopes', { - accountId: account.id, - folderId: folder.id, - query, - }))) + .map(account => + Promise.all( + getters + .getFolders(account.id) + .filter(f => f.specialRole === folder.specialRole) + .map(folder => + dispatch('fetchEnvelopes', { + accountId: account.id, + folderId: folder.id, + query, + }) + ) + ) ) ) .then(res => res.map(envs => envs.slice(0, 19))) .then(res => _.flattenDepth(res, 2)) - .then(envs => _.orderBy( - envs, - env => env.dateInt, - 'desc' - )) + .then(envs => _.orderBy(envs, env => env.dateInt, 'desc')) .then(envs => _.slice(envs, 0, 19)) // 19 to handle non-overlapping streams .then(envelopes => { if (!isSearch) { @@ -158,11 +151,13 @@ export default { let folder = getters.getFolder(accountId, folderId) if (!isSearch) { - envelopes.forEach(envelope => commit('addEnvelope', { - accountId, - folder, - envelope, - })) + envelopes.forEach(envelope => + commit('addEnvelope', { + accountId, + folder, + envelope, + }) + ) } else { commit('addSearchEnvelopes', { accountId, @@ -174,23 +169,21 @@ export default { return envelopes }) }, - fetchNextUnifiedEnvelopePage ({state, commit, getters, dispatch}, {accountId, folderId, query}) { + fetchNextUnifiedEnvelopePage({state, commit, getters, dispatch}, {accountId, folderId, query}) { const folder = getters.getFolder(accountId, folderId) const isSearch = !_.isUndefined(query) const list = isSearch ? 'searchEnvelopes' : 'envelopes' // We only care about folders of the same type/role const individualFolders = _.flatten( - getters.getAccounts() + getters + .getAccounts() .filter(a => !a.isUnified) - .map(a => getters.getFolders(a.id) - .filter(f => f.specialRole === folder.specialRole)) + .map(a => getters.getFolders(a.id).filter(f => f.specialRole === folder.specialRole)) ) // Build a sorted list of all currently known envelopes (except last elem) const knownEnvelopes = _.orderBy( - _.flatten( - individualFolders.map(f => f[list].slice(0, f[list].length - 1)) - ), + _.flatten(individualFolders.map(f => f[list].slice(0, f[list].length - 1))), id => state.envelopes[id].dateInt, 'desc' ) @@ -199,7 +192,9 @@ export default { const tailId = _.last(folder[list]) const tailIdx = knownEnvelopes.indexOf(tailId) if (tailIdx === -1) { - return Promise.reject(new Error('current envelopes do not contain unified mailbox tail. this should not have happened')) + return Promise.reject( + new Error('current envelopes do not contain unified mailbox tail. this should not have happened') + ) } // Select the next page, based on offline data @@ -225,42 +220,36 @@ export default { commit('addUnifiedEnvelopes', { folder, uids: _.sortedUniq( - _.orderBy( - folder[list].concat(nextCandidates), - id => state.envelopes[id].dateInt, - 'desc' - ) + _.orderBy(folder[list].concat(nextCandidates), id => state.envelopes[id].dateInt, 'desc') ), }) } else { commit('addUnifiedSearchEnvelopes', { folder, uids: _.sortedUniq( - _.orderBy( - folder[list].concat(nextCandidates), - id => state.envelopes[id].dateInt, - 'desc' - ) + _.orderBy(folder[list].concat(nextCandidates), id => state.envelopes[id].dateInt, 'desc') ), }) } } else { - return Promise.all(needFetch - .map(f => dispatch('fetchNextEnvelopePage', { - accountId: f.accountId, - folderId: f.id, - query, - }))) - .then(() => { - return dispatch('fetchNextUnifiedEnvelopePage', { - accountId, - folderId, + return Promise.all( + needFetch.map(f => + dispatch('fetchNextEnvelopePage', { + accountId: f.accountId, + folderId: f.id, query, }) + ) + ).then(() => { + return dispatch('fetchNextUnifiedEnvelopePage', { + accountId, + folderId, + query, }) + }) } }, - fetchNextEnvelopePage ({commit, getters, dispatch}, {accountId, folderId, query}) { + fetchNextEnvelopePage({commit, getters, dispatch}, {accountId, folderId, query}) { const folder = getters.getFolder(accountId, folderId) const isSearch = !_.isUndefined(query) const list = isSearch ? 'searchEnvelopes' : 'envelopes' @@ -269,7 +258,7 @@ export default { return dispatch('fetchNextUnifiedEnvelopePage', { accountId, folderId, - query + query, }) } @@ -283,40 +272,47 @@ export default { return Promise.reject(new Error('Cannot find last envelope. Required for the folder cursor')) } - return fetchEnvelopes(accountId, folderId, query, lastEnvelope.dateInt) - .then(envelopes => { - if (!isSearch) { - envelopes.forEach(envelope => commit('addEnvelope', { - accountId, - folder, - envelope - })) - } else { - commit('addSearchEnvelopes', { + return fetchEnvelopes(accountId, folderId, query, lastEnvelope.dateInt).then(envelopes => { + if (!isSearch) { + envelopes.forEach(envelope => + commit('addEnvelope', { accountId, folder, - envelopes, - clear: false, + envelope, }) - } + ) + } else { + commit('addSearchEnvelopes', { + accountId, + folder, + envelopes, + clear: false, + }) + } - return envelopes - }) + return envelopes + }) }, - syncEnvelopes ({commit, getters, dispatch}, {accountId, folderId}) { + syncEnvelopes({commit, getters, dispatch}, {accountId, folderId}) { const folder = getters.getFolder(accountId, folderId) if (folder.isUnified) { return Promise.all( - getters.getAccounts() + getters + .getAccounts() .filter(account => !account.isUnified) - .map(account => Promise.all( - getters.getFolders(account.id) - .filter(f => f.specialRole === folder.specialRole) - .map(folder => dispatch('syncEnvelopes', { - accountId: account.id, - folderId: folder.id, - }))) + .map(account => + Promise.all( + getters + .getFolders(account.id) + .filter(f => f.specialRole === folder.specialRole) + .map(folder => + dispatch('syncEnvelopes', { + accountId: account.id, + folderId: folder.id, + }) + ) + ) ) ) } @@ -331,12 +327,12 @@ export default { commit('addEnvelope', { accountId, folder, - envelope + envelope, }) if (unifiedFolder) { commit('addUnifiedEnvelope', { folder: unifiedFolder, - envelope + envelope, }) } }) @@ -344,124 +340,114 @@ export default { commit('addEnvelope', { accountId, folder, - envelope + envelope, }) }) syncData.vanishedMessages.forEach(id => { commit('removeEnvelope', { accountId, folder, - id + id, }) // Already removed from unified inbox }) commit('updateFolderSyncToken', { folder, - syncToken: syncData.token + syncToken: syncData.token, }) return syncData.newMessages }) }, - syncInboxes ({getters, dispatch}) { - return Promise.all(getters.getAccounts() - .filter(a => !a.isUnified) - .map(account => { - return Promise.all(getters.getFolders(account.id).map(folder => { - if (folder.specialRole !== 'inbox') { - return - } + syncInboxes({getters, dispatch}) { + return Promise.all( + getters + .getAccounts() + .filter(a => !a.isUnified) + .map(account => { + return Promise.all( + getters.getFolders(account.id).map(folder => { + if (folder.specialRole !== 'inbox') { + return + } - return dispatch('syncEnvelopes', { - accountId: account.id, - folderId: folder.id, - }) - })) - })) - .then(results => { - const newMessages = _.flatMapDeep(results).filter(_.negate(_.isUndefined)) - if (newMessages.length > 0) { - showNewMessagesNotification(newMessages) - } - }) + return dispatch('syncEnvelopes', { + accountId: account.id, + folderId: folder.id, + }) + }) + ) + }) + ).then(results => { + const newMessages = _.flatMapDeep(results).filter(_.negate(_.isUndefined)) + if (newMessages.length > 0) { + showNewMessagesNotification(newMessages) + } + }) }, - toggleEnvelopeFlagged ({commit, getters}, envelope) { + toggleEnvelopeFlagged({commit, getters}, envelope) { // Change immediately and switch back on error const oldState = envelope.flags.flagged commit('flagEnvelope', { envelope, flag: 'flagged', - value: !oldState + value: !oldState, }) - setEnvelopeFlag( - envelope.accountId, - envelope.folderId, - envelope.id, - 'flagged', - !oldState - ).catch(e => { + setEnvelopeFlag(envelope.accountId, envelope.folderId, envelope.id, 'flagged', !oldState).catch(e => { console.error('could not toggle message flagged state', e) // Revert change commit('flagEnvelope', { envelope, flag: 'flagged', - value: oldState + value: oldState, }) }) }, - toggleEnvelopeSeen ({commit, getters}, envelope) { + toggleEnvelopeSeen({commit, getters}, envelope) { // Change immediately and switch back on error const oldState = envelope.flags.unseen commit('flagEnvelope', { envelope, flag: 'unseen', - value: !oldState + value: !oldState, }) - setEnvelopeFlag( - envelope.accountId, - envelope.folderId, - envelope.id, - 'unseen', - !oldState - ) - .catch(e => { - console.error('could not toggle message unseen state', e) + setEnvelopeFlag(envelope.accountId, envelope.folderId, envelope.id, 'unseen', !oldState).catch(e => { + console.error('could not toggle message unseen state', e) - // Revert change - commit('flagEnvelope', { - envelope, - flag: 'unseen', - value: oldState - }) + // Revert change + commit('flagEnvelope', { + envelope, + flag: 'unseen', + value: oldState, }) + }) }, - fetchMessage ({commit}, uid) { + fetchMessage({commit}, uid) { const {accountId, folderId, id} = parseUid(uid) - return fetchMessage(accountId, folderId, id) - .then(message => { - // Only commit if not undefined (not found) - if (message) { - commit('addMessage', { - accountId, - folderId, - message - }) - } + return fetchMessage(accountId, folderId, id).then(message => { + // Only commit if not undefined (not found) + if (message) { + commit('addMessage', { + accountId, + folderId, + message, + }) + } - return message - }) + return message + }) }, - replaceDraft ({getters, commit}, {draft, uid, data}) { + replaceDraft({getters, commit}, {draft, uid, data}) { commit('updateDraft', { draft, data, newUid: uid, }) }, - deleteMessage ({getters, commit}, envelope) { + deleteMessage({getters, commit}, envelope) { const folder = getters.getFolder(envelope.accountId, envelope.folderId) commit('removeEnvelope', { accountId: envelope.accountId, @@ -487,5 +473,5 @@ export default { }) throw err }) - } -}
\ No newline at end of file + }, +} diff --git a/src/store/index.js b/src/store/index.js index f7c9abe6d..f2a1cf429 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -26,44 +26,39 @@ import Vuex from 'vuex' import {value} from '../util/undefined' -import { - UNIFIED_ACCOUNT_ID, - UNIFIED_INBOX_ID, - UNIFIED_INBOX_UID -} from './constants' +import {UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID, UNIFIED_INBOX_UID} from './constants' import actions from './actions' import mutations from './mutations' Vue.use(Vuex) export const getters = { - getPreference: (state) => (key, def) => { + getPreference: state => (key, def) => { return value(state.preferences[key]).or(def) }, - getAccount: (state) => (id) => { + getAccount: state => id => { return state.accounts[id] }, - getAccounts: (state) => () => { + getAccounts: state => () => { return state.accountList.map(id => state.accounts[id]) }, - getFolder: (state) => (accountId, folderId) => { + getFolder: state => (accountId, folderId) => { return state.folders[accountId + '-' + folderId] }, - getFolders: (state) => (accountId) => { + getFolders: state => accountId => { return state.accounts[accountId].folders.map(folderId => state.folders[folderId]) }, - getUnifiedFolder: (state) => (specialRole) => { + getUnifiedFolder: state => specialRole => { return _.head( - state.accounts[UNIFIED_ACCOUNT_ID] - .folders + state.accounts[UNIFIED_ACCOUNT_ID].folders .map(folderId => state.folders[folderId]) .filter(folder => folder.specialRole === specialRole) ) }, - getEnvelope: (state) => (accountId, folderId, id) => { + getEnvelope: state => (accountId, folderId, id) => { return state.envelopes[accountId + '-' + folderId + '-' + id] }, - getEnvelopeById: (state) => (id) => { + getEnvelopeById: state => id => { return state.envelopes[id] }, getEnvelopes: (state, getters) => (accountId, folderId) => { @@ -72,10 +67,10 @@ export const getters = { getSearchEnvelopes: (state, getters) => (accountId, folderId) => { return getters.getFolder(accountId, folderId).searchEnvelopes.map(msgId => state.envelopes[msgId]) }, - getMessage: (state) => (accountId, folderId, id) => { + getMessage: state => (accountId, folderId, id) => { return state.messages[accountId + '-' + folderId + '-' + id] }, - getMessageByUid: (state) => uid => { + getMessageByUid: state => uid => { return state.messages[uid] }, } @@ -91,12 +86,10 @@ export default new Vuex.Store({ folders: [UNIFIED_INBOX_UID], collapsed: false, emailAddress: '', - name: '' + name: '', }, }, - accountList: [ - UNIFIED_ACCOUNT_ID, - ], + accountList: [UNIFIED_ACCOUNT_ID], folders: { [UNIFIED_INBOX_UID]: { id: UNIFIED_INBOX_ID, @@ -108,7 +101,7 @@ export default new Vuex.Store({ folders: [], envelopes: [], searchEnvelopes: [], - } + }, }, envelopes: {}, messages: {}, @@ -116,5 +109,5 @@ export default new Vuex.Store({ }, getters, mutations, - actions + actions, }) diff --git a/src/store/mutations.js b/src/store/mutations.js index 4da2571cd..dc06a1258 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -19,36 +19,28 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import _ from "lodash"; +import _ from 'lodash' import Vue from 'vue' -import {UNIFIED_ACCOUNT_ID} from "./constants"; +import {UNIFIED_ACCOUNT_ID} from './constants' export default { - savePreference (state, {key, value}) { + savePreference(state, {key, value}) { Vue.set(state.preferences, key, value) }, - addAccount (state, account) { + addAccount(state, account) { account.folders = [] account.collapsed = true Vue.set(state.accounts, account.id, account) - Vue.set( - state, - 'accountList', - _.sortBy(state.accountList.concat([account.id])) - ) + Vue.set(state, 'accountList', _.sortBy(state.accountList.concat([account.id]))) }, editAccount(state, account) { - Vue.set( - state.accounts, - account.id, - Object.assign({}, state.accounts[account.id], account) - ) + Vue.set(state.accounts, account.id, Object.assign({}, state.accounts[account.id], account)) }, - toggleAccountCollapsed (state, accountId) { + toggleAccountCollapsed(state, accountId) { state.accounts[accountId].collapsed = !state.accounts[accountId].collapsed }, - addFolder (state, {account, folder}) { + addFolder(state, {account, folder}) { const addToState = folder => { const id = account.id + '-' + folder.id folder.accountId = account.id @@ -64,10 +56,10 @@ export default { account.folders.push(id) }, - updateFolderSyncToken (state, {folder, syncToken}) { + updateFolderSyncToken(state, {folder, syncToken}) { folder.syncToken = syncToken }, - addEnvelope (state, {accountId, folder, envelope}) { + addEnvelope(state, {accountId, folder, envelope}) { const uid = accountId + '-' + folder.id + '-' + envelope.id envelope.accountId = accountId envelope.folderId = folder.id @@ -76,16 +68,10 @@ export default { Vue.set( folder, 'envelopes', - _.sortedUniq( - _.orderBy( - folder.envelopes.concat([uid]), - id => state.envelopes[id].dateInt, - 'desc' - ) - ) + _.sortedUniq(_.orderBy(folder.envelopes.concat([uid]), id => state.envelopes[id].dateInt, 'desc')) ) }, - addSearchEnvelopes (state, {accountId, folder, envelopes, clear}) { + addSearchEnvelopes(state, {accountId, folder, envelopes, clear}) { const uids = envelopes.map(envelope => { const uid = accountId + '-' + folder.id + '-' + envelope.id envelope.accountId = accountId @@ -96,48 +82,32 @@ export default { }) if (clear) { - Vue.set( - folder, - 'searchEnvelopes', - uids - ) + Vue.set(folder, 'searchEnvelopes', uids) } else { Vue.set( folder, 'searchEnvelopes', - _.sortedUniq( - _.orderBy( - folder.searchEnvelopes.concat(uids), - id => state.envelopes[id].dateInt, - 'desc' - ) - ) + _.sortedUniq(_.orderBy(folder.searchEnvelopes.concat(uids), id => state.envelopes[id].dateInt, 'desc')) ) } }, - addUnifiedEnvelope (state, {folder, envelope}) { + addUnifiedEnvelope(state, {folder, envelope}) { Vue.set( folder, 'envelopes', - _.sortedUniq( - _.orderBy( - folder.envelopes.concat([envelope.uid]), - id => state.envelopes[id].dateInt, - 'desc' - ) - ) + _.sortedUniq(_.orderBy(folder.envelopes.concat([envelope.uid]), id => state.envelopes[id].dateInt, 'desc')) ) }, - addUnifiedEnvelopes (state, {folder, uids}) { + addUnifiedEnvelopes(state, {folder, uids}) { Vue.set(folder, 'envelopes', uids) }, - addUnifiedSearchEnvelopes (state, {folder, uids}) { + addUnifiedSearchEnvelopes(state, {folder, uids}) { Vue.set(folder, 'searchEnvelopes', uids) }, - flagEnvelope (state, {envelope, flag, value}) { + flagEnvelope(state, {envelope, flag, value}) { envelope.flags[flag] = value }, - removeEnvelope (state, {accountId, folder, id}) { + removeEnvelope(state, {accountId, folder, id}) { const envelopeUid = accountId + '-' + folder.id + '-' + id const idx = folder.envelopes.indexOf(envelopeUid) if (idx < 0) { @@ -161,14 +131,14 @@ export default { Vue.delete(folder.envelopes, envelopeUid) }, - addMessage (state, {accountId, folderId, message}) { + addMessage(state, {accountId, folderId, message}) { const uid = accountId + '-' + folderId + '-' + message.id message.accountId = accountId message.folderId = folderId message.uid = uid Vue.set(state.messages, uid, message) }, - updateDraft (state, {draft, data, newUid}) { + updateDraft(state, {draft, data, newUid}) { // Update draft's UID const oldUid = draft.uid const uid = draft.accountId + '-' + draft.folderId + '-' + newUid @@ -194,10 +164,10 @@ export default { Vue.set(state.envelopes, uid, draft) Vue.set(state.messages, uid, draft) }, - setMessageBodyText (state, {uid, bodyText}) { + setMessageBodyText(state, {uid, bodyText}) { Vue.set(state.messages[uid], 'bodyText', bodyText) }, - removeMessage (state, {accountId, folderId, id}) { + removeMessage(state, {accountId, folderId, id}) { Vue.delete(state.messages, accountId + '-' + folderId + '-' + id) }, -}
\ No newline at end of file +} |