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
10 changes: 7 additions & 3 deletions apps/web/app/(app)/cold-email-blocker/ColdEmailSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/api/user/settings/cold-email/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ColdEmailSetting" ADD VALUE 'ARCHIVE_AND_READ_AND_LABEL';
1 change: 1 addition & 0 deletions apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ enum ColdEmailSetting {
LIST
LABEL
ARCHIVE_AND_LABEL
ARCHIVE_AND_READ_AND_LABEL
}

enum PremiumTier {
Expand Down
22 changes: 16 additions & 6 deletions apps/web/utils/cold-email/is-cold-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
});
}
}