Skip to content

Commit

Permalink
Merge pull request #8550 from nextcloud/enh/set-multiple-lables-in-on…
Browse files Browse the repository at this point in the history
…e-request

feat: send multiple flags in a single request
  • Loading branch information
ChristophWurst authored Jun 15, 2023
2 parents a6ffbfb + 95319c0 commit 8092412
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/service/MessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
20 changes: 14 additions & 6 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
fetchThread,
moveMessage,
removeEnvelopeTag,
setEnvelopeFlag,
setEnvelopeFlags,
setEnvelopeTag,
syncEnvelopes,
updateEnvelopeTag,
Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8092412

Please sign in to comment.