diff --git a/src/service/MessageService.js b/src/service/MessageService.js index 50cd2047fe..8d993289ed 100644 --- a/src/service/MessageService.js +++ b/src/service/MessageService.js @@ -106,18 +106,22 @@ export async function clearCache(accountId, id) { } } -export function setEnvelopeFlag(id, flag, value) { +/** + * Set flags for envelope + * + * @param {int} id + * @param {object} flags + */ +export async function setEnvelopeFlags(id, flags) { const url = generateUrl('/apps/mail/api/messages/{id}/flags', { id, }) - return axios - .put(url, { - flags: { - [flag]: value, - }, - }) + return await axios.put(url, { + flags, + }) } + export async function createEnvelopeTag(displayName, color) { const url = generateUrl('/apps/mail/api/tags') diff --git a/src/store/actions.js b/src/store/actions.js index abc1b8c47a..0a43ceb5e7 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -73,7 +73,7 @@ import { fetchThread, moveMessage, removeEnvelopeTag, - setEnvelopeFlag, + setEnvelopeFlags, setEnvelopeTag, syncEnvelopes, updateEnvelopeTag, @@ -897,7 +897,9 @@ export default { }) try { - await setEnvelopeFlag(envelope.databaseId, 'flagged', !oldState) + await setEnvelopeFlags(envelope.databaseId, { + flagged: !oldState, + }) } catch (error) { logger.error('Could not toggle message flagged state', { error }) @@ -943,7 +945,9 @@ export default { }) try { - await setEnvelopeFlag(envelope.databaseId, 'seen', newState) + await setEnvelopeFlags(envelope.databaseId, { + seen: newState, + }) } catch (error) { console.error('could not toggle message seen state', error) @@ -974,8 +978,10 @@ export default { }) try { - await setEnvelopeFlag(envelope.databaseId, '$junk', !oldState) - await setEnvelopeFlag(envelope.databaseId, '$notjunk', oldState) + await setEnvelopeFlags(envelope.databaseId, { + $junk: !oldState, + $notjunk: oldState, + }) } catch (error) { console.error('could not toggle message junk state', error) @@ -1006,7 +1012,9 @@ export default { }) try { - await setEnvelopeFlag(envelope.databaseId, 'flagged', favFlag) + await setEnvelopeFlags(envelope.databaseId, { + flagged: favFlag, + }) } catch (error) { console.error('could not favorite/unfavorite message ' + envelope.uid, error)