Mailspring/packages/nylas-sync/syncback-task-factory.js
2016-06-30 11:54:12 -07:00

42 lines
1.7 KiB
JavaScript

/**
* Given a `SyncbackRequestObject` it creates the appropriate syncback task.
*
*/
class SyncbackTaskFactory {
static create(account, syncbackRequest) {
let Task = null;
switch (syncbackRequest.type) {
case "MoveToFolder":
Task = require('./syncback_tasks/move-to-folder.imap'); break;
case "MarkThreadAsRead":
Task = require('./syncback_tasks/mark-thread-as-read.imap'); break;
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;
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;
default:
throw new Error(`Invalid Task Type: ${syncbackRequest.type}`)
}
return new Task(account, syncbackRequest)
}
}
module.exports = SyncbackTaskFactory