mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
Adding in syncback message actions
This commit is contained in:
parent
b6f57f3ce8
commit
3f5cac4342
7 changed files with 95 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
"inert": "4.0.0",
|
||||
"joi": "8.4.2",
|
||||
"nylas-core": "0.x.x",
|
||||
"nylas-sync": "0.x.x",
|
||||
"vision": "4.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = (server) => {
|
|||
},
|
||||
response: {
|
||||
schema: Joi.array().items(
|
||||
Serialization.jsonSchema('Account')
|
||||
Serialization.jsonSchema('Thread')
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -28,4 +28,39 @@ module.exports = (server) => {
|
|||
})
|
||||
},
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'PUT',
|
||||
path: '/threads/${id}',
|
||||
config: {
|
||||
description: 'Update a thread',
|
||||
notes: 'Can move between folders',
|
||||
tags: ['threads'],
|
||||
validate: {
|
||||
params: {
|
||||
payload: {
|
||||
folder_id: Joi.string(),
|
||||
},
|
||||
},
|
||||
},
|
||||
response: {
|
||||
schema: Joi.array().items(
|
||||
Serialization.jsonSchema('Thread')
|
||||
),
|
||||
},
|
||||
},
|
||||
handler: (request, reply) => {
|
||||
request.getAccountDatabase().then((db) => {
|
||||
db.SyncbackRequest.create({
|
||||
type: "MoveToFolder",
|
||||
props: {
|
||||
folderId: request.params.folder_id,
|
||||
threadId: request.params.id,
|
||||
},
|
||||
}).then((syncbackRequest) => {
|
||||
reply(Serialization.jsonStringify(syncbackRequest))
|
||||
})
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
@ -17,6 +17,9 @@ function jsonSchema(modelName) {
|
|||
if (modelName === 'Message') {
|
||||
return Joi.object();
|
||||
}
|
||||
if (modelName === 'Thread') {
|
||||
return Joi.object();
|
||||
}
|
||||
if (modelName === 'Error') {
|
||||
return Joi.object();
|
||||
}
|
||||
|
|
26
packages/nylas-core/models/account/syncback-request.js
Normal file
26
packages/nylas-core/models/account/syncback-request.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
module.exports = (sequelize, Sequelize) => {
|
||||
const SyncbackRequest = sequelize.define('SyncbackRequest', {
|
||||
type: Sequelize.STRING,
|
||||
status: Sequelize.STRING,
|
||||
error: {
|
||||
type: Sequelize.STRING,
|
||||
get: function get() {
|
||||
return JSON.parse(this.getDataValue('error'))
|
||||
},
|
||||
set: function set(val) {
|
||||
this.setDataValue('error', JSON.stringify(val));
|
||||
},
|
||||
},
|
||||
props: {
|
||||
type: Sequelize.STRING,
|
||||
get: function get() {
|
||||
return JSON.parse(this.getDataValue('props'))
|
||||
},
|
||||
set: function set(val) {
|
||||
this.setDataValue('props', JSON.stringify(val));
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return SyncbackRequest;
|
||||
};
|
|
@ -116,6 +116,11 @@ class PubsubConnector {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
queueSyncbackTask({taskName, props}) {
|
||||
const channel = this.channelForSyncbackTaskQueue(accountId);
|
||||
this.broadcastClient().publish(channel, JSON.stringify(data))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new PubsubConnector()
|
||||
|
|
|
@ -6,6 +6,7 @@ const {
|
|||
|
||||
const FetchCategoryList = require('./imap/fetch-category-list')
|
||||
const FetchMessagesInCategory = require('./imap/fetch-messages-in-category')
|
||||
const SyncbackTaskFactory = require('./syncback-task-factory')
|
||||
//
|
||||
// account.syncPolicy = {
|
||||
// afterSync: 'idle',
|
||||
|
@ -116,7 +117,18 @@ class SyncWorker {
|
|||
}
|
||||
|
||||
syncbackMessageActions() {
|
||||
return Promise.resolve()
|
||||
return Promise.resolve();
|
||||
// TODO
|
||||
const {SyncbackRequest, accountId, Account} = this._db;
|
||||
|
||||
return Account.find({where: {id: accountId}}).then((account) => {
|
||||
return Promise.each(SyncbackRequest.findAll().then((reqs = []) =>
|
||||
reqs.map((request) => {
|
||||
const task = SyncbackTaskFactory.create(account, request);
|
||||
return this._conn.runOperation(task)
|
||||
})
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fetchMessagesInCategory() {
|
||||
|
|
11
packages/nylas-sync/syncback-task-factory.js
Normal file
11
packages/nylas-sync/syncback-task-factory.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* Given a `SyncbackRequestObject` it creates the appropriate syncback task.
|
||||
*
|
||||
*/
|
||||
class SyncbackTaskFactory {
|
||||
static create(account, syncbackRequest) {
|
||||
if (account) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue