Use id normalization where applicable

Signed-off-by: Anton Strömkvist <anton@stromkvist.com>
This commit is contained in:
Anton Strömkvist 2020-02-28 16:05:45 +01:00
Родитель 75397358d5
Коммит b6dd82f132
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 50A3573EFBFA9867
3 изменённых файлов: 11 добавлений и 10 удалений

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

@ -18,7 +18,8 @@
* 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 {normalizeFolderId} from './normalization'
export const UNIFIED_ACCOUNT_ID = 0
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 {UNIFIED_ACCOUNT_ID} from './constants'
import {normalizeEnvelopeListId} from './normalization'
import {normalizeEnvelopeListId, normalizeFolderId, normalizeMessageId} from './normalization'
export const getters = {
getPreference: state => (key, def) => {
@ -35,7 +35,7 @@ export const getters = {
return state.accountList.map(id => state.accounts[id])
},
getFolder: state => (accountId, folderId) => {
return state.folders[accountId + '-' + folderId]
return state.folders[normalizeFolderId(accountId, folderId)]
},
getFolders: state => accountId => {
return state.accounts[accountId].folders.map(folderId => state.folders[folderId])
@ -53,7 +53,7 @@ export const getters = {
)
},
getEnvelope: state => (accountId, folderId, id) => {
return state.envelopes[accountId + '-' + folderId + '-' + id]
return state.envelopes[normalizeMessageId(accountId, folderId, id)]
},
getEnvelopeById: state => id => {
return state.envelopes[id]
@ -63,6 +63,6 @@ export const getters = {
return list.map(msgId => state.envelopes[msgId])
},
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'
const addFolderToState = (state, account) => folder => {
const id = account.id + '-' + folder.id
const id = normalizedFolderId(account.id, folder.id)
folder.accountId = account.id
folder.envelopeLists = {}
Vue.set(state.folders, id, folder)
@ -151,7 +151,7 @@ export default {
Vue.delete(list, normalizedMessageId(accountId, folderId, id))
},
addMessage(state, {accountId, folderId, message}) {
const uid = accountId + '-' + folderId + '-' + message.id
const uid = normalizedMessageId(accountId, folderId, message.id)
message.accountId = accountId
message.folderId = folderId
message.uid = uid
@ -160,7 +160,7 @@ export default {
updateDraft(state, {draft, data, newUid}) {
// Update draft's 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)
draft.uid = uid
@ -169,7 +169,7 @@ export default {
draft.subject = data.subject
// 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)
if (idx < 0) {
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)
},
removeMessage(state, {accountId, folderId, id}) {
Vue.delete(state.messages, accountId + '-' + folderId + '-' + id)
Vue.delete(state.messages, normalizedMessageId(accountId, folderId, id))
},
}