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(web): clear channel soup notifications on open (#6028)

Sean Aye6a6f5c7c64db
diff --git a/apps/web/src/components/app/split-layout/components/SplitHeader.tsx b/apps/web/src/components/app/split-layout/components/SplitHeader.tsx
index e0edd3ce93..43198a0088 100644
--- a/apps/web/src/components/app/split-layout/components/SplitHeader.tsx
+++ b/apps/web/src/components/app/split-layout/components/SplitHeader.tsx
@@ -2,6 +2,7 @@ import { isListViewID, LIST_VIEW_ID } from '@app/constants/list-views';
import { useSoup } from '@app/features/next-soup/soup-context';
import { openEntityInSplitFromUnifiedList } from '@app/features/next-soup/utils';
import { CALENDAR_BLOCK_ID } from '@block-calendar/types';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { useSidebarCollapse } from '@components/app/sidebarVisibility';
import type { BlockName } from '@core/block';
import {
@@ -224,6 +225,7 @@ function SplitCloseButton() {
function SoupNavigationButtons() {
const context = useContext(SplitPanelContext);
const soup = useSoup();
+ const notificationSource = useGlobalNotificationSource();
if (!context) return null;
const rows = createMemo(() => soup.rows());
@@ -266,6 +268,7 @@ function SoupNavigationButtons() {
splitHandle: context.handle,
mergeHistory: true,
referredFrom: navigationReferredFrom(),
+ notificationSource,
});
};
@@ -461,6 +464,7 @@ export function SplitHeader(props: {
collapseController: PriorityCollapseController;
}) {
const panel = useContext(SplitPanelContext);
+ const notificationSource = useGlobalNotificationSource();
if (!panel) {
throw new Error('<SplitHeader> must be used within a <SplitLayout>');
}
@@ -497,6 +501,7 @@ export function SplitHeader(props: {
void openEntityInSplitFromUnifiedList(data, {
splitHandle: panel.handle,
allowDuplicate: true,
+ notificationSource,
});
});
diff --git a/apps/web/src/features/dynamic-ui/widgets/List.tsx b/apps/web/src/features/dynamic-ui/widgets/List.tsx
index aa1d59f993..0d32ea04f9 100644
--- a/apps/web/src/features/dynamic-ui/widgets/List.tsx
+++ b/apps/web/src/features/dynamic-ui/widgets/List.tsx
@@ -7,6 +7,7 @@ import {
import type { FieldFilters } from '@app/features/next-soup/filters/filter-store/types';
import { soupItemMatchesQuery } from '@app/features/next-soup/filters/query-filters';
import { openEntityInSplitFromUnifiedList } from '@app/features/next-soup/utils';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { ListEntityMetadataQueryProvider } from '@entity';
import { CollapsibleList } from '@entity/components/CollapsibleList';
import { ListEntity, ListLayoutProvider } from '@entity/composed/ListEntity';
@@ -118,11 +119,16 @@ const GROUP_BY_BY_NAME: Record<
* `email` included.
*/
function Row(props: { entity: EntityData }) {
+ const notificationSource = useGlobalNotificationSource();
return (
<ListEntity
entity={props.entity as WithNotification<EntityData>}
hideCheckbox
- onClick={() => openEntityInSplitFromUnifiedList(props.entity, {})}
+ onClick={() =>
+ openEntityInSplitFromUnifiedList(props.entity, {
+ notificationSource,
+ })
+ }
/>
);
}
diff --git a/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts b/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts
index ae918549e4..19ca2d0722 100644
--- a/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts
+++ b/apps/web/src/features/next-soup/actions/make-mark-done-action.test.ts
@@ -77,6 +77,7 @@ const nextEntity = {
type: 'email',
id: 'next',
} as EntityData;
+const notificationSource = {} as NotificationSource;
function createSoup() {
const focusSet = vi.fn();
@@ -107,7 +108,7 @@ function createSoup() {
function createAction() {
return createRoot((dispose) => ({
action: makeMarkDoneAction({
- notificationSource: () => ({}) as NotificationSource,
+ notificationSource: () => notificationSource,
}),
dispose,
}));
@@ -145,6 +146,7 @@ describe('makeMarkDoneAction', () => {
{
splitHandle: mocks.controller as unknown as SplitHandle,
mergeHistory: true,
+ notificationSource,
}
);
dispose();
diff --git a/apps/web/src/features/next-soup/actions/make-mark-done-action.ts b/apps/web/src/features/next-soup/actions/make-mark-done-action.ts
index 90a618823a..bede448d46 100644
--- a/apps/web/src/features/next-soup/actions/make-mark-done-action.ts
+++ b/apps/web/src/features/next-soup/actions/make-mark-done-action.ts
@@ -362,6 +362,7 @@ export const makeMarkDoneAction = (options: MakeMarkDoneOptions) => {
void openEntityInSplitFromUnifiedList(nextRow.original, {
splitHandle: controller,
mergeHistory: true,
+ notificationSource: options.notificationSource(),
});
}
onNavigate?.(nextRow.original);
diff --git a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts b/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts
index 9c595fb092..9b73c06223 100644
--- a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts
+++ b/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts
@@ -131,6 +131,7 @@ export const useBlockEntityCommands = (
splitHandle,
mergeHistory: true,
referredFrom: splitHandle.referredFrom(),
+ notificationSource,
});
};
diff --git a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts
index 74c3b58752..c6bed1301d 100644
--- a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts
+++ b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts
@@ -130,6 +130,7 @@ export const useEntityActionHotkeys = (
splitHandle,
mergeHistory: true,
referredFrom: splitHandle.referredFrom(),
+ notificationSource,
});
};
diff --git a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
index 8e59b70d51..f1fd9dce6a 100644
--- a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
+++ b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
@@ -277,6 +277,7 @@ export function createSoupEntityActions(): {
...options,
splitHandle,
referredFrom: 'entity-actions-menu',
+ notificationSource,
});
};
diff --git a/apps/web/src/features/next-soup/soup-view/soup-view.tsx b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
index 4729f92ad9..1c0f578c55 100644
--- a/apps/web/src/features/next-soup/soup-view/soup-view.tsx
+++ b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
@@ -52,7 +52,7 @@ import { TaskListEntity } from '@app/features/next-soup/soup-view/views/tasks/Ta
import { ResponsiveTaskListHeader } from '@app/features/next-soup/soup-view/views/tasks/TaskListHeader';
import { TaskGroupHeader } from '@app/features/next-soup/soup-view/views/tasks/task-group-header';
import {
- markChannelTargetSeenOnOpen,
+ markChannelNotificationsSeenOnOpen,
markReminderSeenOnOpen,
openEntityInNewTab,
openEntityInSplitFromUnifiedList,
@@ -294,6 +294,7 @@ interface SoupViewProps {
export const SoupView = (props: SoupViewProps) => {
const soup = useSoup();
const panel = useSplitPanelOrThrow();
+ const notificationSource = useGlobalNotificationSource();
const soupView = useSoupView();
const isInboxView = useIsInboxView();
const openFocusedEntityInPreview = () => {
@@ -307,6 +308,7 @@ export const SoupView = (props: SoupViewProps) => {
}
void openEntityInSplitFromUnifiedList(focusedRow.original, {
splitHandle: panel.handle,
+ notificationSource,
});
};
const hasPreviewItems = useSoupPreviewAvailability({
@@ -1000,7 +1002,7 @@ const SoupViewListContent = (props: SoupViewListProps) => {
// Join button (or, in preview, the Viewer's Join prompt) is the only
// affordance.
if (!isNonMemberChannelEntity(entity)) {
- markChannelTargetSeenOnOpen(entity, notificationSource);
+ markChannelNotificationsSeenOnOpen(entity, notificationSource);
openEntityInNewTab({ entity, location });
}
return;
@@ -1027,9 +1029,6 @@ const SoupViewListContent = (props: SoupViewListProps) => {
// Single click: focus the row AND open it in the Preview Pair's Viewer.
// The openWithSplit redirect keeps the Viewer unfocused so keyboard
// navigation stays in this list.
- if (!isNonMemberChannelEntity(entity)) {
- markChannelTargetSeenOnOpen(entity, notificationSource);
- }
if (args.rowIndex !== undefined) soup.focus.setIndex(args.rowIndex);
else soup.focus.set(entity.id);
@@ -1038,22 +1037,20 @@ const SoupViewListContent = (props: SoupViewListProps) => {
splitHandle: panel.handle,
replacePreview: event.altKey,
referredFrom: currentView(),
+ notificationSource,
});
return;
}
const finishTouchHighlight = persistSoupNavigationTouchHighlight(event);
- if (!isNonMemberChannelEntity(entity)) {
- markChannelTargetSeenOnOpen(entity, notificationSource);
- }
-
try {
await openEntityInSplitFromUnifiedList(entity, {
openInNewSplit: event.shiftKey,
location,
splitHandle: panel.handle,
referredFrom: currentView(),
+ notificationSource,
});
} finally {
finishTouchHighlight?.();
diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts
index 79ba027201..a7e47dc252 100644
--- a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts
+++ b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.test.ts
@@ -29,6 +29,10 @@ vi.mock('@app/signal/splitLayout', () => ({
globalSplitManager: () => undefined,
}));
+vi.mock('@components/app/GlobalAppState', () => ({
+ useGlobalNotificationSource: () => ({ bulkMarkAsRead: vi.fn() }),
+}));
+
vi.mock('@core/hotkey/hotkeys', () => {
const registration = {
dispose: vi.fn(),
diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts
index 740865dfe3..bc827c73d6 100644
--- a/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts
+++ b/apps/web/src/features/next-soup/soup-view/use-soup-navigation-hotkeys.ts
@@ -5,6 +5,7 @@ import {
openEntityInSplitFromUnifiedList,
} from '@app/features/next-soup/utils';
import { globalSplitManager } from '@app/signal/splitLayout';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import type {
SplitContent,
SplitEvent,
@@ -36,6 +37,7 @@ export const useSoupNavigationHotkeys = (
options: UseSoupNavigationHotkeysOptions
) => {
const { scopeId, soup, splitHandle, virtualizerHandle } = options;
+ const notificationSource = useGlobalNotificationSource();
const scrollTo = (index: number) => {
const handle = virtualizerHandle();
@@ -66,6 +68,7 @@ export const useSoupNavigationHotkeys = (
splitHandle,
mergeHistory: true,
referredFrom: navigationReferredFrom(),
+ notificationSource,
});
}, 150);
onCleanup(() => openInViewerDebounced.clear());
@@ -84,6 +87,7 @@ export const useSoupNavigationHotkeys = (
splitHandle,
mergeHistory: true,
referredFrom: navigationReferredFrom(),
+ notificationSource,
});
};
diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
index dcc9c52a37..dc1a81c0e2 100644
--- a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
+++ b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts
@@ -3,6 +3,7 @@ import { isListViewID, type ListView } from '@app/constants/list-views';
import { CommandState } from '@app/features/command/state';
import { VIEW_TAB_PRESETS } from '@app/features/next-soup/sidebar/soup-filter-presets';
import {
+ markChannelNotificationsSeenOnOpen,
markReminderSeenOnOpen,
openEntityInSplitFromUnifiedList,
} from '@app/features/next-soup/utils';
@@ -131,15 +132,18 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
filterValidNotifications(entity.notifications?.() ?? [])
);
const splitManager = globalSplitManager();
- return (
+ const didOpen =
!!splitManager &&
openSingleStackNotification(
validNotifs,
splitManager,
newSplit,
splitHandle
- )
- );
+ );
+ if (didOpen) {
+ markChannelNotificationsSeenOnOpen(entity, notificationSource);
+ }
+ return didOpen;
};
// enter - Open entity in split, toggle group, or load more
@@ -188,6 +192,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
splitHandle,
location,
referredFrom: currentView(),
+ notificationSource,
});
return true;
},
@@ -228,6 +233,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
splitHandle,
replacePreview: true,
referredFrom: currentView(),
+ notificationSource,
});
return true;
},
@@ -346,6 +352,7 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {
splitHandle,
openInNewSplit: true,
referredFrom: currentView(),
+ notificationSource,
});
return true;
},
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index 6b28df517f..1e727a6e90 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -79,7 +79,7 @@ import {
executeMarkEntitiesDone,
getChannelEntityTarget,
getRowClickFallbackLocation,
- markChannelTargetSeenOnOpen,
+ markChannelNotificationsSeenOnOpen,
openEntityInSplitFromUnifiedList,
preventDuplicatePreviewEntityOpen,
resolveMarkEntitiesDoneVariables,
@@ -124,6 +124,10 @@ const asRead = (notification: UnifiedNotification): UnifiedNotification =>
viewed_at: '2026-07-14T00:00:00.000Z',
}) as unknown as UnifiedNotification;
+const notificationSourceWithBulkMarkAsRead = (
+ bulkMarkAsRead = vi.fn(async () => {})
+) => ({ bulkMarkAsRead }) as unknown as NotificationSource;
+
const channelMessageRow = (opts?: {
target?: ChannelEntityTarget;
notifications?: UnifiedNotification[];
@@ -394,9 +398,12 @@ describe('getChannelEntityTarget', () => {
});
});
- it('marks an attached agent notification read even when the global source does not contain it', () => {
- const notification = sendNotification('agent-notification', 'agent-msg');
- notification.notification_metadata = {
+ it('marks every unread notification attached to a channel row', () => {
+ const agentNotification = sendNotification(
+ 'agent-notification',
+ 'agent-msg'
+ );
+ agentNotification.notification_metadata = {
tag: 'channel_message_send',
content: {
messageId: 'agent-msg',
@@ -404,42 +411,106 @@ describe('getChannelEntityTarget', () => {
senderDisplayName: 'Macro Agent',
},
} as UnifiedNotification['notification_metadata'];
+ const olderNotification = sendNotification('older-notification', 'older');
+ const readNotification = asRead(sendNotification('read', 'read-msg'));
+
const bulkMarkAsRead = vi.fn(async () => {});
- const notificationSource = {
- notificationsByEntity: () => ({}),
- bulkMarkAsRead,
- } as unknown as NotificationSource;
+ markChannelNotificationsSeenOnOpen(
+ channelRow({
+ notifications: [agentNotification, olderNotification, readNotification],
+ }),
+ notificationSourceWithBulkMarkAsRead(bulkMarkAsRead)
+ );
+
+ expect(bulkMarkAsRead).toHaveBeenCalledOnce();
+ expect(bulkMarkAsRead).toHaveBeenCalledWith([
+ agentNotification,
+ olderNotification,
+ ]);
+ });
- markChannelTargetSeenOnOpen(
+ it('marks attached channel notifications through the shared split-open path', async () => {
+ const notification = sendNotification('shared-open', 'message');
+ const openWithSplit = vi.fn();
+ setGlobalSplitManager({
+ activeSplit: vi.fn(),
+ getOrchestrator: vi.fn(() => ({
+ getBlockHandle: vi.fn(async () => undefined),
+ })),
+ getSplitByContent: vi.fn(),
+ openWithSplit,
+ } as unknown as SplitManager);
+
+ const bulkMarkAsRead = vi.fn(async () => {});
+ await openEntityInSplitFromUnifiedList(
channelRow({ notifications: [notification] }),
- notificationSource
+ {
+ notificationSource:
+ notificationSourceWithBulkMarkAsRead(bulkMarkAsRead),
+ }
);
- expect(bulkMarkAsRead).toHaveBeenCalledOnce();
+ expect(openWithSplit).toHaveBeenCalledWith(
+ expect.objectContaining({
+ params: expect.objectContaining({ channel_message_id: 'message' }),
+ }),
+ expect.any(Object)
+ );
expect(bulkMarkAsRead).toHaveBeenCalledWith([notification]);
});
+ it('does not mark a thread-stack notification when opening its parent channel row', async () => {
+ const parentNotification = sendNotification('parent-send', 'message');
+ const threadNotification = replyNotification(
+ 'thread-reply',
+ 'reply',
+ 'thread-root'
+ );
+ setGlobalSplitManager({
+ activeSplit: vi.fn(),
+ getOrchestrator: vi.fn(() => ({
+ getBlockHandle: vi.fn(async () => undefined),
+ })),
+ getSplitByContent: vi.fn(),
+ openWithSplit: vi.fn(),
+ } as unknown as SplitManager);
+
+ const bulkMarkAsRead = vi.fn(async () => {});
+ await openEntityInSplitFromUnifiedList(
+ channelRow({
+ notifications: [parentNotification, threadNotification],
+ }),
+ {
+ notificationSource:
+ notificationSourceWithBulkMarkAsRead(bulkMarkAsRead),
+ }
+ );
+
+ expect(bulkMarkAsRead).toHaveBeenCalledWith([parentNotification]);
+ expect(bulkMarkAsRead).not.toHaveBeenCalledWith(
+ expect.arrayContaining([threadNotification])
+ );
+ });
+
it('reports failures to mark an attached channel notification read', async () => {
const error = new Error('mark failed');
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
const notification = sendNotification('notification', 'message');
- const notificationSource = {
- bulkMarkAsRead: vi.fn(async () => {
- throw error;
- }),
- } as unknown as NotificationSource;
+ const bulkMarkAsRead = vi.fn(async () => {
+ throw error;
+ });
try {
- markChannelTargetSeenOnOpen(
+ markChannelNotificationsSeenOnOpen(
channelRow({ notifications: [notification] }),
- notificationSource
+ notificationSourceWithBulkMarkAsRead(bulkMarkAsRead)
);
await Promise.resolve();
expect(consoleError).toHaveBeenCalledWith(
- 'Failed to mark message notifications as read',
+ 'Failed to mark channel notifications as read',
error
);
} finally {
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 425acee6da..23f9aad606 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -373,6 +373,11 @@ interface OpenEntityOptions {
mergeHistory?: boolean;
allowDuplicate?: boolean;
referredFrom?: ReferredFrom;
+ /**
+ * Notification source used to keep REST-backed unread state optimistic when
+ * opening a channel row. Callers that can open channels must provide it.
+ */
+ notificationSource?: NotificationSource;
}
const DUPLICATE_CONTENT_MESSAGE = 'Content already open.';
@@ -669,6 +674,10 @@ export const openEntityInSplitFromUnifiedList = async (
channelTarget?.kind === 'message' ? channelTarget : undefined;
const openChannelAtLatest = channelTarget?.kind === 'latest';
+ if (options.notificationSource) {
+ markChannelNotificationsSeenOnOpen(entity, options.notificationSource);
+ }
+
let params: Record<string, string> | undefined;
if (entity.type === 'channel' && location?.type === 'channel') {
params = getChannelParams(location.messageId, location.threadId);
@@ -734,32 +743,35 @@ export const openEntityInSplitFromUnifiedList = async (
};
/**
- * Mark the attached notification that caused a channel row to target a message.
+ * Mark every unread notification represented by an opened channel Soup row.
*
- * The row's Soup edge is authoritative here. The channel block's message marker
- * discovers notifications through the separately paginated global source, so
- * an older notification can drive navigation without being present there.
+ * The row's attached Soup edge is authoritative. The channel block's message
+ * marker discovers notifications through the separately paginated global
+ * source, so it cannot reliably clear older notifications. Passing the row's
+ * attached notifications through the source keeps its REST cache and durable
+ * seen overrides in sync while the configured mutation updates GraphQL edges.
*/
-export function markChannelTargetSeenOnOpen(
+export function markChannelNotificationsSeenOnOpen(
entity: EntityData,
notificationSource: NotificationSource
) {
- const target = getChannelEntityTarget(entity);
- if (target?.kind !== 'message' || !isWithNotification(entity)) return;
+ if (
+ (entity.type !== 'channel' &&
+ entity.type !== 'channel_message' &&
+ entity.type !== 'channel_thread') ||
+ !isWithNotification(entity)
+ ) {
+ return;
+ }
const notifications = scopeChannelNotificationsForEntity(
entity,
entity.notifications?.() ?? []
- ).filter((notification) => {
- if (notificationIsRead(notification)) return false;
- return (
- getChannelNotificationParams(notification).messageId === target.messageId
- );
- });
+ ).filter((notification) => !notificationIsRead(notification));
if (notifications.length === 0) return;
void notificationSource.bulkMarkAsRead(notifications).catch((error) => {
- console.error('Failed to mark message notifications as read', error);
+ console.error('Failed to mark channel notifications as read', error);
});
}
diff --git a/apps/web/src/lib/queries/notification/entity-mutations.ts b/apps/web/src/lib/queries/notification/entity-mutations.ts
index 71d8fed65f..53c6ee7e0d 100644
--- a/apps/web/src/lib/queries/notification/entity-mutations.ts
+++ b/apps/web/src/lib/queries/notification/entity-mutations.ts
@@ -1,11 +1,15 @@
import type { UnifiedNotification } from '@notifications/types';
+import { refreshActiveGraphqlSoupQueries } from '@queries/soup/graphql/active-queries';
import type {
GraphqlEntityType,
NotificationEntityInput,
NotificationUpdateOperation,
} from '@service-storage/graphql/generated/graphql';
import { updateNotificationsForEntities as updateGraphqlNotificationsForEntities } from '@service-storage/graphql-notifications';
-import { mapGraphqlNotification } from '@service-storage/graphql-soup';
+import {
+ graphqlCacheEnabled,
+ mapGraphqlNotification,
+} from '@service-storage/graphql-soup';
type SimpleNotificationEntityType =
| 'calendar_event'
@@ -122,5 +126,8 @@ export async function updateNotificationsForEntities(args: {
entities: args.entities.map(toNotificationEntityInput),
operation: args.operation,
});
+ if (!graphqlCacheEnabled()) {
+ await refreshActiveGraphqlSoupQueries();
+ }
return rows.map((row) => mapGraphqlNotification(row));
}
diff --git a/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts
new file mode 100644
index 0000000000..641700dd31
--- /dev/null
+++ b/apps/web/src/lib/queries/notification/tests/entity-mutations.test.ts
@@ -0,0 +1,49 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({
+ cacheEnabled: true,
+ refreshActiveGraphqlSoupQueries: vi.fn(async () => undefined),
+ updateGraphqlNotificationsForEntities: vi.fn(async () => []),
+}));
+
+vi.mock('@queries/soup/graphql/active-queries', () => ({
+ refreshActiveGraphqlSoupQueries: mocks.refreshActiveGraphqlSoupQueries,
+}));
+
+vi.mock('@service-storage/graphql-notifications', () => ({
+ updateNotificationsForEntities: mocks.updateGraphqlNotificationsForEntities,
+}));
+
+vi.mock('@service-storage/graphql-soup', () => ({
+ graphqlCacheEnabled: () => mocks.cacheEnabled,
+ mapGraphqlNotification: vi.fn((notification) => notification),
+}));
+
+import { updateNotificationsForEntities } from '../entity-mutations';
+
+describe('updateNotificationsForEntities', () => {
+ beforeEach(() => {
+ mocks.cacheEnabled = true;
+ vi.clearAllMocks();
+ });
+
+ it('relies on normalized cache updates when the cache is active', async () => {
+ await updateNotificationsForEntities({
+ entities: [{ type: 'channel', id: 'channel-1' }],
+ operation: 'MARK_SEEN',
+ });
+
+ expect(mocks.refreshActiveGraphqlSoupQueries).not.toHaveBeenCalled();
+ });
+
+ it('refreshes active Soup queries after an uncached write', async () => {
+ mocks.cacheEnabled = false;
+
+ await updateNotificationsForEntities({
+ entities: [{ type: 'channel', id: 'channel-1' }],
+ operation: 'MARK_SEEN',
+ });
+
+ expect(mocks.refreshActiveGraphqlSoupQueries).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx b/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx
index 7f0051185a..d57721c86c 100644
--- a/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx
+++ b/apps/web/src/lib/queries/notification/tests/user-notifications.test.tsx
@@ -24,7 +24,9 @@ const {
createGraphqlMutationMock,
createGraphqlQueryMock,
executeGraphqlMutationMock,
+ graphqlCacheEnabledMock,
graphqlSoupEnabledMock,
+ refreshActiveSoupQueriesMock,
restMarkDoneMock,
restMarkSeenMock,
restUserNotificationsMock,
@@ -33,7 +35,9 @@ const {
createGraphqlMutationMock: vi.fn(),
createGraphqlQueryMock: vi.fn(),
executeGraphqlMutationMock: vi.fn(),
+ graphqlCacheEnabledMock: vi.fn(() => true),
graphqlSoupEnabledMock: vi.fn(() => true),
+ refreshActiveSoupQueriesMock: vi.fn(async () => undefined),
restMarkDoneMock: vi.fn(),
restMarkSeenMock: vi.fn(),
restUserNotificationsMock: vi.fn(),
@@ -65,12 +69,20 @@ vi.mock('@service-storage/graphql-notifications', () => ({
updateNotifications: vi.fn(),
}));
+vi.mock('@queries/soup/graphql/active-queries', () => ({
+ refreshActiveGraphqlSoupQueries: refreshActiveSoupQueriesMock,
+}));
+
vi.mock('@queries/soup/normalized-cache', () => ({
optimisticUpdateSoupItemUpdatedAt: vi.fn(),
hasSoupEntity: vi.fn(() => false),
refetchSoupEntity: vi.fn(),
}));
+vi.mock('@service-storage/graphql-soup', () => ({
+ graphqlCacheEnabled: graphqlCacheEnabledMock,
+}));
+
import {
hasSoupEntity,
optimisticUpdateSoupItemUpdatedAt,
@@ -108,6 +120,7 @@ type GraphqlMutationOptions = {
};
beforeEach(() => {
+ graphqlCacheEnabledMock.mockReturnValue(true);
graphqlSoupEnabledMock.mockReturnValue(true);
restUserNotificationsMock.mockResolvedValue(
ok({ items: [], next_cursor: null })
@@ -431,7 +444,26 @@ describe('notification mutations', () => {
const notifications = getNotificationsFromCache();
expect(typeof notifications[0].viewed_at).toBe('string');
expect(notifications[1].viewed_at).toBe(null);
+ expect(refreshActiveSoupQueriesMock).not.toHaveBeenCalled();
+
+ cleanup();
+ });
+
+ it('refreshes active Soup queries when the GraphQL cache is unavailable', async () => {
+ graphqlCacheEnabledMock.mockReturnValue(false);
+ executeGraphqlMutationMock.mockResolvedValue([]);
+
+ let mutatePromise: Promise<unknown> | undefined;
+ const TestComponent = () => {
+ const mutation = useMarkNotificationsAsSeenMutation();
+ mutatePromise = mutation.mutateAsync({ notificationIds: ['n1'] });
+ return null;
+ };
+ const cleanup = renderWithClient(TestComponent);
+
+ await mutatePromise;
+ expect(refreshActiveSoupQueriesMock).toHaveBeenCalledOnce();
cleanup();
});
diff --git a/apps/web/src/lib/queries/notification/user-notifications.ts b/apps/web/src/lib/queries/notification/user-notifications.ts
index 53faf5458d..0ae6a1bfca 100644
--- a/apps/web/src/lib/queries/notification/user-notifications.ts
+++ b/apps/web/src/lib/queries/notification/user-notifications.ts
@@ -2,6 +2,7 @@ import { ENABLE_GRAPHQL_SOUP } from '@core/constant/featureFlags';
import type { Maybe } from '@core/types';
import { throwOnErr } from '@core/util/result';
import type { UnifiedNotification } from '@notifications/types';
+import { refreshActiveGraphqlSoupQueries } from '@queries/soup/graphql/active-queries';
import {
hasSoupEntity,
optimisticUpdateSoupItemUpdatedAt,
@@ -14,6 +15,7 @@ import type { ApiUserNotification } from '@service-notification/generated/schema
import type { GetAllUserNotificationsResponse } from '@service-notification/generated/schemas/getAllUserNotificationsResponse';
import type { NotificationUpdateOperation } from '@service-storage/graphql/generated/graphql';
import { updateNotifications } from '@service-storage/graphql-notifications';
+import { graphqlCacheEnabled } from '@service-storage/graphql-soup';
import {
type InfiniteData,
useInfiniteQuery,
@@ -386,6 +388,12 @@ export function invalidateUserNotifications() {
});
}
+async function refreshSoupAfterUncachedGraphqlWrite(): Promise<void> {
+ if (ENABLE_GRAPHQL_SOUP() && !graphqlCacheEnabled()) {
+ await refreshActiveGraphqlSoupQueries();
+ }
+}
+
/** Mark notifications done through the shared GraphQL mutation. Throws on failure. */
export async function bulkMarkNotificationsAsDone(
notificationIds: string[]
@@ -594,6 +602,10 @@ function createNotificationsMutation(
context as NotificationsMutationContext,
undefined as never
);
+ // The normalized client propagates the optimistic notification row
+ // into active Soup edges. Its uncached fallback cannot, so refetch
+ // mounted Soup queries after the authoritative mutation succeeds.
+ await refreshSoupAfterUncachedGraphqlWrite();
},
onError: async (error, variables, context) => {
await lifecycle.onError?.(