From a4eb7d6ee2114a54cee76400a90d651524ea548a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sun, 16 Jun 2019 14:25:55 -0500 Subject: [PATCH] Sentry fix: guard more aggressively against creating tasks when folders are missing --- app/src/flux/tasks/change-labels-task.ts | 12 +++++++ app/src/flux/tasks/change-starred-task.ts | 9 ++++- app/src/flux/tasks/change-unread-task.ts | 9 ++++- app/src/flux/tasks/task-factory.ts | 42 +++++++++-------------- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/app/src/flux/tasks/change-labels-task.ts b/app/src/flux/tasks/change-labels-task.ts index 4a8ad6d2e..5903c3e3a 100644 --- a/app/src/flux/tasks/change-labels-task.ts +++ b/app/src/flux/tasks/change-labels-task.ts @@ -2,6 +2,9 @@ import { Label } from '../models/label'; import { ChangeMailTask } from './change-mail-task'; import Attributes from '../attributes'; import { localized } from '../../intl'; +import { AttributeValues } from '../models/model'; +import { Thread } from '../models/thread'; +import { Message } from '../models/message'; // Public: Create a new task to apply labels to a message or thread. // @@ -28,6 +31,15 @@ export class ChangeLabelsTask extends ChangeMailTask { labelsToAdd: Label[]; labelsToRemove: Label[]; + constructor( + data: AttributeValues & { + threads?: Thread[]; + messages?: Message[]; + } = {} + ) { + super(data); + } + label() { return localized('Applying labels'); } diff --git a/app/src/flux/tasks/change-starred-task.ts b/app/src/flux/tasks/change-starred-task.ts index bb9c1da2c..7b4599620 100644 --- a/app/src/flux/tasks/change-starred-task.ts +++ b/app/src/flux/tasks/change-starred-task.ts @@ -4,6 +4,8 @@ import Attributes from '../attributes'; import { ChangeMailTask } from './change-mail-task'; import { localized } from '../../intl'; import { AttributeValues } from '../models/model'; +import { Thread } from '../models/thread'; +import { Message } from '../models/message'; export class ChangeStarredTask extends ChangeMailTask { static attributes = { @@ -16,7 +18,12 @@ export class ChangeStarredTask extends ChangeMailTask { starred: boolean; - constructor(data: AttributeValues = {}) { + constructor( + data: AttributeValues & { + threads?: Thread[]; + messages?: Message[]; + } = {} + ) { super(data); } diff --git a/app/src/flux/tasks/change-unread-task.ts b/app/src/flux/tasks/change-unread-task.ts index d930e8813..514475a5e 100644 --- a/app/src/flux/tasks/change-unread-task.ts +++ b/app/src/flux/tasks/change-unread-task.ts @@ -4,6 +4,8 @@ import Attributes from '../attributes'; import { ChangeMailTask } from './change-mail-task'; import { localized } from '../../intl'; import { AttributeValues } from '../models/model'; +import { Thread } from '../models/thread'; +import { Message } from '../models/message'; export class ChangeUnreadTask extends ChangeMailTask { static attributes = { @@ -16,7 +18,12 @@ export class ChangeUnreadTask extends ChangeMailTask { unread: boolean; - constructor(data: AttributeValues = {}) { + constructor( + data: AttributeValues & { + threads?: Thread[]; + messages?: Message[]; + } = {} + ) { super(data); } diff --git a/app/src/flux/tasks/task-factory.ts b/app/src/flux/tasks/task-factory.ts index 9e6c29317..a5e8f7122 100644 --- a/app/src/flux/tasks/task-factory.ts +++ b/app/src/flux/tasks/task-factory.ts @@ -38,29 +38,24 @@ export const TaskFactory = { tasksForMarkingAsSpam({ threads, source }: { threads: Thread[]; source: string }) { return this.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => { - return new ChangeFolderTask({ - folder: CategoryStore.getSpamCategory(accountId), - threads: accountThreads, - source, - }); + const folder = CategoryStore.getSpamCategory(accountId); + if (!folder) return null; + return new ChangeFolderTask({ folder, source, threads: accountThreads }); }); }, tasksForMarkingNotSpam({ threads, source }: { threads: Thread[]; source: string }) { return this.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => { const inbox = CategoryStore.getInboxCategory(accountId); + if (inbox instanceof Label) { - return new ChangeFolderTask({ - folder: CategoryStore.getAllMailCategory(accountId) as any, - threads: accountThreads, - source, - }); + const all = CategoryStore.getAllMailCategory(accountId) as any; + if (!all) return null; + return new ChangeFolderTask({ folder: all, threads: accountThreads, source }); } - return new ChangeFolderTask({ - folder: inbox, - threads: accountThreads, - source, - }); + + if (!inbox) return null; + return new ChangeFolderTask({ folder: inbox, threads: accountThreads, source }); }); }, @@ -75,21 +70,18 @@ export const TaskFactory = { source, }); } - return new ChangeFolderTask({ - folder: CategoryStore.getArchiveCategory(accountId), - threads: accountThreads, - source, - }); + + const archive = CategoryStore.getArchiveCategory(accountId); + if (!archive) return null; + return new ChangeFolderTask({ folder: archive, threads: accountThreads, source }); }); }, tasksForMovingToTrash({ threads, source }: { threads: Thread[]; source: string }) { return this.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => { - return new ChangeFolderTask({ - folder: CategoryStore.getTrashCategory(accountId) as any, - threads: accountThreads, - source, - }); + const trash = CategoryStore.getTrashCategory(accountId) as any; + if (!trash) return null; + return new ChangeFolderTask({ folder: trash, threads: accountThreads, source }); }); },