Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/utils/__mocks__/email-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const createMockEmailProvider = (
overrides?: Partial<EmailProvider>,
): EmailProvider => ({
name: "google",
toJSON: () => ({ name: "google", type: "MockEmailProvider" }),
Comment thread
elie222 marked this conversation as resolved.
getThreads: vi.fn().mockResolvedValue([]),
getThread: vi.fn().mockResolvedValue({
id: "thread1",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/utils/email/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class GmailProvider implements EmailProvider {
this.client = client;
}

toJSON() {
return { name: this.name, type: "GmailProvider" };
}

async getThreads(labelId?: string): Promise<EmailThread[]> {
const response = await this.client.users.threads.list({
userId: "me",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/utils/email/microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export class OutlookProvider implements EmailProvider {
this.client = client;
}

toJSON() {
return { name: this.name, type: "OutlookProvider" };
}

async getThreads(folderId?: string): Promise<EmailThread[]> {
const messages = await this.getMessages({ folderId });
const threadMap = new Map<string, ParsedMessage[]>();
Expand Down
1 change: 1 addition & 0 deletions apps/web/utils/email/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface EmailSignature {

export interface EmailProvider {
readonly name: "google" | "microsoft";
toJSON(): { name: string; type: string };
getThreads(folderId?: string): Promise<EmailThread[]>;
getThread(threadId: string): Promise<EmailThread>;
getLabels(): Promise<EmailLabel[]>;
Expand Down
19 changes: 11 additions & 8 deletions apps/web/utils/reply-tracker/label-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function removeConflictingThreadStatusLabels({
emailAccountId,
threadId,
systemType,
provider,
provider: provider.name,
},
);

Expand Down Expand Up @@ -110,7 +110,7 @@ export async function applyThreadStatusLabel({
threadId,
messageId,
systemType,
provider,
provider: provider.name,
});

const [dbLabels, providerLabels] = await Promise.all([
Expand All @@ -121,8 +121,8 @@ export async function applyThreadStatusLabel({
const addLabel = async () => {
let targetLabel = dbLabels[systemType];

// If we don't have both labelId and label from DB, fetch/create it
if (!targetLabel.labelId && !targetLabel.label) {
// If we don't have labelId from DB, fetch/create it
if (!targetLabel.labelId) {
const label =
providerLabels.find((l) => l.name === getRuleLabel(systemType)) ||
(await provider.createLabel(getRuleLabel(systemType)));
Expand All @@ -134,16 +134,19 @@ export async function applyThreadStatusLabel({
}
}

// Error only if we still don't have either field after attempting to fetch/create
if (!targetLabel.labelId && !targetLabel.label) {
logger.error("Failed to get or create target label");
// Must have labelId to proceed
if (!targetLabel.labelId) {
logger.error("Failed to get or create target label", {
systemType,
labelName: getRuleLabel(systemType),
});
return;
}

return labelMessageAndSync({
provider,
messageId,
labelId: targetLabel.labelId || "",
labelId: targetLabel.labelId,
labelName: targetLabel.label,
emailAccountId,
}).catch((error) =>
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.17.29
v2.17.30
Loading