Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ import { isGoogleProvider } from "@/utils/email/provider-types";
import { useRuleDialog } from "@/app/(app)/[emailAccountId]/assistant/RuleDialog";

export function EmailCell({
from,
subject,
snippet,
threadId,
messageId,
message,
userEmail,
createdAt,
}: {
from: string;
subject: string;
snippet: string;
threadId: string;
messageId: string;
message: ParsedMessage;
userEmail: string;
createdAt: Date;
}) {
const { id: messageId, threadId, headers, snippet } = message;
const from = headers?.from || "";
const subject = headers?.subject || "";
return (
<div className="flex flex-1 flex-col justify-center">
<div className="flex items-center justify-between">
Expand All @@ -44,11 +39,7 @@ export function EmailCell({
</div>
<div className="mt-1 flex items-center font-medium">
<span>{subject}</span>
<OpenInGmailButton
messageId={messageId}
threadId={threadId}
userEmail={userEmail}
/>
<OpenInGmailButton message={message} userEmail={userEmail} />
<ViewEmailButton
threadId={threadId}
messageId={messageId}
Expand Down Expand Up @@ -170,12 +161,10 @@ export function DateCell({ createdAt }: { createdAt: Date }) {
}

function OpenInGmailButton({
messageId,
threadId,
message,
userEmail,
}: {
messageId: string;
threadId: string;
message: ParsedMessage;
userEmail: string;
}) {
const { provider } = useAccount();
Expand All @@ -186,7 +175,7 @@ function OpenInGmailButton({

return (
<Link
href={getEmailUrlForMessage(messageId, threadId, userEmail, provider)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified this function signature to pass the entire message instead of just messageId and threadId.
Reason was that for Outlook, the link will be sourced from the message.webLink and gmail will use the message.id

href={getEmailUrlForMessage(message, provider, userEmail)}
target="_blank"
className="ml-2 text-muted-foreground hover:text-foreground"
>
Expand Down
6 changes: 1 addition & 5 deletions apps/web/app/(app)/[emailAccountId]/assistant/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ function HistoryTable({
<TableRow key={p.id}>
<TableCell>
<EmailCell
from={p.message.headers.from}
subject={p.message.headers.subject}
snippet={p.message.snippet}
threadId={p.message.threadId}
messageId={p.message.id}
message={p.message}
userEmail={userEmail}
createdAt={p.createdAt}
/>
Expand Down
10 changes: 1 addition & 9 deletions apps/web/app/(app)/[emailAccountId]/assistant/ProcessRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,7 @@ function ProcessRulesRow({
>
<TableCell>
<div className="flex items-center justify-between">
<EmailMessageCell
sender={message.headers.from}
subject={message.headers.subject}
snippet={message.snippet}
userEmail={userEmail}
threadId={message.threadId}
messageId={message.id}
labelIds={message.labelIds}
/>
<EmailMessageCell message={message} userEmail={userEmail} />
<div className="ml-4 flex items-center gap-1">
{result ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,7 @@ function TestRulesContentRow({
>
<TableCell>
<div className="flex items-center justify-between">
<EmailMessageCell
sender={message.headers.from}
subject={message.headers.subject}
snippet={message.snippet}
userEmail={userEmail}
threadId={message.threadId}
messageId={message.id}
labelIds={message.labelIds}
/>
<EmailMessageCell message={message} userEmail={userEmail} />
<div className="ml-4">
<Button
color="white"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,9 @@ function Row({
<TableCell onClick={openSplitView} className="py-8 pl-8 pr-6">
<div className="flex items-center justify-between">
<EmailMessageCell
sender={
message.labelIds?.includes("SENT")
? message.headers.to
: message.headers.from
}
subject={message.headers.subject}
snippet={message.snippet}
message={message}
userEmail={userEmail}
threadId={message.threadId}
messageId={message.id}
hideViewEmailButton
labelIds={message.labelIds}
filterReplyTrackerLabels
/>

Expand Down
9 changes: 9 additions & 0 deletions apps/web/app/api/resend/digest/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { extractNameFromEmail } from "../../../../utils/email";
import { RuleName } from "@/utils/rule/consts";
import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";
import { camelCase } from "lodash";
import { getEmailUrlForMessage } from "@/utils/url";
import { createEmailProvider } from "@/utils/email/provider";
import { sleep } from "@/utils/sleep";

Expand Down Expand Up @@ -129,6 +130,7 @@ async function sendEmail({
items: {
select: {
messageId: true,
threadId: true,
content: true,
action: {
select: {
Expand Down Expand Up @@ -246,10 +248,17 @@ async function sendEmail({
storedDigestContentSchema.safeParse(parsedContent);

if (contentResult.success) {
const emailUrl = getEmailUrlForMessage(
message,
emailAccount.account.provider,
emailAccount.email,
);

acc[ruleNameKey].push({
content: contentResult.data.content,
from: extractNameFromEmail(message?.headers?.from || ""),
subject: message?.headers?.subject || "",
emailUrl,
});
} else {
logger.warn("Failed to validate digest content structure", {
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/api/resend/digest/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const digestItemSchema = z.object({
from: z.string(),
subject: z.string(),
content: z.string(),
emailUrl: z.string().optional(),
});

const digestSchema = z.record(z.string(), z.array(digestItemSchema).optional());
Expand Down
70 changes: 35 additions & 35 deletions apps/web/components/EmailMessageCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,22 @@ import {
AWAITING_REPLY_LABEL_NAME,
} from "@/utils/reply-tracker/consts";
import { isGoogleProvider } from "@/utils/email/provider-types";
import type { ParsedMessage } from "@/utils/types";

export function EmailMessageCell({
sender,
message,
userEmail,
subject,
snippet,
threadId,
messageId,
hideViewEmailButton,
labelIds,
filterReplyTrackerLabels,
}: {
sender: string;
message: ParsedMessage;
userEmail: string;
subject: string;
snippet: string;
threadId: string;
messageId: string;
hideViewEmailButton?: boolean;
labelIds?: string[];
filterReplyTrackerLabels?: boolean;
}) {
const { id: messageId, threadId, headers, snippet, labelIds } = message;
const sender = headers?.from || "";
const subject = headers?.subject || "";
const { userLabels } = useEmail();
const { provider } = useAccount();

Expand Down Expand Up @@ -97,12 +91,7 @@ export function EmailMessageCell({
<>
<Link
className="ml-2 hover:text-foreground"
href={getEmailUrlForMessage(
messageId,
threadId,
userEmail,
provider,
)}
href={getEmailUrlForMessage(message, provider, userEmail)}
target="_blank"
>
<ExternalLinkIcon className="h-4 w-4" />
Expand Down Expand Up @@ -148,21 +137,32 @@ export function EmailMessageCellWithData({

const firstMessage = data?.thread.messages?.[0];

return (
<EmailMessageCell
sender={sender}
userEmail={userEmail}
subject={
error
? "Error loading email"
: isLoading
? "Loading email..."
: firstMessage?.headers.subject || ""
}
snippet={error ? "" : isLoading ? "" : firstMessage?.snippet || ""}
threadId={threadId}
messageId={messageId}
labelIds={firstMessage?.labelIds}
/>
);
// Construct a message object for the component
const message: ParsedMessage = {
id: messageId,
threadId,
historyId: firstMessage?.historyId || "",
inline: firstMessage?.inline || [],
subject: error
? "Error loading email"
: isLoading
? "Loading email..."
: firstMessage?.headers.subject || "",
date: firstMessage?.headers.date || "",
headers: {
from: sender,
to: firstMessage?.headers.to || "",
subject: error
? "Error loading email"
: isLoading
? "Loading email..."
: firstMessage?.headers.subject || "",
date: firstMessage?.headers.date || "",
},
snippet: error ? "" : isLoading ? "" : firstMessage?.snippet || "",
labelIds: firstMessage?.labelIds,
weblink: firstMessage?.weblink,
};

return <EmailMessageCell message={message} userEmail={userEmail} />;
}
7 changes: 4 additions & 3 deletions apps/web/utils/outlook/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export async function queryBatchMessages(
.getClient()
.api("/me/messages")
.select(
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId",
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId,webLink",
)
.top(maxResults);

Expand Down Expand Up @@ -347,7 +347,7 @@ export async function queryMessagesWithFilters(
.getClient()
.api("/me/messages")
.select(
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId",
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId,webLink",
)
.top(maxResults);

Expand Down Expand Up @@ -419,7 +419,7 @@ export async function getMessage(
.getClient()
.api(`/me/messages/${messageId}`)
.select(
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId",
"id,conversationId,conversationIndex,subject,bodyPreview,from,sender,toRecipients,receivedDateTime,isDraft,isRead,body,categories,parentFolderId,webLink",
)
.get();

Expand Down Expand Up @@ -487,5 +487,6 @@ export function convertMessage(
historyId: "",
inline: [],
conversationIndex: message.conversationIndex,
weblink: message.webLink,
};
}
1 change: 1 addition & 0 deletions apps/web/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ParsedMessage {
date: string;
conversationIndex?: string | null;
internalDate?: string | null;
weblink?: string;
}

export interface Attachment {
Expand Down
Loading
Loading