Sentry fix: guard more aggressively against creating tasks when folders are missing

This commit is contained in:
Ben Gotow 2019-06-16 14:25:55 -05:00
parent b70e27a66a
commit a4eb7d6ee2
4 changed files with 45 additions and 27 deletions

View file

@ -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<typeof ChangeLabelsTask.attributes> & {
threads?: Thread[];
messages?: Message[];
} = {}
) {
super(data);
}
label() {
return localized('Applying labels');
}

View file

@ -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<typeof ChangeStarredTask.attributes> = {}) {
constructor(
data: AttributeValues<typeof ChangeStarredTask.attributes> & {
threads?: Thread[];
messages?: Message[];
} = {}
) {
super(data);
}

View file

@ -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<typeof ChangeUnreadTask.attributes> = {}) {
constructor(
data: AttributeValues<typeof ChangeUnreadTask.attributes> & {
threads?: Thread[];
messages?: Message[];
} = {}
) {
super(data);
}

View file

@ -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 });
});
},