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(home): stop sending a nil uuid as the channel thread participant (#8668)

gbirmancf0edd4e43b6
diff --git a/apps/web/src/features/home/queries/home-query.ts b/apps/web/src/features/home/queries/home-query.ts
index 815b2dcff9..b4a6060595 100644
--- a/apps/web/src/features/home/queries/home-query.ts
+++ b/apps/web/src/features/home/queries/home-query.ts
@@ -59,9 +59,13 @@ function signalClause(
clause.eq('channelDone', false),
clause.eq('channelIsParticipant', true)
),
+ // Participant only accepts `macro|` user ids, so an unknown viewer
+ // matches no threads instead of sending a placeholder id.
cthf: clause.and(
clause.eq('channelThreadDone', false),
- clause.eq('channelThreadParticipantId', userId ?? NIL_UUID)
+ userId
+ ? clause.eq('channelThreadParticipantId', userId)
+ : clause.eq('channelThreadId', NIL_UUID)
),
cf: clause.and(
clause.eq('chatDone', false),
diff --git a/apps/web/src/features/home/queries/home-results.test.ts b/apps/web/src/features/home/queries/home-results.test.ts
index 86420717e3..ba8396e2ed 100644
--- a/apps/web/src/features/home/queries/home-results.test.ts
+++ b/apps/web/src/features/home/queries/home-results.test.ts
@@ -84,6 +84,25 @@ describe('home sort method per tab', () => {
});
});
+describe('home channel thread scope', () => {
+ const NIL = '00000000-0000-0000-0000-000000000000';
+
+ it("scopes Signal's channel threads to the viewer", () => {
+ const body = JSON.stringify(
+ buildHomeQuery({ ...context, tab: 'signal' }).body.cthf
+ );
+ expect(body).toContain('{"Participant":"macro|[email protected]"}');
+ });
+
+ it('matches no channel threads before the viewer is known', () => {
+ const body = JSON.stringify(
+ buildHomeQuery({ ...context, userId: undefined, tab: 'signal' }).body.cthf
+ );
+ expect(body).not.toContain('"Participant"');
+ expect(body).toContain(`{"ThreadId":"${NIL}"}`);
+ });
+});
+
describe('home date buckets', () => {
it('buckets a notified row by its notification on the notification tabs', () => {
const signal = { tab: 'signal' as const, capabilities };
diff --git a/apps/web/src/features/home/queries/home-search.test.ts b/apps/web/src/features/home/queries/home-search.test.ts
new file mode 100644
index 0000000000..5833673b23
--- /dev/null
+++ b/apps/web/src/features/home/queries/home-search.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, it, vi } from 'vitest';
+import { buildHomeSearchRequest } from './home-search';
+
+// The soup barrel imports the websocket client modules, which open real
+// sockets at module scope and reject under jsdom.
+vi.mock('@service-storage/websocket', () => ({
+ storageWS: { reconnectIfDisconnected: vi.fn() },
+ createWebSocketJob: vi.fn(),
+}));
+vi.mock('@service-connection/websocket', () => ({
+ ws: { addEventListener: vi.fn(), send: vi.fn() },
+ state: () => 'closed',
+ createConnectionBlockWebsocketEffect: vi.fn(),
+ createConnectionWebsocketEffect: vi.fn(),
+}));
+
+const NIL = '00000000-0000-0000-0000-000000000000';
+
+const context = {
+ tab: 'signal' as const,
+ facets: {},
+ facetContext: { notificationSource: undefined as never },
+ capabilities: {
+ calendar: true,
+ foreignEntities: true,
+ notifiedSort: true,
+ snippets: true,
+ },
+ userId: 'macro|[email protected]',
+};
+
+const search = { query: 'roadmap', matchType: 'partial' as const };
+
+describe('Home search channel threads', () => {
+ it("searches the viewer's channel threads", () => {
+ const { filters } = buildHomeSearchRequest(context, search).body;
+ expect(filters?.channel_thread_filters).toEqual({
+ participant_ids: ['macro|[email protected]'],
+ });
+ });
+
+ it('excludes channel threads before the viewer is known', () => {
+ const { filters } = buildHomeSearchRequest(
+ { ...context, userId: undefined },
+ search
+ ).body;
+ expect(filters?.channel_thread_filters).toEqual({ thread_ids: [NIL] });
+ });
+});
diff --git a/apps/web/src/features/home/queries/home-search.ts b/apps/web/src/features/home/queries/home-search.ts
index 420ebb32bf..f5ba36508d 100644
--- a/apps/web/src/features/home/queries/home-search.ts
+++ b/apps/web/src/features/home/queries/home-search.ts
@@ -130,12 +130,12 @@ export function buildHomeSearchRequest(
}
filters.channel_filters = channelFilters;
- }
- if (types.has('channels')) {
- filters.channel_thread_filters = {
- participant_ids: [context.userId ?? NIL_UUID],
- };
+ if (context.userId) {
+ filters.channel_thread_filters = {
+ participant_ids: [context.userId],
+ };
+ }
}
if (documentTypes.length > 0) {
diff --git a/apps/web/src/features/home/queries/use-home-query.test.ts b/apps/web/src/features/home/queries/use-home-query.test.ts
index 2ffb28a698..cd2f6fabc6 100644
--- a/apps/web/src/features/home/queries/use-home-query.test.ts
+++ b/apps/web/src/features/home/queries/use-home-query.test.ts
@@ -68,7 +68,10 @@ vi.mock('@core/mobile/isTouchDevice', () => ({
vi.mock('@components/app/GlobalAppState', () => ({
useGlobalNotificationSource: () => ({ notificationsByEntity: () => ({}) }),
}));
-vi.mock('@core/context/user', () => ({ useUserId: () => () => 'alice' }));
+const viewer = vi.hoisted(() => ({
+ id: (() => 'alice') as () => string | undefined,
+}));
+vi.mock('@core/context/user', () => ({ useUserId: () => viewer.id }));
vi.mock('@queries/soup/items', () => ({ useSoupAstItemsQuery: vi.fn() }));
vi.mock('@service-storage/websocket', () => ({
storageWS: { reconnectIfDisconnected: vi.fn() },
@@ -182,6 +185,7 @@ describe('Home data source', () => {
vi.setSystemTime(new Date(2026, 8, 10, 12));
flags.graphqlSoup = false;
touch.device = false;
+ viewer.id = () => 'alice';
});
afterEach(() => {
dispose?.();
@@ -560,4 +564,44 @@ describe('Home work feed', () => {
expect(workFeedSource.enabled?.()).toBe(false);
expect(ids(source)).toEqual(['from-soup']);
});
+
+ it('waits for the viewer before querying the notification feed', () => {
+ touch.device = true;
+ const [userId, setUserId] = createSignal<string>();
+ viewer.id = userId;
+ const notifications = makeQuery([email('from-soup', 9)], false);
+ const activity = makeQuery([], false);
+ const { source } = mount(notifications, activity);
+ const [args, options] = vi.mocked(useSoupAstItemsQuery).mock.calls[0];
+
+ expect(options?.().enabled).toBe(false);
+ expect(JSON.stringify(args().body)).not.toContain('"Participant"');
+ expect(source.isLoading()).toBe(true);
+ expect(ids(source)).toEqual([]);
+
+ setUserId('macro|[email protected]');
+ expect(options?.().enabled).toBe(true);
+ expect(JSON.stringify(args().body.cthf)).toContain(
+ '{"Participant":"macro|[email protected]"}'
+ );
+ expect(source.isLoading()).toBe(false);
+ expect(ids(source)).toEqual(['from-soup']);
+ });
+
+ it('holds desktop recents back until the viewer is known', () => {
+ flags.graphqlSoup = false;
+ const [userId, setUserId] = createSignal<string>();
+ viewer.id = userId;
+ const notifications = makeQuery([email('notified', 9)], false);
+ const activity = makeQuery([email('recent', 10)], false);
+ const { source } = mount(notifications, activity);
+
+ expect(workFeedSource.enabled?.()).toBe(false);
+ expect(source.isLoading()).toBe(true);
+ expect(ids(source)).toEqual([]);
+
+ setUserId('macro|[email protected]');
+ expect(source.isLoading()).toBe(false);
+ expect(ids(source)).toEqual(['recent', 'notified']);
+ });
});
diff --git a/apps/web/src/features/home/queries/use-home-query.ts b/apps/web/src/features/home/queries/use-home-query.ts
index adaec6a723..a49e0b2635 100644
--- a/apps/web/src/features/home/queries/use-home-query.ts
+++ b/apps/web/src/features/home/queries/use-home-query.ts
@@ -163,13 +163,18 @@ export function useHomeEntitiesQuery(
const queryArgs = createMemo(() => buildHomeQuery(viewContext()));
+ const requested = () => options.enabled?.() ?? true;
+ // Signal's channel threads are the viewer's own, so wait for the viewer
+ // like the Channels thread queries instead of fetching a page to discard.
+ const awaitingViewer = () => requested() && !userId();
+
const query = useSoupAstItemsQuery(queryArgs, () => {
// Capture the tab alongside the query args so the insert gate stays bound
// to the query it was registered on: after a tab switch the previous
// tab's cached query keeps gating cache inserts by its own membership.
const tab = viewContext().tab;
return {
- enabled: options.enabled?.() ?? true,
+ enabled: requested() && Boolean(userId()),
showSupportedForeignEntities: foreignEntities().enabled,
meta: {
insertFilter: homeTabInsertFilter(tab),
@@ -219,6 +224,7 @@ export function useHomeEntitiesQuery(
transformEntities,
hasUnreadEntity,
notificationSource,
+ awaitingViewer,
};
}
@@ -274,7 +280,9 @@ function useSoupHomeDataSource(
filterEntities,
attachNotifications,
transformEntities,
+ awaitingViewer,
} = useHomeEntitiesQuery(state, options);
+ const notificationsLoading = () => awaitingViewer() || query.isLoading;
const [now, setNow] = createSignal(homeClock());
onMount(() => {
@@ -341,7 +349,9 @@ function useSoupHomeDataSource(
const rawEntities = createMemo<EntityData[]>((previous) => {
if (!search.isSearching()) {
- const notifications = query.isLoading ? [] : (query.data?.entities ?? []);
+ const notifications = notificationsLoading()
+ ? []
+ : (query.data?.entities ?? []);
return notifications;
}
@@ -360,11 +370,11 @@ function useSoupHomeDataSource(
if (!mergeRecents() || search.isSearching()) return undefined;
return getHomePagination(
{
- oldestFetchedTimestamp: query.isLoading
+ oldestFetchedTimestamp: notificationsLoading()
? undefined
: query.data?.oldestFetchedTimestamp,
hasMore: query.hasNextPage && !query.error,
- isLoading: query.isLoading,
+ isLoading: notificationsLoading(),
},
{
oldestFetchedTimestamp: recentQuery.isLoading
@@ -435,13 +445,13 @@ function useSoupHomeDataSource(
if (hasNoTypes()) return false;
if (!search.isSearching()) {
return (
- (query.isLoading || (mergeRecents() && recentQuery.isLoading)) &&
+ (notificationsLoading() || (mergeRecents() && recentQuery.isLoading)) &&
entities().items.length === 0
);
}
if (entities().items.length > 0) return false;
if (usesServiceSearch()) return search.isLoading();
- return query.isLoading;
+ return notificationsLoading();
};
return {
diff --git a/apps/web/src/features/home/queries/use-home-unread-query.test.ts b/apps/web/src/features/home/queries/use-home-unread-query.test.ts
index a91f5fbaf9..d38a9e01a4 100644
--- a/apps/web/src/features/home/queries/use-home-unread-query.test.ts
+++ b/apps/web/src/features/home/queries/use-home-unread-query.test.ts
@@ -19,6 +19,7 @@ const mocks = vi.hoisted(() => ({
legacy: vi.fn(),
legacyUnread: vi.fn(),
notifiedSort: vi.fn(),
+ userId: vi.fn(),
}));
vi.mock('@app/lib/analytics/posthog', () => ({
useFeatureFlag: () => () => ({ enabled: mocks.notifiedSort() }),
@@ -27,6 +28,7 @@ vi.mock('@service-storage/graphql-soup', () => ({
getGraphqlSoupClient: mocks.client,
}));
vi.mock('./use-home-query', () => ({ useHomeEntitiesQuery: mocks.legacy }));
+vi.mock('@core/context/user', () => ({ useUserId: () => mocks.userId }));
vi.mock('@service-storage/websocket', () => ({
storageWS: { reconnectIfDisconnected: vi.fn() },
createWebSocketJob: vi.fn(),
@@ -68,6 +70,8 @@ function setup(initialNotifiedSort = false) {
mocks.notifiedSort.mockImplementation(notifiedSort);
const [state, setState] = createSignal<'unseen' | 'seen' | 'done'>();
const [pending, setPending] = createSignal(false);
+ const [userId, setUserId] = createSignal<string | undefined>('viewer');
+ mocks.userId.mockImplementation(userId);
mocks.legacyUnread.mockReturnValue(true);
mocks.legacy.mockReturnValue({
query: {
@@ -91,7 +95,7 @@ function setup(initialNotifiedSort = false) {
tab: 'signal',
facets: { read: ['unread'] },
facetContext: {},
- userId: 'viewer',
+ userId: userId(),
capabilities: {
calendar: true,
snippets: true,
@@ -101,7 +105,14 @@ function setup(initialNotifiedSort = false) {
}),
});
const unread = useHomeUnreadQuery(enabled);
- return { unread, setEnabled, setState, setNotifiedSort, setPending };
+ return {
+ unread,
+ setEnabled,
+ setState,
+ setNotifiedSort,
+ setPending,
+ setUserId,
+ };
});
const queries = () => operations.filter((op) => op.kind === 'query');
const respond = (state: 'UNSEEN' | 'SEEN', error?: CombinedError) =>
@@ -203,6 +214,22 @@ describe('Home unread presence query', () => {
expect(getActiveGraphqlSoupRevalidations(f.client)).toEqual([]);
});
+ it('waits for the viewer before querying GraphQL', async () => {
+ const f = setup();
+ f.setUserId(undefined);
+ // The legacy query waits for the viewer too, so it has no page yet.
+ f.setPending(true);
+ f.setEnabled(true);
+ expect(f.unread()).toBe(false);
+ expect(f.queries()).toHaveLength(0);
+ f.setPending(false);
+ f.setUserId('viewer');
+ await vi.waitFor(() => expect(f.queries()).toHaveLength(1));
+ expect(JSON.stringify(f.queries()[0].variables)).toContain(
+ '"participant":"viewer"'
+ );
+ });
+
it('keeps notified-at sorting on REST, including while GraphQL is disabled', async () => {
const f = setup(true);
expect(f.unread()).toBe(true);
diff --git a/apps/web/src/features/home/queries/use-home-unread-query.ts b/apps/web/src/features/home/queries/use-home-unread-query.ts
index adae9f761e..df5cd43fdd 100644
--- a/apps/web/src/features/home/queries/use-home-unread-query.ts
+++ b/apps/web/src/features/home/queries/use-home-unread-query.ts
@@ -1,5 +1,6 @@
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { enableInboxNotifiedSort } from '@core/constant/featureFlags';
+import { useUserId } from '@core/context/user';
import { createLiveQuery } from '@graphql-cache/solid/create-live-query';
import { registerActivityRevalidator } from '@queries/activity/push-registry';
import { registerChannelNotificationRefresh } from '@queries/channel/register-notification-refresh';
@@ -29,7 +30,9 @@ export function useHomeUnreadQuery(
// page rather than silently changing its order/bounds or building an invalid
// GraphQL input. Disabled queries must not compile an unsupported AST either.
const notifiedSort = useFeatureFlag(enableInboxNotifiedSort);
- const enabled = () => graphqlEnabled() && !notifiedSort().enabled;
+ const userId = useUserId();
+ const enabled = () =>
+ graphqlEnabled() && !notifiedSort().enabled && Boolean(userId());
const legacy = useHomeEntitiesQuery(
{ tab: 'signal', facets: { read: ['unread'] } },
{ enabled: () => !enabled() }