Mailspring/packages/nylas-sync/syncback-task-factory.js

43 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-06-24 06:46:52 +08:00
/**
* Given a `SyncbackRequestObject` it creates the appropriate syncback task.
*
*/
class SyncbackTaskFactory {
static create(account, syncbackRequest) {
2016-06-29 08:12:45 +08:00
let Task = null;
2016-06-29 10:07:49 +08:00
switch (syncbackRequest.type) {
2016-06-29 08:12:45 +08:00
case "MoveToFolder":
Task = require('./syncback_tasks/move-to-folder.imap'); break;
2016-06-30 08:01:30 +08:00
case "MarkThreadAsRead":
Task = require('./syncback_tasks/mark-thread-as-read.imap'); break;
2016-06-30 08:23:18 +08:00
case "MarkThreadAsUnread":
Task = require('./syncback_tasks/mark-thread-as-unread.imap'); break;
case "StarThread":
Task = require('./syncback_tasks/star-thread.imap'); break;
case "UnstarThread":
Task = require('./syncback_tasks/unstar-thread.imap'); break;
case "MoveMessageToFolder":
Task = require('./syncback_tasks/move-message-to-folder.imap'); break;
case "MarkMessageAsRead":
Task = require('./syncback_tasks/mark-message-as-read.imap'); break;
case "MarkMessageAsUnread":
Task = require('./syncback_tasks/mark-message-as-unread.imap'); break;
case "StarMessage":
Task = require('./syncback_tasks/star-message.imap'); break;
case "UnstarMessage":
Task = require('./syncback_tasks/unstar-message.imap'); break;
2016-07-01 02:50:26 +08:00
case "CreateFolder":
Task = require('./syncback_tasks/create-folder.imap'); break;
case "RenameFolder":
Task = require('./syncback_tasks/rename-folder.imap'); break;
case "DeleteFolder":
Task = require('./syncback_tasks/delete-folder.imap'); break;
2016-06-29 08:12:45 +08:00
default:
throw new Error(`Invalid Task Type: ${syncbackRequest.type}`)
2016-06-24 06:46:52 +08:00
}
2016-06-29 08:12:45 +08:00
return new Task(account, syncbackRequest)
2016-06-24 06:46:52 +08:00
}
}
2016-06-29 05:07:54 +08:00
module.exports = SyncbackTaskFactory