Merge pull request #2707 from ahstro/refactor/use-id-normalization

Use id normalization where applicable
This commit is contained in:
Christoph Wurst 2020-02-28 16:27:20 +01:00 коммит произвёл GitHub
Родитель 75397358d5 b6dd82f132
Коммит e5a6a40acc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -18,7 +18,8 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import {normalizeFolderId} from './normalization'
export const UNIFIED_ACCOUNT_ID = 0 export const UNIFIED_ACCOUNT_ID = 0
export const UNIFIED_INBOX_ID = btoa('inbox') export const UNIFIED_INBOX_ID = btoa('inbox')
export const UNIFIED_INBOX_UID = UNIFIED_ACCOUNT_ID + '-' + UNIFIED_INBOX_ID export const UNIFIED_INBOX_UID = normalizeFolderId(UNIFIED_ACCOUNT_ID, UNIFIED_INBOX_ID)

Просмотреть файл

@ -22,7 +22,7 @@
import {defaultTo, head} from 'ramda' import {defaultTo, head} from 'ramda'
import {UNIFIED_ACCOUNT_ID} from './constants' import {UNIFIED_ACCOUNT_ID} from './constants'
import {normalizeEnvelopeListId} from './normalization' import {normalizeEnvelopeListId, normalizeFolderId, normalizeMessageId} from './normalization'
export const getters = { export const getters = {
getPreference: state => (key, def) => { getPreference: state => (key, def) => {
@ -35,7 +35,7 @@ export const getters = {
return state.accountList.map(id => state.accounts[id]) return state.accountList.map(id => state.accounts[id])
}, },
getFolder: state => (accountId, folderId) => { getFolder: state => (accountId, folderId) => {
return state.folders[accountId + '-' + folderId] return state.folders[normalizeFolderId(accountId, folderId)]
}, },
getFolders: state => accountId => { getFolders: state => accountId => {
return state.accounts[accountId].folders.map(folderId => state.folders[folderId]) return state.accounts[accountId].folders.map(folderId => state.folders[folderId])
@ -53,7 +53,7 @@ export const getters = {
) )
}, },
getEnvelope: state => (accountId, folderId, id) => { getEnvelope: state => (accountId, folderId, id) => {
return state.envelopes[accountId + '-' + folderId + '-' + id] return state.envelopes[normalizeMessageId(accountId, folderId, id)]
}, },
getEnvelopeById: state => id => { getEnvelopeById: state => id => {
return state.envelopes[id] return state.envelopes[id]
@ -63,6 +63,6 @@ export const getters = {
return list.map(msgId => state.envelopes[msgId]) return list.map(msgId => state.envelopes[msgId])
}, },
getMessage: state => (accountId, folderId, id) => { getMessage: state => (accountId, folderId, id) => {
return state.messages[accountId + '-' + folderId + '-' + id] return state.messages[normalizeMessageId(accountId, folderId, id)]
}, },
} }

Просмотреть файл

@ -30,7 +30,7 @@ import {sortMailboxes} from '../imap/MailboxSorter'
import {UNIFIED_ACCOUNT_ID} from './constants' import {UNIFIED_ACCOUNT_ID} from './constants'
const addFolderToState = (state, account) => folder => { const addFolderToState = (state, account) => folder => {
const id = account.id + '-' + folder.id const id = normalizedFolderId(account.id, folder.id)
folder.accountId = account.id folder.accountId = account.id
folder.envelopeLists = {} folder.envelopeLists = {}
Vue.set(state.folders, id, folder) Vue.set(state.folders, id, folder)
@ -151,7 +151,7 @@ export default {
Vue.delete(list, normalizedMessageId(accountId, folderId, id)) Vue.delete(list, normalizedMessageId(accountId, folderId, id))
}, },
addMessage(state, {accountId, folderId, message}) { addMessage(state, {accountId, folderId, message}) {
const uid = accountId + '-' + folderId + '-' + message.id const uid = normalizedMessageId(accountId, folderId, message.id)
message.accountId = accountId message.accountId = accountId
message.folderId = folderId message.folderId = folderId
message.uid = uid message.uid = uid
@ -160,7 +160,7 @@ export default {
updateDraft(state, {draft, data, newUid}) { updateDraft(state, {draft, data, newUid}) {
// Update draft's UID // Update draft's UID
const oldUid = draft.uid const oldUid = draft.uid
const uid = draft.accountId + '-' + draft.folderId + '-' + newUid const uid = normalizedMessageId(draft.accountId, draft.folderId, newUid)
console.debug('saving draft as UID ' + uid) console.debug('saving draft as UID ' + uid)
draft.uid = uid draft.uid = uid
@ -169,7 +169,7 @@ export default {
draft.subject = data.subject draft.subject = data.subject
// Update ref in folder's envelope list // Update ref in folder's envelope list
const envs = state.folders[draft.accountId + '-' + draft.folderId].envelopes const envs = state.folders[normalizedFolderId(draft.accountId, draft.folderId)].envelopes
const idx = envs.indexOf(oldUid) const idx = envs.indexOf(oldUid)
if (idx < 0) { if (idx < 0) {
console.warn('not replacing draft ' + oldUid + ' in envelope list because it did not exist') console.warn('not replacing draft ' + oldUid + ' in envelope list because it did not exist')
@ -184,6 +184,6 @@ export default {
Vue.set(state.messages, uid, draft) Vue.set(state.messages, uid, draft)
}, },
removeMessage(state, {accountId, folderId, id}) { removeMessage(state, {accountId, folderId, id}) {
Vue.delete(state.messages, accountId + '-' + folderId + '-' + id) Vue.delete(state.messages, normalizedMessageId(accountId, folderId, id))
}, },
} }