mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
[local-sync] Fix setlabels task
Make sure we /remove/ the labels when we get an empty set of label ids
This commit is contained in:
parent
aba77ca637
commit
ce27b0db2a
|
@ -10,14 +10,22 @@ class SetThreadLabelsIMAP extends SyncbackTask {
|
|||
const threadId = this.syncbackRequestObject().props.threadId
|
||||
const labelIds = this.syncbackRequestObject().props.labelIds
|
||||
|
||||
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;
|
||||
});
|
||||
if (!labelIds || labelIds.length === 0) {
|
||||
return TaskHelpers.forEachMessageInThread({
|
||||
db,
|
||||
imap,
|
||||
threadId,
|
||||
callback: ({message, box}) => {
|
||||
return message.getLabels().then((labels) => {
|
||||
const labelIdentifiers = labels.map(label => label.imapLabelIdentifier())
|
||||
return box.removeLabels(message.folderImapUID, labelIdentifiers)
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const labels = await db.Label.findAll({where: {id: labelIds}});
|
||||
const labelIdentifiers = labels.map(label => label.imapLabelIdentifier());
|
||||
|
||||
// Ben TODO this is super inefficient because it makes IMAP requests
|
||||
// one UID at a time, rather than gathering all the UIDs and making
|
||||
|
@ -27,7 +35,7 @@ class SetThreadLabelsIMAP extends SyncbackTask {
|
|||
imap,
|
||||
threadId,
|
||||
callback: ({message, box}) => {
|
||||
return box.setLabels(message.folderImapUID, gmailLabelIdentifiers)
|
||||
return box.setLabels(message.folderImapUID, labelIdentifiers)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -36,7 +36,14 @@ module.exports = (sequelize, Sequelize) => {
|
|||
},
|
||||
},
|
||||
instanceMethods: {
|
||||
toJSON: function toJSON() {
|
||||
imapLabelIdentifier() {
|
||||
if (this.role) {
|
||||
return `\\${this.role[0].toUpperCase()}${this.role.slice(1)}`
|
||||
}
|
||||
return this.name;
|
||||
},
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: `${this.id}`,
|
||||
account_id: this.accountId,
|
||||
|
|
Loading…
Reference in a new issue