Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): list a calendar invitation once in View your day (#9060)

gbirmand3ae55ca1777
diff --git a/apps/web/src/features/email-thread/calendar-invitation-day.test.tsx b/apps/web/src/features/email-thread/calendar-invitation-day.test.tsx
new file mode 100644
index 0000000000..1be751a5a2
--- /dev/null
+++ b/apps/web/src/features/email-thread/calendar-invitation-day.test.tsx
@@ -0,0 +1,252 @@
+import {
+ DEFAULT_GUEST_POLICY,
+ NO_VIEWER_CAPABILITIES,
+} from '@app/features/calendar/types';
+import type { CalendarOccurrenceItem } from '@service-storage/generated/schemas/calendarOccurrenceItem';
+import type { EventTime } from '@service-storage/generated/schemas/eventTime';
+import { cleanup, render, screen, within } from '@solidjs/testing-library';
+import type { JSX } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import {
+ type CalendarInvitation,
+ invitationSchedule,
+} from '../email-message/core/calendar-invitation';
+import { invitationFixture } from '../email-message/core/calendar-invitation-fixtures';
+import { CalendarInvitationDay } from './calendar-invitation-day';
+
+const day = vi.hoisted(() => ({
+ state: 'success' as 'loading' | 'paused' | 'success' | 'error',
+ items: [] as CalendarOccurrenceItem[],
+}));
+vi.mock('@queries/calendar/occurrences', () => ({
+ createCalendarOccurrenceQueryRange: (start: Date, end: Date) => ({
+ start: start.toISOString(),
+ end: end.toISOString(),
+ startDate: '2026-09-24',
+ endDate: '2026-09-25',
+ }),
+ useCalendarOccurrencesQuery: () => ({
+ get isPending() {
+ return day.state === 'loading' || day.state === 'paused';
+ },
+ get isLoading() {
+ return day.state === 'loading';
+ },
+ get isSuccess() {
+ return day.state === 'success';
+ },
+ get isError() {
+ return day.state === 'error';
+ },
+ get data() {
+ if (day.state !== 'success')
+ throw new Error('Unsettled resource must not be read');
+ return { items: day.items, syncStatus: 'synced' };
+ },
+ }),
+}));
+vi.mock('@core/context/user', () => ({ useUserId: () => () => 'viewer' }));
+vi.mock('@ui', () => ({
+ Button: (props: JSX.ButtonHTMLAttributes<HTMLButtonElement>) => (
+ <button {...props} />
+ ),
+}));
+afterEach(() => {
+ cleanup();
+ day.state = 'success';
+ day.items = [];
+});
+
+function occurrence(
+ id: string,
+ title: string,
+ startsAt: string,
+ endsAt: string
+): CalendarOccurrenceItem {
+ const time = {
+ kind: 'timed' as const,
+ startsAt,
+ endsAt,
+ timeZone: 'America/Los_Angeles',
+ };
+ return {
+ event: {
+ id,
+ ownerId: 'viewer',
+ icalUid: `${id}@example.com`,
+ title,
+ attendees: [],
+ recurrenceLines: [],
+ sequence: 0,
+ status: 'confirmed',
+ isReadOnly: false,
+ guestPolicy: DEFAULT_GUEST_POLICY,
+ isSnapshot: false,
+ viewerCan: NO_VIEWER_CAPABILITIES,
+ time,
+ transparency: 'opaque',
+ visibility: 'default',
+ createdAt: '2026-09-19T00:00:00Z',
+ updatedAt: '2026-09-19T00:00:00Z',
+ },
+ occurrence: {
+ eventId: id,
+ occurrenceKey: startsAt,
+ isCancelled: false,
+ time,
+ },
+ };
+}
+
+const ownCopy = occurrence(
+ 'own-copy',
+ 'Product review',
+ '2026-09-24T17:00:00Z',
+ '2026-09-24T17:30:00Z'
+);
+/** The viewer's copy, moved to another time shape on the same day. */
+const ownCopyAt = (time: EventTime): CalendarOccurrenceItem => ({
+ event: { ...ownCopy.event, time },
+ occurrence: { ...ownCopy.occurrence, time },
+});
+const allDayInvitation: CalendarInvitation = {
+ ...invitationFixture,
+ start: { kind: 'date', value: '2026-09-24' },
+ end: { kind: 'date', value: '2026-09-25' },
+};
+const standup = occurrence(
+ 'standup',
+ 'Standup',
+ '2026-09-24T16:00:00Z',
+ '2026-09-24T16:15:00Z'
+);
+
+/** The invitation's time as the agenda writes it, in this machine's zone. */
+const invitationTime = (invitation: CalendarInvitation) =>
+ invitationSchedule(
+ invitation,
+ true,
+ Intl.DateTimeFormat().resolvedOptions().timeZone
+ ).when;
+
+function renderDay(invitation: CalendarInvitation = invitationFixture) {
+ render(() => (
+ <CalendarInvitationDay
+ invitation={invitation}
+ eventId={ownCopy.event.id}
+ occurrenceKey={ownCopy.occurrence.occurrenceKey}
+ hour12
+ onClose={() => {}}
+ />
+ ));
+ return screen.getByRole('region', { name: 'Your day' });
+}
+
+describe('CalendarInvitationDay', () => {
+ it('shows the invitation once, as the viewer’s copy in its time slot', () => {
+ day.items = [standup, ownCopy];
+ const agenda = renderDay();
+ const rows = within(agenda).getAllByRole('listitem');
+ expect(rows.map((row) => row.textContent)).toEqual([
+ expect.stringContaining('Standup'),
+ expect.stringContaining('Product review'),
+ ]);
+ expect(within(rows[1]).getByText('This invitation')).toBeTruthy();
+ expect(within(agenda).getAllByText('This invitation')).toHaveLength(1);
+ expect(agenda.textContent).not.toContain(invitationTime(invitationFixture));
+ });
+
+ it('keeps a newer email’s time above the day when the copy is still at its old time', () => {
+ day.items = [standup, ownCopy];
+ const moved: CalendarInvitation = {
+ ...invitationFixture,
+ start: {
+ kind: 'zoned',
+ value: '2026-09-24T18:00:00Z',
+ time_zone: 'America/Los_Angeles',
+ },
+ end: {
+ kind: 'zoned',
+ value: '2026-09-24T18:30:00Z',
+ time_zone: 'America/Los_Angeles',
+ },
+ };
+ const agenda = renderDay(moved);
+ const line = within(agenda).getByText('This invitation').closest('p');
+ expect(line?.textContent).toContain(invitationTime(moved));
+ const rows = within(agenda).getAllByRole('listitem');
+ expect(rows[1]?.textContent).toContain('Product review');
+ expect(rows[1]?.classList.contains('bg-accent-bg')).toBe(true);
+ expect(within(agenda).getAllByText('This invitation')).toHaveLength(1);
+ });
+
+ it('shows an all-day invitation once, as its all-day copy', () => {
+ day.items = [
+ ownCopyAt({
+ kind: 'allDay',
+ startDate: '2026-09-24',
+ endDate: '2026-09-25',
+ }),
+ ];
+ const agenda = renderDay(allDayInvitation);
+ const [row] = within(agenda).getAllByRole('listitem');
+ expect(row?.textContent).toContain('All day');
+ expect(within(agenda).getAllByText('This invitation')).toHaveLength(1);
+ expect(row && within(row).getByText('This invitation')).toBeTruthy();
+ });
+
+ it('keeps an all-day invitation’s time above a timed copy over the same day', () => {
+ day.items = [
+ ownCopyAt({
+ kind: 'timed',
+ startsAt: new Date('2026-09-24T00:00:00').toISOString(),
+ endsAt: new Date('2026-09-25T00:00:00').toISOString(),
+ timeZone: 'America/Los_Angeles',
+ }),
+ ];
+ const agenda = renderDay(allDayInvitation);
+ const line = within(agenda).getByText('This invitation').closest('p');
+ expect(line?.textContent).toContain(invitationTime(allDayInvitation));
+ const [row] = within(agenda).getAllByRole('listitem');
+ expect(row?.classList.contains('bg-accent-bg')).toBe(true);
+ expect(within(agenda).getAllByText('This invitation')).toHaveLength(1);
+ });
+
+ it('keeps the invitation’s time above the day while its copy is not listed', () => {
+ day.items = [standup];
+ const agenda = renderDay();
+ const line = within(agenda).getByText('This invitation').closest('p');
+ expect(line?.textContent).toContain(invitationTime(invitationFixture));
+ expect(within(agenda).getAllByRole('listitem')).toHaveLength(1);
+ });
+
+ it('waits for the day before placing the invitation', () => {
+ day.state = 'loading';
+ const agenda = renderDay();
+ expect(within(agenda).getByRole('status').textContent).toBe(
+ 'Loading calendar…'
+ );
+ expect(within(agenda).queryByText('This invitation')).toBeNull();
+ });
+
+ it('shows the invitation’s time while the day cannot load offline', () => {
+ day.state = 'paused';
+ const agenda = renderDay();
+ expect(
+ within(agenda).getByText('This invitation').closest('p')?.textContent
+ ).toContain(invitationTime(invitationFixture));
+ });
+
+ it('shows the invitation’s time when the calendar is unavailable', () => {
+ day.state = 'error';
+ const agenda = renderDay();
+ expect(
+ within(agenda).getByText('This invitation').closest('p')?.textContent
+ ).toContain(invitationTime(invitationFixture));
+ expect(
+ within(agenda).getByText(
+ 'Calendar unavailable. Conflicts could not be checked.'
+ )
+ ).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/features/email-thread/calendar-invitation-day.tsx b/apps/web/src/features/email-thread/calendar-invitation-day.tsx
index f94abb8af4..ae760b88f0 100644
--- a/apps/web/src/features/email-thread/calendar-invitation-day.tsx
+++ b/apps/web/src/features/email-thread/calendar-invitation-day.tsx
@@ -3,15 +3,24 @@ import {
createCalendarOccurrenceQueryRange,
useCalendarOccurrencesQuery,
} from '@queries/calendar/occurrences';
+import type { CalendarOccurrenceItem } from '@service-storage/generated/schemas/calendarOccurrenceItem';
import { Button } from '@ui';
import { For, Show } from 'solid-js';
import {
type CalendarInvitation,
invitationSchedule,
} from '../email-message/core/calendar-invitation';
-import { invitationConflicts } from './queries/invitation-conflict';
+import {
+ invitationConflicts,
+ occurrenceAtInvitationTime,
+} from './queries/invitation-conflict';
-/** A local-day agenda using the same occurrence cache as the calendar. */
+/**
+ * A local-day agenda using the same occurrence cache as the calendar. The
+ * viewer's own copy of the event, at the invitation's time, is the
+ * invitation's row in its time slot; the invitation's own time stands above
+ * the list only while no such row is in it.
+ */
export function CalendarInvitationDay(props: {
invitation: CalendarInvitation;
eventId: string;
@@ -38,6 +47,13 @@ export function CalendarInvitationDay(props: {
range: range(),
}));
const data = () => (query.isSuccess ? query.data : undefined);
+ const items = () => data()?.items.slice(0, 20);
+ const isEvent = (item: CalendarOccurrenceItem) =>
+ item.event.id === props.eventId &&
+ item.occurrence.occurrenceKey === props.occurrenceKey;
+ const isInvitation = (item: CalendarOccurrenceItem) =>
+ isEvent(item) && occurrenceAtInvitationTime(props.invitation, item);
+ const invitationListed = () => items()?.some(isInvitation) ?? false;
const label = (value: string) =>
new Intl.DateTimeFormat(undefined, {
hour: 'numeric',
@@ -55,16 +71,18 @@ export function CalendarInvitationDay(props: {
Close
</Button>
</div>
- <p class="my-3 rounded-md bg-accent-bg p-3 text-ink">
- <span class="mr-2 font-medium">This invitation</span>
- {
- invitationSchedule(
- props.invitation,
- props.hour12,
- Intl.DateTimeFormat().resolvedOptions().timeZone
- ).when
- }
- </p>
+ <Show when={!query.isLoading && !invitationListed()}>
+ <p class="my-3 rounded-md bg-accent-bg p-3 text-ink">
+ <span class="mr-2 font-medium">This invitation</span>
+ {
+ invitationSchedule(
+ props.invitation,
+ props.hour12,
+ Intl.DateTimeFormat().resolvedOptions().timeZone
+ ).when
+ }
+ </p>
+ </Show>
<Show
when={range()}
fallback={
@@ -91,16 +109,12 @@ export function CalendarInvitationDay(props: {
>
<p>No events found for this day.</p>
</Show>
- <ul class="flex flex-col gap-2">
- <For each={data()?.items.slice(0, 20)}>
+ <ul class="mt-3 flex flex-col gap-2">
+ <For each={items()}>
{(item) => (
<li
class="rounded-md p-2 [overflow-wrap:anywhere]"
- classList={{
- 'bg-accent-bg':
- item.event.id === props.eventId &&
- item.occurrence.occurrenceKey === props.occurrenceKey,
- }}
+ classList={{ 'bg-accent-bg': isEvent(item) }}
>
<span class="mr-3 text-ink-muted">
{item.occurrence.time.kind === 'timed'
@@ -108,6 +122,9 @@ export function CalendarInvitationDay(props: {
: 'All day'}
</span>
{item.event.title}
+ <Show when={isInvitation(item)}>
+ <span class="ml-2 font-medium">This invitation</span>
+ </Show>
<Show when={invitationConflicts(props.invitation, item, props)}>
<span class="ml-2 text-ink-muted">
Overlaps this invitation
diff --git a/apps/web/src/features/email-thread/queries/invitation-conflict.ts b/apps/web/src/features/email-thread/queries/invitation-conflict.ts
index c546e02adc..04f839224d 100644
--- a/apps/web/src/features/email-thread/queries/invitation-conflict.ts
+++ b/apps/web/src/features/email-thread/queries/invitation-conflict.ts
@@ -12,6 +12,39 @@ const instant = (value: InvitationDateTime | null | undefined) => {
return Number.isFinite(date.getTime()) ? date.getTime() : undefined;
};
+const occurrenceBounds = (item: CalendarOccurrenceItem) => {
+ const time = item.occurrence.time;
+ return {
+ start: new Date(
+ time.kind === 'timed' ? time.startsAt : `${time.startDate}T00:00:00`
+ ).getTime(),
+ end: new Date(
+ time.kind === 'timed' ? time.endsAt : `${time.endDate}T00:00:00`
+ ).getTime(),
+ };
+};
+
+/**
+ * The occurrence is at the invitation's own time, so it can stand for the
+ * invitation; a proposal or a newer email than the calendar has its own time.
+ */
+export function occurrenceAtInvitationTime(
+ invitation: CalendarInvitation,
+ item: CalendarOccurrenceItem
+): boolean {
+ const start = instant(invitation.start);
+ if (start === undefined) return false;
+ // An all-day invitation and a timed copy from midnight to midnight span the
+ // same instants but are different times.
+ const allDay = invitation.start?.kind === 'date';
+ if (allDay !== (item.occurrence.time.kind === 'allDay')) return false;
+ const end = instant(invitation.end);
+ const occurrence = occurrenceBounds(item);
+ return (
+ start === occurrence.start && (end === undefined || end === occurrence.end)
+ );
+}
+
/** Availability uses busy, noncancelled, nondeclined occurrences and exclusive ends. */
export function invitationConflicts(
invitation: CalendarInvitation,
@@ -32,12 +65,6 @@ export function invitationConflicts(
const start = instant(invitation.start);
const end = instant(invitation.end);
if (start === undefined || end === undefined) return false;
- const time = item.occurrence.time;
- const otherStart = new Date(
- time.kind === 'timed' ? time.startsAt : `${time.startDate}T00:00:00`
- ).getTime();
- const otherEnd = new Date(
- time.kind === 'timed' ? time.endsAt : `${time.endDate}T00:00:00`
- ).getTime();
- return start < otherEnd && end > otherStart;
+ const other = occurrenceBounds(item);
+ return start < other.end && end > other.start;
}
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index d3a374500f..bef30d9dc7 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -1435,8 +1435,13 @@ action is unavailable.
Calendar split that is already open; otherwise a click replaces the email with Calendar and a
shift-click opens Calendar in a new split beside it, from the inline card and the `.ics` dialog.
`View your day` opens a compact agenda without changing the active split; Close returns
-focus to its trigger. Busy overlapping events are labeled, while cancelled, declined,
-and free events do not count as conflicts. Calendar 12/24-hour preferences apply to
+focus to its trigger. The event appears once, as the viewer's own copy in its time slot,
+highlighted and marked `This invitation` (also on a shared event's card after `Add to
+calendar`). A `This invitation` line with the email's own time stands above the list
+instead while no such row is there: an unreadable time, the calendar unavailable, offline or
+syncing, the copy past the first 20 events, or an email whose time differs from the copy
+(a proposal, or an update the calendar has not synced yet; the copy stays highlighted). Busy overlapping events are labeled, while
+cancelled, declined, and free events do not count as conflicts. Calendar 12/24-hour preferences apply to
already-open invitation cards as well as the calendar view.
For a writable Outlook event you organize, the editor's `Replace event…` action