diff --git a/apps/web/app/(app)/cold-email-blocker/ColdEmailSettings.tsx b/apps/web/app/(app)/cold-email-blocker/ColdEmailSettings.tsx index 1ebf7f6638..8ca0deba2e 100644 --- a/apps/web/app/(app)/cold-email-blocker/ColdEmailSettings.tsx +++ b/apps/web/app/(app)/cold-email-blocker/ColdEmailSettings.tsx @@ -85,16 +85,20 @@ export function ColdEmailForm({ description: string; }[] = useMemo( () => [ + { + value: ColdEmailSetting.ARCHIVE_AND_READ_AND_LABEL, + label: "Archive, Mark Read & Label", + description: "Archive cold emails, mark them as read, and label them", + }, { value: ColdEmailSetting.ARCHIVE_AND_LABEL, label: "Archive & Label", - description: "Automatically archive and label cold emails", + description: "Archive cold emails and label them", }, { value: ColdEmailSetting.LABEL, label: "Label Only", - description: - "Label cold emails as 'Cold Email', but keep them in my inbox", + description: "Label cold emails, but keep them in my inbox", }, { value: ColdEmailSetting.DISABLED, diff --git a/apps/web/app/api/user/settings/cold-email/validation.ts b/apps/web/app/api/user/settings/cold-email/validation.ts index 257e7474d5..27c4832532 100644 --- a/apps/web/app/api/user/settings/cold-email/validation.ts +++ b/apps/web/app/api/user/settings/cold-email/validation.ts @@ -8,6 +8,7 @@ export const updateColdEmailSettingsBody = z.object({ ColdEmailSetting.LIST, ColdEmailSetting.LABEL, ColdEmailSetting.ARCHIVE_AND_LABEL, + ColdEmailSetting.ARCHIVE_AND_READ_AND_LABEL, ]) .nullish(), coldEmailPrompt: z.string().nullish(), diff --git a/apps/web/prisma/migrations/20250130215802_read_cold_emails/migration.sql b/apps/web/prisma/migrations/20250130215802_read_cold_emails/migration.sql new file mode 100644 index 0000000000..6a1eab362d --- /dev/null +++ b/apps/web/prisma/migrations/20250130215802_read_cold_emails/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ColdEmailSetting" ADD VALUE 'ARCHIVE_AND_READ_AND_LABEL'; diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma index 0f27f9aeb4..cbcec292ba 100644 --- a/apps/web/prisma/schema.prisma +++ b/apps/web/prisma/schema.prisma @@ -412,6 +412,7 @@ enum ColdEmailSetting { LIST LABEL ARCHIVE_AND_LABEL + ARCHIVE_AND_READ_AND_LABEL } enum PremiumTier { diff --git a/apps/web/utils/cold-email/is-cold-email.ts b/apps/web/utils/cold-email/is-cold-email.ts index 3f2eb6ef24..e7ad58e19e 100644 --- a/apps/web/utils/cold-email/is-cold-email.ts +++ b/apps/web/utils/cold-email/is-cold-email.ts @@ -155,7 +155,8 @@ async function blockColdEmail(options: { if ( user.coldEmailBlocker === ColdEmailSetting.LABEL || - user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_LABEL + user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_LABEL || + user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_READ_AND_LABEL ) { if (!user.email) throw new Error("User email is required"); const coldEmailLabel = await getOrCreateInboxZeroLabel({ @@ -166,15 +167,24 @@ async function blockColdEmail(options: { logger.error("No gmail label id", { userId: user.id }); const shouldArchive = - user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_LABEL; + user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_LABEL || + user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_READ_AND_LABEL; + + const shouldMarkRead = + user.coldEmailBlocker === ColdEmailSetting.ARCHIVE_AND_READ_AND_LABEL; + + const addLabelIds: string[] = []; + if (coldEmailLabel?.id) addLabelIds.push(coldEmailLabel.id); + + const removeLabelIds: string[] = []; + if (shouldArchive) removeLabelIds.push(GmailLabel.INBOX); + if (shouldMarkRead) removeLabelIds.push(GmailLabel.UNREAD); await labelMessage({ gmail, messageId: email.messageId, - // label email as "Cold Email" - addLabelIds: coldEmailLabel?.id ? [coldEmailLabel.id] : undefined, - // archive email - removeLabelIds: shouldArchive ? [GmailLabel.INBOX] : undefined, + addLabelIds: addLabelIds.length ? addLabelIds : undefined, + removeLabelIds: removeLabelIds.length ? removeLabelIds : undefined, }); } }