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
Original file line number Diff line number Diff line change
Expand Up @@ -219,42 +219,48 @@ export function EntityWithEverything(

const EntityTitle = () => {
if (props.entity.type === 'email') {
const macroDisplayNames =
props.entity.participantEmails?.map((email) => {
return useDisplayName(emailToId(email))[0];
}) ?? [];
const isLikelyEmail = (value?: string) =>
typeof value === 'string' && value.includes('@');

const combinedParticipantFirstNames = createMemo(() => {
if (props.entity.type !== 'email') return [];
const me = userEmail();
const participantNames = props.entity.participantNames ?? [];
if (
props.entity.participants?.length === 1 &&
props.entity.participants?.[0].email === me
) {
return ['me'];
}
const namesSet = new Set<string>();
props.entity.participantEmails?.forEach((email, idx) => {
if (me && email === me) return;
const macroFirstName = macroDisplayNames[idx]?.().split(' ')[0];
const participantFirstName = participantNames[idx].split(' ')[0];

props.entity.participants?.forEach((participant) => {
if (!participant.email) return;
if (me && participant.email === me) return;
const macroDisplayName = useDisplayName(
emailToId(participant.email)
)[0]?.();
const macroFirstName = macroDisplayName?.split(' ')[0];
const participantFirstName = participant.name?.split(' ')[0] ?? '';
if (macroFirstName && !isLikelyEmail(macroFirstName)) {
namesSet.add(macroFirstName);
} else if (
isLikelyEmail(macroFirstName) &&
participantFirstName &&
!isLikelyEmail(participantFirstName)
) {
namesSet.add(participantFirstName);
} else {
namesSet.add(email.split('@')[0]);
const emailName = participant.email.split('@')[0];
namesSet.add(emailName);
}
});
return Array.from(namesSet);
});

const displayedNames = () => {
const names = combinedParticipantFirstNames();
if (names.length <= 3 && names.length > 0) return names.join(', ');
if (names.length > 3)
return `${names[0]} .. ${names[names.length - 2]}, ${names[names.length - 1]}`;
return undefined;
if (!names || names.length === 0) return undefined;
if (names.length <= 3) return names.join(', ');
return `${names[0]} .. ${names[names.length - 2]}, ${names[names.length - 1]}`;
};

return (
Expand Down
6 changes: 6 additions & 0 deletions js/app/packages/macro-entity/src/queries/dss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ const selectData: (
}

if (item.tag === 'emailThread') {
const participants = item.data.participants?.map((p) => ({
email: p.emailAddress ?? '',
name: p.name ?? '',
}));

return {
...item.data,
senderEmail: item.data.senderEmail ?? undefined,
Expand All @@ -266,6 +271,7 @@ const selectData: (
name: item.data.name || 'Email Thread',
frecencyScore: item.frecency_score,
viewedAt: item.data.viewedAt ?? undefined,
participants,
};
}

Expand Down
11 changes: 5 additions & 6 deletions js/app/packages/macro-entity/src/queries/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export function createEmailsInfiniteQuery(
select: (data) =>
data.pages.flatMap(({ items }) =>
items.map((email): EmailEntity => {
const participantEmails = email.contacts.map(
(p) => p.emailAddress ?? ''
);
const participantNames = email.contacts.map((p) => p.name ?? '');
const participants = email.contacts.map((p) => ({
email: p.emailAddress ?? '',
name: p.name ?? '',
}));

return {
...email,
Expand All @@ -91,8 +91,7 @@ export function createEmailsInfiniteQuery(
snippet: email.snippet ?? undefined,
isImportant: email.isImportant ?? false,
done: !email.inboxVisible,
participantEmails,
participantNames,
participants,
senderEmail: email.senderEmail ?? undefined,
senderName: email.senderName ?? email.senderEmail ?? undefined,
};
Expand Down
3 changes: 1 addition & 2 deletions js/app/packages/macro-entity/src/types/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export type EmailEntity = EntityBase & {
snippet?: string;
isImportant: boolean;
done: boolean;
participantEmails?: string[];
participantNames?: string[];
participants?: Array<{ email: string; name: string }>;
senderEmail?: string;
senderName?: string;
};
Expand Down