mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-07 13:14:47 +08:00
[local-sync] Fix “Add INBOX label” issue
This commit is contained in:
parent
d8703b90c4
commit
94722f27ab
1 changed files with 14 additions and 23 deletions
|
@ -6,37 +6,28 @@ class SetThreadLabelsIMAP extends SyncbackTask {
|
|||
return `SetThreadLabels`;
|
||||
}
|
||||
|
||||
run(db, imap) {
|
||||
async run(db, imap) {
|
||||
const threadId = this.syncbackRequestObject().props.threadId
|
||||
const labelIds = this.syncbackRequestObject().props.labelIds
|
||||
|
||||
if (!labelIds || labelIds.length === 0) {
|
||||
return TaskHelpers.forEachMessageInThread({
|
||||
db,
|
||||
imap,
|
||||
threadId,
|
||||
callback: ({message, box}) => {
|
||||
return message.getLabels().then((labels) => {
|
||||
const labelNames = labels.map(({name}) => name)
|
||||
return box.removeLabels(message.folderImapUID, labelNames)
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
const labels = await db.Label.findAll({where: {id: labelIds}});
|
||||
const gmailLabelIdentifiers = labels.map((label) => {
|
||||
if (label.role) {
|
||||
return `\\${label.role[0].toUpperCase()}${label.role.slice(1)}`
|
||||
}
|
||||
return label.name;
|
||||
});
|
||||
|
||||
|
||||
// Ben TODO this is super inefficient because it makes IMAP requests
|
||||
// one UID at a time, rather than gathering all the UIDs and making
|
||||
// a single removeLabels call.
|
||||
return TaskHelpers.forEachMessageInThread({
|
||||
db,
|
||||
imap,
|
||||
threadId,
|
||||
callback: ({message, box}) => {
|
||||
return db.Label.findAll({
|
||||
where: {
|
||||
id: {'in': labelIds},
|
||||
},
|
||||
})
|
||||
.then((labels) => {
|
||||
const labelNames = labels.map(({name}) => name)
|
||||
return box.setLabels(message.folderImapUID, labelNames)
|
||||
})
|
||||
return box.setLabels(message.folderImapUID, gmailLabelIdentifiers)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue