Files
multica/packages/core/notification-preferences/queries.ts
Bohan Jiang a9a9e93905 fix(core): scope inbox notification mute check to the source workspace (#3821)
Follow-up to #3797. The inbox:new handler keys the notification-preference
query on item.workspace_id, but the request itself still resolved its
workspace from the active-workspace X-Workspace-Slug header. On a cold
cache, a user viewing workspace B who received a workspace-A notification
read B's mute setting and cached it under A's key — so A's banners could
fire while muted (and vice-versa), polluting A's cache.

Add an optional workspaceSlug override to getNotificationPreferences and
notificationPreferenceOptions, and pass the resolved source slug from the
inbox:new handler. When the source slug can't be resolved, read only an
already-warm cache instead of fetching with the wrong workspace. Tests
cover the cold-cache source-slug fetch, source mute suppression, and the
no-fallback guard.

MUL-3062

Co-authored-by: J <j@multica.ai>
Co-authored-by: multica-agent <github@multica.ai>
2026-06-05 16:05:49 +08:00

21 lines
829 B
TypeScript

import { queryOptions } from "@tanstack/react-query";
import { api } from "../api";
export const notificationPreferenceKeys = {
all: (wsId: string) => ["notification-preferences", wsId] as const,
};
/**
* `workspaceSlug` scopes the underlying request to a specific workspace via
* the `X-Workspace-Slug` override. The query key stays keyed on `wsId` (slug
* and id are 1:1), so the cache entry is still per-workspace; the slug only
* ensures a cold-cache fetch reads the intended workspace rather than the
* active one. Omit it to follow the active workspace (the Settings page).
*/
export function notificationPreferenceOptions(wsId: string, workspaceSlug?: string) {
return queryOptions({
queryKey: notificationPreferenceKeys.all(wsId),
queryFn: () => api.getNotificationPreferences(workspaceSlug),
});
}