Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add per-type React Email digest templates
Cursor Agent2c69e6f32aaa
diff --git a/components/emails/digest-blocked-access.tsx b/components/emails/digest-blocked-access.tsxnew file mode 100644index 00000000..18894180--- /dev/null+++ b/components/emails/digest-blocked-access.tsx@@ -0,0 +1,109 @@+import React from "react";++import {+ Body,+ Button,+ Container,+ Head,+ Html,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";++import { Footer } from "./shared/footer";++type BlockedAccessSummary = {+ blockedEmail: string;+ resourceName: string;+ resourceType: "document" | "dataroom";+};++export default function DigestBlockedAccess({+ teamName = "My Team",+ attempts = [+ { blockedEmail: "[email protected]", resourceName: "Pitch Deck v3", resourceType: "document" as const },+ { blockedEmail: "[email protected]", resourceName: "NDA Agreement", resourceType: "document" as const },+ { blockedEmail: "[email protected]", resourceName: "Series A Dataroom", resourceType: "dataroom" as const },+ ],+ totalAttempts = 3,+ frequency = "daily",+ remainingCount = 0,+}: {+ teamName: string;+ attempts: BlockedAccessSummary[];+ totalAttempts: number;+ frequency: "daily" | "weekly";+ remainingCount: number;+}) {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";++ return (+ <Html>+ <Head />+ <Preview>+ {`${totalAttempts} blocked access attempt${totalAttempts !== 1 ? "s" : ""} ${periodLabel} on ${teamName}`}+ </Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 w-[465px] p-5">+ <Text className="mb-8 mt-4 text-center text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ <Text className="mb-8 mt-4 text-center text-xl font-semibold">+ {totalAttempts} blocked access attempt+ {totalAttempts !== 1 ? "s" : ""} {periodLabel}+ </Text>+ <Text className="text-sm leading-6 text-black">+ The following access attempts were blocked on{" "}+ <span className="font-semibold">{teamName}</span> {periodLabel}:+ </Text>+ <Section className="my-4">+ {attempts.map((attempt, i) => (+ <Text+ key={i}+ className="my-1 text-sm leading-6 text-black"+ >+ •{" "}+ <span className="font-semibold">{attempt.blockedEmail}</span>+ {" tried to access "}+ <span className="font-semibold">{attempt.resourceName}</span>+ <span className="text-gray-500">+ {" "}+ ({attempt.resourceType})+ </span>+ </Text>+ ))}+ {remainingCount > 0 ? (+ <Text className="my-1 text-sm leading-6 text-gray-500">+ + {remainingCount} more attempt+ {remainingCount !== 1 ? "s" : ""}+ </Text>+ ) : null}+ </Section>+ <Section className="my-8 text-center">+ <Button+ className="rounded bg-black text-center text-xs font-semibold text-white no-underline"+ href="https://app.papermark.com/settings/general"+ style={{ padding: "12px 20px" }}+ >+ Review security settings+ </Button>+ </Section>+ <Footer+ footerText={+ <>+ You received this {frequency} digest because you have blocked+ access notifications set to {frequency} on{" "}+ <span className="font-semibold">{teamName}</span>. You can+ change this in your notification settings.+ </>+ }+ />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/components/emails/digest-conversation-messages.tsx b/components/emails/digest-conversation-messages.tsxnew file mode 100644index 00000000..0f052c6e--- /dev/null+++ b/components/emails/digest-conversation-messages.tsx@@ -0,0 +1,73 @@+import React from "react";++import {+ Body,+ Button,+ Container,+ Head,+ Html,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";++import { Footer } from "./shared/footer";++export default function DigestConversationMessages({+ teamName = "My Team",+ totalMessages = 5,+ frequency = "daily",+}: {+ teamName: string;+ totalMessages: number;+ frequency: "daily" | "weekly";+}) {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";++ return (+ <Html>+ <Head />+ <Preview>+ {`${totalMessages} new conversation message${totalMessages !== 1 ? "s" : ""} ${periodLabel} on ${teamName}`}+ </Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 w-[465px] p-5">+ <Text className="mb-8 mt-4 text-center text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ <Text className="mb-8 mt-4 text-center text-xl font-semibold">+ {totalMessages} new conversation message+ {totalMessages !== 1 ? "s" : ""} {periodLabel}+ </Text>+ <Text className="text-sm leading-6 text-black">+ You have {totalMessages} new message+ {totalMessages !== 1 ? "s" : ""} across your conversations on{" "}+ <span className="font-semibold">{teamName}</span> {periodLabel}.+ </Text>+ <Section className="my-8 text-center">+ <Button+ className="rounded bg-black text-center text-xs font-semibold text-white no-underline"+ href="https://app.papermark.com/conversations"+ style={{ padding: "12px 20px" }}+ >+ View conversations+ </Button>+ </Section>+ <Footer+ footerText={+ <>+ You received this {frequency} digest because you have+ conversation notifications set to {frequency} on{" "}+ <span className="font-semibold">{teamName}</span>. You can+ change this in your notification settings.+ </>+ }+ />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/components/emails/digest-dataroom-uploads.tsx b/components/emails/digest-dataroom-uploads.tsxnew file mode 100644index 00000000..fef840d5--- /dev/null+++ b/components/emails/digest-dataroom-uploads.tsx@@ -0,0 +1,110 @@+import React from "react";++import {+ Body,+ Button,+ Container,+ Head,+ Html,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";++import { Footer } from "./shared/footer";++type UploadSummary = {+ dataroomName: string;+ fileCount: number;+ uploaderEmail?: string;+};++export default function DigestDataroomUploads({+ teamName = "My Team",+ uploads = [+ { dataroomName: "Series A Dataroom", fileCount: 3, uploaderEmail: "[email protected]" },+ { dataroomName: "Due Diligence Room", fileCount: 1, uploaderEmail: "[email protected]" },+ ],+ totalUploads = 4,+ frequency = "daily",+ remainingCount = 0,+}: {+ teamName: string;+ uploads: UploadSummary[];+ totalUploads: number;+ frequency: "daily" | "weekly";+ remainingCount: number;+}) {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";++ return (+ <Html>+ <Head />+ <Preview>+ {`${totalUploads} data room upload${totalUploads !== 1 ? "s" : ""} ${periodLabel} on ${teamName}`}+ </Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 w-[465px] p-5">+ <Text className="mb-8 mt-4 text-center text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ <Text className="mb-8 mt-4 text-center text-xl font-semibold">+ {totalUploads} data room upload{totalUploads !== 1 ? "s" : ""}{" "}+ {periodLabel}+ </Text>+ <Text className="text-sm leading-6 text-black">+ Viewers uploaded files to data rooms on{" "}+ <span className="font-semibold">{teamName}</span> {periodLabel}:+ </Text>+ <Section className="my-4">+ {uploads.map((upload, i) => (+ <Text+ key={i}+ className="my-1 text-sm leading-6 text-black"+ >+ •{" "}+ <span className="font-semibold">{upload.dataroomName}</span>+ {" — "}+ {upload.fileCount} file{upload.fileCount !== 1 ? "s" : ""}+ {upload.uploaderEmail ? (+ <span className="text-gray-500">+ {" "}+ (by {upload.uploaderEmail})+ </span>+ ) : null}+ </Text>+ ))}+ {remainingCount > 0 ? (+ <Text className="my-1 text-sm leading-6 text-gray-500">+ + {remainingCount} more data room+ {remainingCount !== 1 ? "s" : ""}+ </Text>+ ) : null}+ </Section>+ <Section className="my-8 text-center">+ <Button+ className="rounded bg-black text-center text-xs font-semibold text-white no-underline"+ href="https://app.papermark.com/datarooms"+ style={{ padding: "12px 20px" }}+ >+ View all data rooms+ </Button>+ </Section>+ <Footer+ footerText={+ <>+ You received this {frequency} digest because you have data+ room upload notifications set to {frequency} on{" "}+ <span className="font-semibold">{teamName}</span>. You can+ change this in your notification settings.+ </>+ }+ />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/components/emails/digest-dataroom-views.tsx b/components/emails/digest-dataroom-views.tsxnew file mode 100644index 00000000..ca74d687--- /dev/null+++ b/components/emails/digest-dataroom-views.tsx@@ -0,0 +1,110 @@+import React from "react";++import {+ Body,+ Button,+ Container,+ Head,+ Html,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";++import { Footer } from "./shared/footer";++type DataroomViewSummary = {+ dataroomName: string;+ viewCount: number;+ linkName?: string;+};++export default function DigestDataroomViews({+ teamName = "My Team",+ datarooms = [+ { dataroomName: "Series A Dataroom", viewCount: 8, linkName: "Investor Link" },+ { dataroomName: "Due Diligence Room", viewCount: 4, linkName: "Legal Link" },+ ],+ totalViews = 12,+ frequency = "daily",+ remainingCount = 0,+}: {+ teamName: string;+ datarooms: DataroomViewSummary[];+ totalViews: number;+ frequency: "daily" | "weekly";+ remainingCount: number;+}) {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";++ return (+ <Html>+ <Head />+ <Preview>+ {`${totalViews} data room visit${totalViews !== 1 ? "s" : ""} ${periodLabel} on ${teamName}`}+ </Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 w-[465px] p-5">+ <Text className="mb-8 mt-4 text-center text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ <Text className="mb-8 mt-4 text-center text-xl font-semibold">+ {totalViews} data room visit{totalViews !== 1 ? "s" : ""}{" "}+ {periodLabel}+ </Text>+ <Text className="text-sm leading-6 text-black">+ Here's a summary of data room visits on{" "}+ <span className="font-semibold">{teamName}</span> {periodLabel}:+ </Text>+ <Section className="my-4">+ {datarooms.map((dr, i) => (+ <Text+ key={i}+ className="my-1 text-sm leading-6 text-black"+ >+ •{" "}+ <span className="font-semibold">{dr.dataroomName}</span>+ {" — "}+ {dr.viewCount} visit{dr.viewCount !== 1 ? "s" : ""}+ {dr.linkName ? (+ <span className="text-gray-500">+ {" "}+ (via {dr.linkName})+ </span>+ ) : null}+ </Text>+ ))}+ {remainingCount > 0 ? (+ <Text className="my-1 text-sm leading-6 text-gray-500">+ + {remainingCount} more data room+ {remainingCount !== 1 ? "s" : ""}+ </Text>+ ) : null}+ </Section>+ <Section className="my-8 text-center">+ <Button+ className="rounded bg-black text-center text-xs font-semibold text-white no-underline"+ href="https://app.papermark.com/datarooms"+ style={{ padding: "12px 20px" }}+ >+ View all data rooms+ </Button>+ </Section>+ <Footer+ footerText={+ <>+ You received this {frequency} digest because you have data+ room visit notifications set to {frequency} on{" "}+ <span className="font-semibold">{teamName}</span>. You can+ change this in your notification settings.+ </>+ }+ />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/components/emails/digest-document-views.tsx b/components/emails/digest-document-views.tsxnew file mode 100644index 00000000..8fa19b8c--- /dev/null+++ b/components/emails/digest-document-views.tsx@@ -0,0 +1,111 @@+import React from "react";++import {+ Body,+ Button,+ Container,+ Head,+ Html,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";++import { Footer } from "./shared/footer";++type DocumentViewSummary = {+ documentName: string;+ viewCount: number;+ linkName?: string;+};++export default function DigestDocumentViews({+ teamName = "My Team",+ documents = [+ { documentName: "Pitch Deck v3", viewCount: 18, linkName: "Investor Link" },+ { documentName: "NDA Agreement", viewCount: 12, linkName: "Legal Review" },+ { documentName: "Product Overview", viewCount: 9, linkName: "Sales Demo" },+ ],+ totalViews = 47,+ frequency = "daily",+ remainingCount = 2,+}: {+ teamName: string;+ documents: DocumentViewSummary[];+ totalViews: number;+ frequency: "daily" | "weekly";+ remainingCount: number;+}) {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";++ return (+ <Html>+ <Head />+ <Preview>+ {`${totalViews} document view${totalViews !== 1 ? "s" : ""} ${periodLabel} on ${teamName}`}+ </Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 w-[465px] p-5">+ <Text className="mb-8 mt-4 text-center text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ <Text className="mb-8 mt-4 text-center text-xl font-semibold">+ {totalViews} document view{totalViews !== 1 ? "s" : ""}{" "}+ {periodLabel}+ </Text>+ <Text className="text-sm leading-6 text-black">+ Here's a summary of document views on{" "}+ <span className="font-semibold">{teamName}</span> {periodLabel}:+ </Text>+ <Section className="my-4">+ {documents.map((doc, i) => (+ <Text+ key={i}+ className="my-1 text-sm leading-6 text-black"+ >+ •{" "}+ <span className="font-semibold">{doc.documentName}</span>+ {" — "}+ {doc.viewCount} view{doc.viewCount !== 1 ? "s" : ""}+ {doc.linkName ? (+ <span className="text-gray-500">+ {" "}+ (via {doc.linkName})+ </span>+ ) : null}+ </Text>+ ))}+ {remainingCount > 0 ? (+ <Text className="my-1 text-sm leading-6 text-gray-500">+ + {remainingCount} more document+ {remainingCount !== 1 ? "s" : ""}+ </Text>+ ) : null}+ </Section>+ <Section className="my-8 text-center">+ <Button+ className="rounded bg-black text-center text-xs font-semibold text-white no-underline"+ href="https://app.papermark.com/documents"+ style={{ padding: "12px 20px" }}+ >+ View all documents+ </Button>+ </Section>+ <Footer+ footerText={+ <>+ You received this {frequency} digest because you have document+ view notifications set to {frequency} on{" "}+ <span className="font-semibold">{teamName}</span>. You can+ change this in your notification settings.+ </>+ }+ />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/lib/notifications/process-digest.ts b/lib/notifications/process-digest.tsindex 9bc6de9e..a80a2672 100644--- a/lib/notifications/process-digest.ts+++ b/lib/notifications/process-digest.ts@@ -1,8 +1,16 @@+import DigestBlockedAccess from "@/components/emails/digest-blocked-access";+import DigestConversationMessages from "@/components/emails/digest-conversation-messages";+import DigestDataroomUploads from "@/components/emails/digest-dataroom-uploads";+import DigestDataroomViews from "@/components/emails/digest-dataroom-views";+import DigestDocumentViews from "@/components/emails/digest-document-views";import { limiter } from "@/lib/cron";import prisma from "@/lib/prisma";+import { sendEmail } from "@/lib/resend";import { log } from "@/lib/utils";import type { TeamNotificationType } from "@/lib/zod/schemas/notifications";+const MAX_ITEMS = 5;+type DigestGroup = {userId: string;teamId: string;@@ -28,11 +36,9 @@ export async function processNotificationDigest(return { processed: 0, sent: 0 };}- const prefGroups = new Map<string, typeof preferences>();- for (const pref of preferences) {- const key = `${pref.userId}:${pref.teamId}:${pref.type}`;- prefGroups.set(key, [...(prefGroups.get(key) || []), pref]);- }+ const prefKeys = new Set(+ preferences.map((p) => `${p.userId}:${p.teamId}:${p.type}`),+ );const digestItems = await prisma.notificationDigest.findMany({where: {@@ -49,7 +55,7 @@ export async function processNotificationDigest(for (const item of digestItems) {const key = `${item.userId}:${item.teamId}:${item.type}`;- if (!prefGroups.has(key)) continue;+ if (!prefKeys.has(key)) continue;if (!groups.has(key)) {groups.set(key, {@@ -92,18 +98,20 @@ export async function processNotificationDigest(let sent = 0;const digestItemIds = digestItems.map((i) => i.id);+ const frequencyLabel: "daily" | "weekly" =+ frequency === "DAILY" ? "daily" : "weekly";for (const group of groups.values()) {if (!group.email || group.items.length === 0) continue;try {await limiter.schedule(() =>- sendDigestEmail(group, frequency),+ sendDigestEmail(group, frequencyLabel),);sent++;} catch (error) {await log({- message: `Failed to send ${frequency.toLowerCase()} ${group.type} digest to ${group.email}. Error: ${(error as Error).message}`,+ message: `Failed to send ${frequencyLabel} ${group.type} digest to ${group.email}. Error: ${(error as Error).message}`,type: "error",});}@@ -119,146 +127,170 @@ export async function processNotificationDigest(async function sendDigestEmail(group: DigestGroup,- frequency: "DAILY" | "WEEKLY",+ frequency: "daily" | "weekly",) {- const { sendEmail } = await import("@/lib/resend");-- const frequencyLabel = frequency === "DAILY" ? "yesterday" : "this week";- const totalCount = group.items.length;-- const { subject, body } = buildDigestContent(- group.type,- group.items,- group.teamName,- frequencyLabel,- totalCount,- );+ const { subject, react } = buildDigestEmail(group, frequency);await sendEmail({to: group.email,subject,- text: body,+ react,system: true,test: process.env.NODE_ENV === "development",});}-function buildDigestContent(- type: TeamNotificationType,- items: Record<string, unknown>[],- teamName: string,- frequencyLabel: string,- totalCount: number,-): { subject: string; body: string } {- const MAX_ITEMS = 5;+function buildDigestEmail(+ group: DigestGroup,+ frequency: "daily" | "weekly",+): { subject: string; react: React.ReactElement } {+ const periodLabel = frequency === "daily" ? "yesterday" : "this week";+ const totalCount = group.items.length;- switch (type) {+ switch (group.type) {case "DOCUMENT_VIEW": {- const docCounts = new Map<string, number>();- for (const item of items) {+ const docCounts = new Map<string, { count: number; linkName?: string }>();+ for (const item of group.items) {const name = (item.documentName as string) || "Unknown Document";- docCounts.set(name, (docCounts.get(name) || 0) + 1);+ const existing = docCounts.get(name);+ docCounts.set(name, {+ count: (existing?.count || 0) + 1,+ linkName: (item.linkName as string) || existing?.linkName,+ });}- const sorted = [...docCounts.entries()].sort((a, b) => b[1] - a[1]);+ const sorted = [...docCounts.entries()].sort(+ (a, b) => b[1].count - a[1].count,+ );const top = sorted.slice(0, MAX_ITEMS);- const remaining = sorted.length - MAX_ITEMS;-- let body = `Here's what happened on ${teamName} ${frequencyLabel}:\n\n`;- body += `Document Views (${totalCount})\n`;- for (const [name, count] of top) {- body += ` - ${name}: ${count} view${count > 1 ? "s" : ""}\n`;- }- if (remaining > 0) {- body += ` + ${remaining} more document${remaining > 1 ? "s" : ""}\n`;- }+ const remaining = Math.max(0, sorted.length - MAX_ITEMS);return {- subject: `${totalCount} document view${totalCount > 1 ? "s" : ""} ${frequencyLabel} on ${teamName}`,- body,+ subject: `${totalCount} document view${totalCount > 1 ? "s" : ""} ${periodLabel} on ${group.teamName}`,+ react: DigestDocumentViews({+ teamName: group.teamName,+ documents: top.map(([name, data]) => ({+ documentName: name,+ viewCount: data.count,+ linkName: data.linkName,+ })),+ totalViews: totalCount,+ frequency,+ remainingCount: remaining,+ }),};}case "DATAROOM_VIEW": {- const drCounts = new Map<string, number>();- for (const item of items) {+ const drCounts = new Map<string, { count: number; linkName?: string }>();+ for (const item of group.items) {const name = (item.dataroomName as string) || "Unknown Data Room";- drCounts.set(name, (drCounts.get(name) || 0) + 1);+ const existing = drCounts.get(name);+ drCounts.set(name, {+ count: (existing?.count || 0) + 1,+ linkName: (item.linkName as string) || existing?.linkName,+ });}- const sorted = [...drCounts.entries()].sort((a, b) => b[1] - a[1]);+ const sorted = [...drCounts.entries()].sort(+ (a, b) => b[1].count - a[1].count,+ );const top = sorted.slice(0, MAX_ITEMS);- const remaining = sorted.length - MAX_ITEMS;-- let body = `Here's what happened on ${teamName} ${frequencyLabel}:\n\n`;- body += `Data Room Views (${totalCount})\n`;- for (const [name, count] of top) {- body += ` - ${name}: ${count} visit${count > 1 ? "s" : ""}\n`;- }- if (remaining > 0) {- body += ` + ${remaining} more data room${remaining > 1 ? "s" : ""}\n`;- }+ const remaining = Math.max(0, sorted.length - MAX_ITEMS);return {- subject: `${totalCount} data room visit${totalCount > 1 ? "s" : ""} ${frequencyLabel} on ${teamName}`,- body,+ subject: `${totalCount} data room visit${totalCount > 1 ? "s" : ""} ${periodLabel} on ${group.teamName}`,+ react: DigestDataroomViews({+ teamName: group.teamName,+ datarooms: top.map(([name, data]) => ({+ dataroomName: name,+ viewCount: data.count,+ linkName: data.linkName,+ })),+ totalViews: totalCount,+ frequency,+ remainingCount: remaining,+ }),};}case "BLOCKED_ACCESS": {- let body = `Here's what happened on ${teamName} ${frequencyLabel}:\n\n`;- body += `Blocked Access Attempts (${totalCount})\n`;- const top = items.slice(0, MAX_ITEMS);- for (const item of top) {- body += ` - ${item.blockedEmail || "Unknown"} tried to access "${item.resourceName || "a resource"}"\n`;- }- if (totalCount > MAX_ITEMS) {- body += ` + ${totalCount - MAX_ITEMS} more attempt${totalCount - MAX_ITEMS > 1 ? "s" : ""}\n`;- }+ const top = group.items.slice(0, MAX_ITEMS);+ const remaining = Math.max(0, totalCount - MAX_ITEMS);return {- subject: `${totalCount} blocked access attempt${totalCount > 1 ? "s" : ""} ${frequencyLabel} on ${teamName}`,- body,+ subject: `${totalCount} blocked access attempt${totalCount > 1 ? "s" : ""} ${periodLabel} on ${group.teamName}`,+ react: DigestBlockedAccess({+ teamName: group.teamName,+ attempts: top.map((item) => ({+ blockedEmail: (item.blockedEmail as string) || "Unknown",+ resourceName: (item.resourceName as string) || "a resource",+ resourceType:+ (item.resourceType as "document" | "dataroom") || "document",+ })),+ totalAttempts: totalCount,+ frequency,+ remainingCount: remaining,+ }),};}case "DATAROOM_UPLOAD": {- const drCounts = new Map<string, string[]>();- for (const item of items) {+ const drUploads = new Map<+ string,+ { fileCount: number; uploaderEmail?: string }+ >();+ for (const item of group.items) {const name = (item.dataroomName as string) || "Unknown Data Room";const docs = (item.documentNames as string[]) || [];- drCounts.set(name, [...(drCounts.get(name) || []), ...docs]);+ const existing = drUploads.get(name);+ drUploads.set(name, {+ fileCount: (existing?.fileCount || 0) + docs.length,+ uploaderEmail:+ (item.uploaderEmail as string) || existing?.uploaderEmail,+ });}- const sorted = [...drCounts.entries()].sort(- (a, b) => b[1].length - a[1].length,+ const sorted = [...drUploads.entries()].sort(+ (a, b) => b[1].fileCount - a[1].fileCount,);const top = sorted.slice(0, MAX_ITEMS);-- let body = `Here's what happened on ${teamName} ${frequencyLabel}:\n\n`;- body += `Data Room Uploads (${totalCount})\n`;- for (const [name, docs] of top) {- body += ` - ${name}: ${docs.length} file${docs.length > 1 ? "s" : ""} uploaded\n`;- }+ const remaining = Math.max(0, sorted.length - MAX_ITEMS);return {- subject: `${totalCount} data room upload${totalCount > 1 ? "s" : ""} ${frequencyLabel} on ${teamName}`,- body,+ subject: `${totalCount} data room upload${totalCount > 1 ? "s" : ""} ${periodLabel} on ${group.teamName}`,+ react: DigestDataroomUploads({+ teamName: group.teamName,+ uploads: top.map(([name, data]) => ({+ dataroomName: name,+ fileCount: data.fileCount,+ uploaderEmail: data.uploaderEmail,+ })),+ totalUploads: totalCount,+ frequency,+ remainingCount: remaining,+ }),};}case "CONVERSATION_MESSAGE": {- let body = `Here's what happened on ${teamName} ${frequencyLabel}:\n\n`;- body += `New Conversation Messages (${totalCount})\n`;- body += ` You have ${totalCount} new message${totalCount > 1 ? "s" : ""} across your conversations.\n`;-return {- subject: `${totalCount} new conversation message${totalCount > 1 ? "s" : ""} ${frequencyLabel} on ${teamName}`,- body,+ subject: `${totalCount} new conversation message${totalCount > 1 ? "s" : ""} ${periodLabel} on ${group.teamName}`,+ react: DigestConversationMessages({+ teamName: group.teamName,+ totalMessages: totalCount,+ frequency,+ }),};}default: {return {- subject: `Activity digest ${frequencyLabel} on ${teamName}`,- body: `You have ${totalCount} new notification${totalCount > 1 ? "s" : ""} on ${teamName}.`,+ subject: `Activity digest ${periodLabel} on ${group.teamName}`,+ react: DigestDocumentViews({+ teamName: group.teamName,+ documents: [],+ totalViews: 0,+ frequency,+ remainingCount: 0,+ }),};}}