mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-12 07:34:52 +08:00
Fix thread moving to support new Promises
This commit is contained in:
parent
a229ba1a90
commit
45f132b746
6 changed files with 31 additions and 34 deletions
|
@ -4,7 +4,6 @@
|
|||
"description": "k2",
|
||||
"main": "",
|
||||
"dependencies": {
|
||||
"bluebird": "3.x.x",
|
||||
"bunyan": "1.8.0",
|
||||
"bunyan-cloudwatch": "2.0.0",
|
||||
"bunyan-loggly": "^1.0.0",
|
||||
|
|
|
@ -10,21 +10,6 @@ module.exports = (server) => {
|
|||
server.route({
|
||||
method: 'POST',
|
||||
path: '/send',
|
||||
config: {
|
||||
validate: {
|
||||
payload: {
|
||||
subject: Joi.string(),
|
||||
reply_to_message_id: Joi.number().integer(),
|
||||
from: Joi.array(),
|
||||
reply_to: Joi.array(),
|
||||
to: Joi.array(),
|
||||
cc: Joi.array(),
|
||||
bcc: Joi.array(),
|
||||
body: Joi.string(),
|
||||
file_ids: Joi.array(),
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: (request, reply) => { DatabaseConnector.forShared().then((db) => {
|
||||
const accountId = request.auth.credentials.id;
|
||||
db.Account.findById(accountId).then((account) => {
|
||||
|
|
|
@ -184,16 +184,15 @@ module.exports = (server) => {
|
|||
},
|
||||
handler: (request, reply) => {
|
||||
const payload = request.payload
|
||||
if (payload.folder_id) {
|
||||
if (payload.folder_id || payload.folder) {
|
||||
createSyncbackRequest(request, reply, {
|
||||
type: "MoveToFolder",
|
||||
props: {
|
||||
folderId: request.payload.folder_id,
|
||||
folderId: request.payload.folder_id || request.payload.folder,
|
||||
threadId: request.params.id,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (payload.unread === false) {
|
||||
} else if (payload.unread === false) {
|
||||
createSyncbackRequest(request, reply, {
|
||||
type: "MarkThreadAsRead",
|
||||
props: {
|
||||
|
@ -207,8 +206,7 @@ module.exports = (server) => {
|
|||
threadId: request.params.id,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (payload.starred === false) {
|
||||
} else if (payload.starred === false) {
|
||||
createSyncbackRequest(request, reply, {
|
||||
type: "UnstarThread",
|
||||
props: {
|
||||
|
@ -222,6 +220,8 @@ module.exports = (server) => {
|
|||
threadId: request.params.id,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
reply("Invalid thread update").code(400)
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -10,5 +10,17 @@ module.exports = (sequelize, Sequelize) => {
|
|||
},
|
||||
error: JSONType('error'),
|
||||
props: JSONType('props'),
|
||||
}, {
|
||||
instanceMethods: {
|
||||
toJSON: function toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
type: this.type,
|
||||
status: this.status,
|
||||
error: this.error,
|
||||
props: this.props,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@ const {
|
|||
DatabaseConnector,
|
||||
MessageTypes,
|
||||
Errors,
|
||||
PromiseUtils,
|
||||
} = require('nylas-core');
|
||||
const {
|
||||
jsonError,
|
||||
|
@ -137,9 +138,9 @@ class SyncWorker {
|
|||
|
||||
syncbackMessageActions() {
|
||||
const where = {where: {status: "NEW"}, limit: 100};
|
||||
return this._db.SyncbackRequest.findAll(where)
|
||||
.map((req) => SyncbackTaskFactory.create(this._account, req))
|
||||
.each(this.runSyncbackTask.bind(this))
|
||||
return PromiseUtils.each((this._db.SyncbackRequest.findAll(where)
|
||||
.map((req) => SyncbackTaskFactory.create(this._account, req))),
|
||||
this.runSyncbackTask.bind(this))
|
||||
}
|
||||
|
||||
runSyncbackTask(task) {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const _ = require('underscore')
|
||||
const {PromiseUtils} = require('nylas-core')
|
||||
|
||||
const TaskHelpers = {
|
||||
messagesForThreadByFolder: function messagesForThreadByFolder(db, threadId) {
|
||||
return db.Thread.findById(threadId).then((thread) => {
|
||||
return Promise.resolve(db.Thread.findById(threadId).then((thread) => {
|
||||
return thread.getMessages()
|
||||
}).then((messages) => {
|
||||
})).then((messages) => {
|
||||
return _.groupBy(messages, "folderId")
|
||||
})
|
||||
},
|
||||
|
@ -13,25 +14,24 @@ const TaskHelpers = {
|
|||
return TaskHelpers.messagesForThreadByFolder(db, threadId)
|
||||
.then((msgsInCategories) => {
|
||||
const cids = Object.keys(msgsInCategories);
|
||||
return db.Folder.findAll({where: {id: cids}})
|
||||
.each((category) =>
|
||||
imap.openBox(category.name, {readOnly: false}).then((box) => {
|
||||
return Promise.all(msgsInCategories[category.id].map((message) =>
|
||||
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: function openMessageBox({messageId, db, imap}) {
|
||||
return db.Message.findById(messageId).then((message) => {
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue