Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(notifications): navigate to replies in open channel previews (#9053)
gbirman7d636f26063e
diff --git a/apps/web/src/components/app/createPreviewSelectionGuard.test.tsx b/apps/web/src/components/app/createPreviewSelectionGuard.test.tsxindex c361f6d30f..aa46d76030 100644--- a/apps/web/src/components/app/createPreviewSelectionGuard.test.tsx+++ b/apps/web/src/components/app/createPreviewSelectionGuard.test.tsx@@ -18,8 +18,14 @@ import { createContentInstanceRegistry } from './split-layout/contentInstanceRegimport { SplitLayoutContext } from './split-layout/context';import type { SplitManager } from './split-layout/layoutManager';-let manager: Pick<SplitManager, 'findOpenView' | 'registerOpenViews'>;+let manager: Pick<+ SplitManager,+ 'findOpenView' | 'registerOpenViews' | 'getOrchestrator'+>;+const goToLocationFromParams = vi.fn();+const getBlockHandle = vi.fn(async () => ({ goToLocationFromParams }));const activate = vi.hoisted(() => vi.fn());+vi.mock('@app/signal/splitLayout', () => ({ globalSplitManager: vi.fn() }));vi.mock('@core/component/Toast/Toast', () => ({ toast: { alert: vi.fn() } }));vi.mock('./split-layout/layoutUtils', () => ({useSplitPanelOrThrow: () => ({ handle: { activate } }),@@ -39,9 +45,15 @@ beforeEach(() => {manager = {findOpenView: registry.find,registerOpenViews: registry.register,+ getOrchestrator: () =>+ ({ getBlockHandle }) as unknown as ReturnType<+ SplitManager['getOrchestrator']+ >,};vi.mocked(toast.alert).mockClear();activate.mockClear();+ getBlockHandle.mockClear();+ goToLocationFromParams.mockClear();});it('activates the split owning a preview and stops exposing it after close', () => {@@ -247,3 +259,39 @@ it('treats Markdown as single-instance and allows revisiting the owning preview'first.unmount();second.unmount();});++it.each([undefined, 'thread'])(+ 'navigates to a message in the owning preview (thread: %s)',+ async (threadId) => {+ const first = setup();+ const second = setup();+ first.stack.reset({ type: 'channel', id: 'channel' });+ second.stack.reset({ type: 'email', id: 'email' });+ const current = second.stack.active();+ const target = {+ blockType: 'channel' as const,+ blockId: 'channel',+ aliasContext: undefined,+ params: {+ channel_message_id: 'reply',+ ...(threadId ? { channel_thread_id: threadId } : {}),+ },+ };++ expect(second.selectionGuard.canSelect(target)).toBe(false);+ expect(activate).toHaveBeenCalledOnce();+ await getBlockHandle.mock.results[0].value;+ expect(goToLocationFromParams).toHaveBeenCalledWith(target.params);+ expect(getBlockHandle).toHaveBeenCalledWith('channel', 'channel');+ expect(second.stack.active()).toBe(current);+ expect(toast.alert).not.toHaveBeenCalled();++ getBlockHandle.mockClear();+ activate.mockClear();+ expect(second.selectionGuard.canSelect(target, 'restore')).toBe(false);+ expect(getBlockHandle).not.toHaveBeenCalled();+ expect(activate).not.toHaveBeenCalled();+ first.unmount();+ second.unmount();+ }+);diff --git a/apps/web/src/components/app/createPreviewSelectionGuard.ts b/apps/web/src/components/app/createPreviewSelectionGuard.tsindex ff754f6634..696c3e6ce5 100644--- a/apps/web/src/components/app/createPreviewSelectionGuard.ts+++ b/apps/web/src/components/app/createPreviewSelectionGuard.ts@@ -1,5 +1,8 @@import type { NavigationStackChangeReason } from '@app/components/navigation-stack/NavigationStack';+import { goToChannelMessage } from '@block-channel/utils/link';import { toast } from '@core/component/Toast/Toast';+import { fireAndForget } from '@core/util/fireAndForget';+import { Telemetry } from '@macro-inc/observability';import { createSignal, onCleanup, untrack, useContext } from 'solid-js';import {type PreviewBlockTarget,@@ -39,20 +42,57 @@ export function createPreviewSelectionGuard(): PreviewSelectionGuard {});onCleanup(unregister);- const identity = (selection: PreviewSelectionInput | undefined) => {+ const targetFor = (selection: PreviewSelectionInput | undefined) => {if (!selection) return;- const target =- 'blockType' in selection ? selection : previewBlockTarget(selection);+ return 'blockType' in selection ? selection : previewBlockTarget(selection);+ };+ const identity = (target: PreviewBlockTarget | undefined) => {+ if (!target) return;return { type: target.blockType, id: target.blockId };};const canSelect: SelectPreview = (selection, reason = 'navigate') =>untrack(() => {- const next = identity(selection);+ const target = targetFor(selection);+ const next = identity(target);const existing = next && manager.findOpenView(next);if (existing && existing.owner !== owner) {if (reason === 'navigate') {existing.activate?.();- toast.alert('Content already open');+ const params = target?.params;+ const messageId =+ params && 'channel_message_id' in params+ ? params.channel_message_id+ : undefined;+ const threadId =+ params && 'channel_thread_id' in params+ ? params.channel_thread_id+ : undefined;+ if (+ target?.blockType === 'channel' &&+ typeof messageId === 'string'+ ) {+ // Keep the current preview and send the location to its existing owner.+ fireAndForget(+ Telemetry.span('channel.navigate_from_preview', async (span) => {+ span.setAttr('channel.id', target.blockId);+ span.setAttr('message.id', messageId);+ try {+ await goToChannelMessage(+ manager.getOrchestrator(),+ target.blockId,+ messageId,+ typeof threadId === 'string' ? threadId : undefined+ );+ } catch (error) {+ span.error(error);+ throw error;+ }+ }),+ 'preview-selection'+ );+ } else {+ toast.alert('Content already open');+ }}return false;}@@ -60,7 +100,7 @@ export function createPreviewSelectionGuard(): PreviewSelectionGuard {});const select: SelectPreview = (selection, reason) => {if (!canSelect(selection, reason)) return false;- setCurrent(identity(selection));+ setCurrent(identity(targetFor(selection)));return true;};diff --git a/docs/agent-guide/home.md b/docs/agent-guide/home.mdindex cdacf6599f..1e24146b84 100644--- a/docs/agent-guide/home.md+++ b/docs/agent-guide/home.md@@ -92,6 +92,10 @@ message. Channel namesprefer the current channel cache, then a matching thread notification's name,then **Unknown channel** if neither source has a name. Selecting athread opens that thread in the channel preview; Shift-click opens it in a split.+If the channel is already open in another split or preview, clicking a message+or reply notification focuses that view and jumps to the specific message,+without a **Content already open** warning. Verify with two splits and a reply+in a different thread from the one currently displayed; repeat on touch.A Home URL containing only the channel `threadId` opens that thread's root,not the latest message. Reloading or opening the same URL on touch retains thetarget; an explicit reply `messageId` still takes precedence.