mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-13 03:29:46 +08:00
f2dbb2144b
- This commit also correctly sets the labels on the corresponding thread whenever a message has its labels updated - Fix removing labels from messages
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
const _ = require('underscore')
|
|
const {PromiseUtils} = require('nylas-core')
|
|
|
|
const TaskHelpers = {
|
|
messagesForThreadByFolder(db, threadId) {
|
|
return Promise.resolve(db.Thread.findById(threadId).then((thread) => {
|
|
return thread.getMessages()
|
|
})).then((messages) => {
|
|
return _.groupBy(messages, "folderId")
|
|
})
|
|
},
|
|
|
|
forEachMessageInThread({threadId, db, imap, callback}) {
|
|
return TaskHelpers.messagesForThreadByFolder(db, threadId)
|
|
.then((msgsInCategories) => {
|
|
const cids = Object.keys(msgsInCategories);
|
|
return PromiseUtils.each(db.Folder.findAll({where: {id: cids}}), (category) =>
|
|
imap.openBox(category.name, {readOnly: false}).then((box) =>
|
|
Promise.all(msgsInCategories[category.id].map((message) =>
|
|
callback({message, category, box})
|
|
)).then(() => box.closeBox())
|
|
)
|
|
)
|
|
})
|
|
},
|
|
|
|
openMessageBox({messageId, db, imap}) {
|
|
return Promise.resolve(db.Message.findById(messageId).then((message) => {
|
|
return db.Folder.findById(message.folderId).then((category) => {
|
|
return imap.openBox(category.name).then((box) => {
|
|
return Promise.resolve({box, message})
|
|
})
|
|
})
|
|
}))
|
|
},
|
|
}
|
|
module.exports = TaskHelpers
|