ChangeMailTask
Summary
The ChangeMailTask is a base class for all tasks that modify sets of threads or messages.
Subclasses implement ChangeMailTask::changesToModel and ChangeMailTask::requestBodyForModel to define the specific transforms they provide, and override ChangeMailTask::performLocal to perform additional consistency checks.
ChangeMailTask aims to be fast and efficient. It does not write changes to the database or make API requests for models that are unmodified by ChangeMailTask::changesToModel
ChangeMailTask stores the previous values of all models it changes into this._restoreValues and handles undo/redo. When undoing, it restores previous values and calls ChangeMailTask::requestBodyForModel to make undo API requests. It does not call ChangeMailTask::changesToModel.
Instance Methods
changesToModel(model)
Override this method and return an object with key-value pairs representing changed values. For example, if (your task sets unread:) false, return {unread: false}.
Parameters
Argument | Description |
---|---|
model | an individual {Thread} or {Message} |
Returns
Return Values |
---|
Returns an object whos key-value pairs represent the desired changed object. |
requestBodyForModel(model)
Override this method and return an object that will be the request body used for saving changes to `model`.
Argument | Description |
---|---|
model | an individual {Thread} or {Message} |
Returns
Return Values |
---|
Returns an object that will be passed as the `body` to the actual API `request` object |
processNestedMessages()
Override to indicate whether actions need to be taken for all messages of each thread. Generally, you cannot provide both messages and threads at the same time. However, ChangeMailTask runs for provided threads first and then messages. Override and return true, and you will receive `changesToModel` for messages in changed threads, and any changes you make will be written to the database and undone during undo. Note that API requests are only made for threads if (threads are) present.
categoriesToAdd()
Return Values |
---|
Returns categories that this task will add to the set of threads Must be overriden |
categoriesToRemove()
Return Values |
---|
Returns categories that this task will remove the set of threads Must be overriden |