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(calendar): clear unread reminders when opening events (#8528)

gbirmanf2348b064b1c
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 6c6281dfce..8deb0b4219 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -147,6 +147,9 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
- Add Google Meet account hints only to join actions using the displayed calendar's
connected email; keep stored and copied conference links unchanged. See the
[calendar walkthrough](../../docs/agent-guide/calendar.md).
+- Mark loaded calendar row notifications through the notification source so read
+ dots update immediately and failed writes roll back; grid selections also mark
+ the canonical event read, excluding team projections.
- Route explicit call exits using the server's `callEnded` result: ended calls
open their record; ongoing channel and scheduled calls return to the channel
and Calendar. Preserve the session ID before disconnecting.
diff --git a/apps/web/src/features/calendar-view/calendar-view.tsx b/apps/web/src/features/calendar-view/calendar-view.tsx
index 5151416de2..7ed92344e4 100644
--- a/apps/web/src/features/calendar-view/calendar-view.tsx
+++ b/apps/web/src/features/calendar-view/calendar-view.tsx
@@ -9,9 +9,11 @@ import {
useNavigate,
useParams,
} from '@app/lib/split-router';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import { useUserId } from '@core/context/user';
import { fireAndForget } from '@core/util/fireAndForget';
+import { markNotificationsForEntityAsRead } from '@notifications/notification-helpers';
import { useCalendarOccurrencesQuery } from '@queries/calendar/occurrences';
import deepEqual from 'fast-deep-equal';
import {
@@ -56,6 +58,7 @@ export function CalendarView(props: CalendarViewProps) {
const posthog = usePosthog();
const userId = useUserId();
const analytics = useAnalytics();
+ const notificationSource = useGlobalNotificationSource();
const panel = useSplitPanelOrThrow();
const navigate = useNavigate();
const routeParams = useParams<{ period: CalendarPeriodView }>();
@@ -189,8 +192,19 @@ export function CalendarView(props: CalendarViewProps) {
if (!next) return;
const landed = next === aimingEventId;
aimingEventId = undefined;
+ // List activation already marks its row; landing must not send a second
+ // overlapping read write that could interfere with optimistic rollback.
if (landed) return;
}
+ if (eventId) {
+ fireAndForget(
+ markNotificationsForEntityAsRead(notificationSource, {
+ type: 'calendar_event',
+ id: eventId,
+ }),
+ 'calendar-notification-read'
+ );
+ }
// Inline, a dismissed popover is not a destination change: the host's
// selection still names this event, and clearing it would make the next
// request for the same event a navigation.
diff --git a/apps/web/src/features/calendar/mark-event-notifications-seen.ts b/apps/web/src/features/calendar/mark-event-notifications-seen.ts
new file mode 100644
index 0000000000..31dc3045da
--- /dev/null
+++ b/apps/web/src/features/calendar/mark-event-notifications-seen.ts
@@ -0,0 +1,30 @@
+import {
+ type EntityWithRawNotifications,
+ getEntityNotifications,
+} from '@app/features/soup/entity-notifications';
+import { fireAndForget } from '@core/util/fireAndForget';
+import type { EntityData } from '@entity/types/entity';
+import { notificationIsRead } from '@entity/utils/notification';
+import { markNotificationsForEntityAsRead } from '@notifications/notification-helpers';
+import type { NotificationSource } from '@notifications/notification-source';
+
+/** Clear the reminders shown by the row before its calendar view opens. */
+export function markCalendarNotificationSeenOnOpen(
+ entity: EntityWithRawNotifications<EntityData>,
+ notificationSource: NotificationSource
+) {
+ if (entity.type !== 'calendar_event') return;
+ const notifications = getEntityNotifications(
+ entity,
+ notificationSource
+ ).filter((notification) => !notificationIsRead(notification));
+ fireAndForget(
+ notifications.length > 0
+ ? notificationSource.bulkMarkAsRead(notifications)
+ : markNotificationsForEntityAsRead(notificationSource, {
+ type: entity.type,
+ id: entity.id,
+ }),
+ 'calendar-notification-read'
+ );
+}
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index c372ea6040..e0a899190d 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -87,7 +87,6 @@ import {
getChannelNotificationParams,
getDocumentCommentLocation,
getDocumentCommentNotification,
- markNotificationsForEntityAsReadInBackground,
type NotificationSource,
notificationIsRead,
setDoneOverride,
@@ -888,21 +887,7 @@ export function markChannelNotificationsSeenOnOpen(
});
}
-/** Mark calendar-event notifications seen when opening their occurrence. */
-export function markCalendarNotificationSeenOnOpen(
- entity: EntityData,
- notificationSource: NotificationSource
-) {
- // Calendar events open a component split without a block to clear notifications.
- if (entity.type !== 'calendar_event') return;
- fireAndForget(
- markNotificationsForEntityAsReadInBackground(notificationSource, {
- type: entity.type,
- id: entity.id,
- }),
- 'open-entity-in-split'
- );
-}
+export { markCalendarNotificationSeenOnOpen } from '../calendar/mark-event-notifications-seen';
/**
* The event and instance a calendar row points at, resolved exactly as the
diff --git a/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts b/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts
new file mode 100644
index 0000000000..350cde43cf
--- /dev/null
+++ b/apps/web/src/features/notifications/tests/calendar-notification-read.test.ts
@@ -0,0 +1,188 @@
+import { markCalendarNotificationSeenOnOpen } from '@app/features/calendar/mark-event-notifications-seen';
+import { withEntityNotifications } from '@app/features/soup/entity-notifications';
+import type { CalendarEventEntity } from '@entity/types/entity';
+import { unreadFilterFn } from '@entity/utils/filter';
+import { Telemetry } from '@macro-inc/observability';
+import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';
+import { createRoot } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { createNotificationSource } from '../notification-source';
+import type { UnifiedNotification } from '../types';
+
+const mocks = vi.hoisted(() => ({
+ seen: vi.fn(),
+ entitySeen: vi.fn(),
+ feed: vi.fn(() => []),
+}));
+
+vi.mock('@core/constant/featureFlags', () => ({
+ ENABLE_DOCUMENT_MENTION_NOTIFICATIONS: true,
+ enableGraphqlSoup: { key: 'enable-graphql-soup' },
+ isFeatureEnabled: () => true,
+}));
+vi.mock('@macro-inc/collaboration/websocket', () => ({
+ createSocketEffect: vi.fn(),
+}));
+vi.mock('@queries/notification/user-notifications', () => ({
+ optimisticInsertNotification: vi.fn(),
+ useMarkNotificationsAsSeenMutation: () => ({ mutateAsync: mocks.seen }),
+ useMarkNotificationsAsDoneMutation: () => ({ mutateAsync: vi.fn() }),
+ useUserNotificationsQuery: () => ({
+ transport: 'graphql',
+ isLoading: false,
+ get data() {
+ return mocks.feed();
+ },
+ }),
+}));
+vi.mock('@queries/notification/notification-soup', () => ({
+ updateSoupForNotification: vi.fn(),
+}));
+vi.mock('@queries/notification/unsubscribes', () => ({
+ useMuteItemMutation: () => ({ mutateAsync: vi.fn() }),
+ useUnmuteItemMutation: () => ({ mutateAsync: vi.fn() }),
+}));
+vi.mock('@queries/notification/entity-mutations', () => ({
+ toNotificationEntityRef: vi.fn(() => ({
+ type: 'calendar_event',
+ id: 'event',
+ })),
+ updateNotificationsForEntities: mocks.entitySeen,
+}));
+vi.mock('@service-storage/graphql-soup', () => ({
+ mapGraphqlNotification: (value: unknown) => value,
+}));
+vi.mock('@service-storage/graphql-soup-websocket', () => ({
+ subscribeToGraphqlNotificationPatches: () => () => {},
+}));
+vi.mock('../queries/muted-entities-query', () => ({
+ createMutedEntitiesQuery: () => ({ isPending: true }),
+}));
+
+const event: CalendarEventEntity = {
+ type: 'calendar_event',
+ id: 'event',
+ name: 'Prod Deploy',
+ ownerId: 'owner',
+ status: 'confirmed',
+ isReadOnly: false,
+};
+const reminder: UnifiedNotification = {
+ id: 'reminder',
+ entity_id: event.id,
+ entity_type: 'calendar_event',
+ state: 'unseen',
+ notification_event_type: 'calendar_event_reminder',
+ notification_metadata: {
+ tag: 'calendar_event_reminder',
+ content: {
+ eventId: event.id,
+ title: event.name,
+ startsAt: '2026-10-22T18:00:00Z',
+ endsAt: '2026-10-22T18:30:00Z',
+ occurrenceKey: '2026-10-22T18:00:00Z',
+ minutesBefore: 60,
+ },
+ },
+ created_at: '2026-10-22T17:00:00Z',
+ updated_at: '2026-10-22T17:00:00Z',
+ viewed_at: null,
+ sent: true,
+};
+
+afterEach(() => vi.restoreAllMocks());
+
+describe('opening calendar notifications', () => {
+ it('reports a failed entity read when the row has no loaded notifications', async () => {
+ const error = new Error('offline');
+ const reported = Promise.withResolvers<void>();
+ const telemetry = vi
+ .spyOn(Telemetry, 'error')
+ .mockImplementation(() => reported.resolve());
+ mocks.entitySeen.mockRejectedValueOnce(error);
+ const { source, dispose } = createRoot((dispose) => ({
+ source: createNotificationSource({} as ConnectionGatewayWebsocket),
+ dispose,
+ }));
+ try {
+ markCalendarNotificationSeenOnOpen(
+ { ...event, notifications: [] },
+ source
+ );
+ await reported.promise;
+ expect(telemetry).toHaveBeenCalledWith(error, {
+ surface: 'calendar-notification-read',
+ });
+ } finally {
+ dispose();
+ }
+ });
+
+ it.each(['array', 'accessor'] as const)(
+ 'clears an attached %s before the write finishes without loading the global feed',
+ async (shape) => {
+ mocks.feed.mockClear();
+ const pending = Promise.withResolvers<void>();
+ mocks.seen.mockReturnValueOnce(pending.promise);
+ const { source, dispose } = createRoot((dispose) => ({
+ source: createNotificationSource({} as ConnectionGatewayWebsocket),
+ dispose,
+ }));
+ const attached = [
+ { ...reminder, id: `pending-${shape}` },
+ { ...reminder, id: `done-${shape}`, state: 'done' as const },
+ { ...reminder, id: `seen-${shape}`, state: 'seen' as const },
+ ];
+ const row = {
+ ...event,
+ notifications: shape === 'array' ? attached : () => attached,
+ };
+ const rendered = withEntityNotifications(row, source);
+ try {
+ expect(unreadFilterFn(rendered)).toBe(true);
+ markCalendarNotificationSeenOnOpen(row, source);
+ expect(unreadFilterFn(rendered)).toBe(false);
+ expect(mocks.seen).toHaveBeenLastCalledWith({
+ notificationIds: [`pending-${shape}`],
+ });
+ expect(mocks.feed).not.toHaveBeenCalled();
+ pending.resolve();
+ await pending.promise;
+ // A stale list snapshot must not resurrect the dot after success.
+ expect(unreadFilterFn(withEntityNotifications(row, source))).toBe(
+ false
+ );
+ } finally {
+ pending.resolve();
+ dispose();
+ }
+ }
+ );
+
+ it('restores the dot after a failed write and clears it on a retry', async () => {
+ const pending = Promise.withResolvers<void>();
+ const reported = Promise.withResolvers<void>();
+ vi.spyOn(Telemetry, 'error').mockImplementation(() => reported.resolve());
+ mocks.seen.mockReturnValueOnce(pending.promise);
+ const { source, dispose } = createRoot((dispose) => ({
+ source: createNotificationSource({} as ConnectionGatewayWebsocket),
+ dispose,
+ }));
+ const row = withEntityNotifications(
+ { ...event, notifications: [{ ...reminder, id: 'failed-read' }] },
+ source
+ );
+ try {
+ markCalendarNotificationSeenOnOpen(row, source);
+ expect(unreadFilterFn(row)).toBe(false);
+ pending.reject(new Error('offline'));
+ await reported.promise;
+ expect(unreadFilterFn(row)).toBe(true);
+ mocks.seen.mockResolvedValueOnce(undefined);
+ markCalendarNotificationSeenOnOpen(row, source);
+ expect(unreadFilterFn(row)).toBe(false);
+ } finally {
+ dispose();
+ }
+ });
+});
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index d53b77315c..792f443ac5 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -32,6 +32,11 @@ that path. Calendar navigation defaults to Day on phones and Week on desktop; th
recent choice is remembered locally for navigation that does not specify a period. An
opened event is reflected in the pane-owned `sN.calendar.eventId` search parameter.
+Opening a calendar row in Home clears its loaded reminder dots immediately;
+failed read writes restore them. Opening event details directly from the grid
+also marks the event's notifications read. Verify both on desktop and mobile,
+including a delayed read response and a failed write followed by another click.
+
Period selection updates its label and route immediately. The active grid redraws
on a deferred task; hidden neighboring periods follow on separate tasks. Calendar
grids stay mounted and undimmed while occurrences load. An uncached range never