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(channels): message links into the open channel navigate again (#6995)
gbirman5cf74553aa1b
diff --git a/apps/web/src/features/block-channel/component/NewChannelBlockAdapter.tsx b/apps/web/src/features/block-channel/component/NewChannelBlockAdapter.tsxindex 8fa4e3036a..01b6d9362e 100644--- a/apps/web/src/features/block-channel/component/NewChannelBlockAdapter.tsx+++ b/apps/web/src/features/block-channel/component/NewChannelBlockAdapter.tsx@@ -40,6 +40,7 @@ import {URL_PARAMS as CHANNEL_URL_PARAMS,isJoinCallRequested,isOpenCallTabRequested,+ toChannelTargetRequest,} from '@channel/Channel/link';import {canUseInlineCallTab,@@ -106,22 +107,6 @@ type ChannelEntryStateSnapshot = {messages?: MessageTimelineStateSnapshot;};-/**- * Decode channel target params into a surface request. A bare `thread` param- * becomes a request whose message is the thread root itself, which the- * surface collapses to a top-level target — same rule convertTargetMessage- * applied when this decoding lived here.- */-function toTargetRequest(- params: ChannelTargetMessageParams-): ChannelTargetRequest | undefined {- const messageId = params[URL_PARAMS.message];- const threadId = params[URL_PARAMS.thread];- const primary = messageId ?? threadId;- if (!primary) return undefined;- return { kind: 'message', messageId: primary, threadId };-}-const initialChannelTab = (options: {wantsJoinCall: boolean;hasActiveCallHere: boolean;@@ -391,7 +376,7 @@ export function NewChannelBlockAdapter(props: BlockChannelProps) {// whenever a fresh request lands, whether or not it was mounted at the time.const [targetRequest, setTargetRequest] = createSignal<ChannelTargetRequest | undefined- >(toTargetRequest(initialTargetMessageParams()));+ >(toChannelTargetRequest(initialTargetMessageParams()));let surfaceApi: ChannelSurfaceApi | undefined;const setActiveTab = (tab: ChannelTabId) => {@@ -440,17 +425,19 @@ export function NewChannelBlockAdapter(props: BlockChannelProps) {// inside `onChannelReady` (Messages tab), so open-call from Attachments/etc. was a no-op.createMethodRegistration(blockHandle, {goToLocationFromParams: async (params: ChannelTargetMessageParams) => {- if (isOpenCallTabRequested(params[CHANNEL_URL_PARAMS.openCallTab])) {- setActiveTab(getCallJoinTab());- return;- }-- const target = toTargetRequest(params);+ // Store any message target first: a request that also opens the call tab+ // leaves it waiting for whenever the user returns to Messages.+ const target = toChannelTargetRequest(params);if (target) {setActiveTab(DEFAULT_CHANNEL_TAB);setTargetRequest(target);}+ if (isOpenCallTabRequested(params[CHANNEL_URL_PARAMS.openCallTab])) {+ setActiveTab(getCallJoinTab());+ return;+ }+if (isJoinCallRequested(params[CHANNEL_URL_PARAMS.joinCall])) {setActiveTab(getCallJoinTab());setPendingJoinCall(true);diff --git a/apps/web/src/features/channel/Channel/ChannelDetail.tsx b/apps/web/src/features/channel/Channel/ChannelDetail.tsxindex 47ce0794a1..7bf78e1f35 100644--- a/apps/web/src/features/channel/Channel/ChannelDetail.tsx+++ b/apps/web/src/features/channel/Channel/ChannelDetail.tsx@@ -4,12 +4,15 @@ import { ChannelAttachmentsTab } from '@channel/Attachments/ChannelAttachmentsTaimport { useChannelBotManagement } from '@channel/Bots/use-channel-bot-management';import { useCallContextOptional } from '@channel/Call/CallContext';import { CallEventSync } from '@channel/Call/CallEventSync';+import { ChannelCallAutoJoin } from '@channel/Call/ChannelCallAutoJoin';import { ChannelCallButton } from '@channel/Call/ChannelCallButton';import { ChannelCallTab } from '@channel/Call/ChannelCallTab';+import { getCallJoinTab } from '@channel/Call/call-tabs';import { useCall } from '@channel/Call/use-call';import { ChannelCallsTab } from '@channel/Calls/ChannelCallsTab';import { ChannelTopIcon } from '@channel/components/ChannelTopIcon';import { ChannelParticipantsTab } from '@channel/Participants/ChannelParticipantsTab';+import { useGlobalBlockOrchestrator } from '@components/app/GlobalAppState';import {createPriorityCollapseController,PriorityCollapseOverflowSensor,@@ -22,12 +25,12 @@ import type { PriorityCollapser } from '@components/app/split-layout/utils/creatimport { TabsInset } from '@core/component/TabsInset';import { ENABLE_CALLS } from '@core/constant/featureFlags';import { useChannelName, useChannelType } from '@core/context/channels';+import { createMethodRegistration } from '@core/orchestrator';import { useChannelParticipantsQuery } from '@queries/channel/channel-participants';import {type Accessor,children,createComputed,- createMemo,createSignal,type JSX,Match,@@ -45,6 +48,12 @@ import { ChannelTabProvider, useChannelTab } from './ChannelTabContext';import { ChannelLiveIndicators } from './ChannelTopBarLiveIndicators';import { toIconTabItems } from './channel-tab-icons';import { type ChannelTabId, DEFAULT_CHANNEL_TAB } from './channel-tabs';+import {+ isJoinCallRequested,+ isOpenCallTabRequested,+ toChannelTargetRequest,+ URL_PARAMS,+} from './link';import {canUseInlineCallTab,normalizeChannelTab,@@ -216,26 +225,38 @@ function ChannelDetailHeader(props: {function ChannelDetailContent(props: ChannelDetailProps) {const panel = useSplitPanelOrThrow();+ const orchestrator = useGlobalBlockOrchestrator();const channelId = props.channelId;const channelName = useChannelName(channelId, props.fallbackName);- // Convert the value-semantic target prop into identity-stable surface- // requests: only a changed target or explicit re-open produces a new request.- let lastTargetKey: string | undefined;- const targetRequest = createMemo<ChannelTargetRequest | undefined>(- (previous) => {- const target = props.target;- const location = !target- ? ''- : target.kind === 'latest'- ? 'latest'- : `${target.messageId}:${target.threadId ?? ''}`;- const key = `${location}:${props.navigationRequest ?? 0}`;- if (lastTargetKey !== undefined && key === lastTargetKey) return previous;- lastTargetKey = key;- return target ? { ...target } : undefined;- }- );+ const requestFromTarget = (+ target: ChannelTargetRequest | undefined+ ): ChannelTargetRequest | undefined => (target ? { ...target } : undefined);++ const targetKey = () => {+ const target = props.target;+ const location = !target+ ? ''+ : target.kind === 'latest'+ ? 'latest'+ : `${target.messageId}:${target.threadId ?? ''}`;+ return `${location}:${props.navigationRequest ?? 0}`;+ };++ // The surface navigates on a fresh request object. The host's `target` is+ // value-semantic, so it only produces one when its value changes; a mention+ // chip or notification arriving through the block handle always does.+ let lastTargetKey = targetKey();+ const [targetRequest, setTargetRequest] = createSignal<+ ChannelTargetRequest | undefined+ >(requestFromTarget(props.target));++ createComputed(() => {+ const key = targetKey();+ if (key === lastTargetKey) return;+ lastTargetKey = key;+ setTargetRequest(requestFromTarget(props.target));+ });const callCtx = useCallContextOptional();// A channel that owns this client's active call opens on the Call tab, so@@ -249,6 +270,7 @@ function ChannelDetailContent(props: ChannelDetailProps) {const setActiveTab = (tab: ChannelTabId) => {setActiveTabInternal(normalizeChannelTab(tab));};+ const [pendingJoinCall, setPendingJoinCall] = createSignal(false);// A new target within the already-mounted channel (a notification jump)// must land on the messages pane, whichever tab is open.@@ -262,6 +284,33 @@ function ChannelDetailContent(props: ChannelDetailProps) {));+ // Mention chips, notifications, and call deep links aim an open channel+ // through its block handle; without one the click only activates the view.+ createComputed(() => {+ const handle = orchestrator.registerBlockHandle('channel', channelId);+ createMethodRegistration(() => handle, {+ goToLocationFromParams: async (params: Record<string, unknown>) => {+ // Store any message target first: a request that also opens the call+ // tab leaves it waiting for whenever the user returns to Messages.+ const request = toChannelTargetRequest(params);+ if (request) setTargetRequest(request);++ if (isOpenCallTabRequested(params[URL_PARAMS.openCallTab])) {+ setActiveTab(getCallJoinTab());+ return;+ }++ if (isJoinCallRequested(params[URL_PARAMS.joinCall])) {+ setActiveTab(getCallJoinTab());+ setPendingJoinCall(true);+ }+ },+ goToLatest: async () => {+ setTargetRequest({ kind: 'latest' });+ },+ });+ });+// CallContext: which channel has the Call tab selected (for isCallPage(), etc.).createComputed(() =>callCtx?.syncCallPageTab(channelId, activeTab() === 'call')@@ -278,6 +327,11 @@ function ChannelDetailContent(props: ChannelDetailProps) {<ChannelSurface channelId={channelId} targetRequest={targetRequest()}><CallEventSync /><ChannelTabProvider activeTab={activeTab} setActiveTab={setActiveTab}>+ <ChannelCallAutoJoin+ channelId={channelId}+ pendingJoinCall={pendingJoinCall}+ onHandled={() => setPendingJoinCall(false)}+ /><div class="flex size-full min-h-0 flex-col"><ChannelDetailHeaderrender={props.children}@@ -309,7 +363,7 @@ function ChannelDetailContent(props: ChannelDetailProps) {<Match when={activeTab() === 'call' && canUseInlineCallTab()}><ChannelCallTabchannelId={channelId}- pendingJoin={() => false}+ pendingJoin={pendingJoinCall}/></Match></Switch>diff --git a/apps/web/src/features/channel/Channel/link.ts b/apps/web/src/features/channel/Channel/link.tsindex 2af5276725..d4a3c211ae 100644--- a/apps/web/src/features/channel/Channel/link.ts+++ b/apps/web/src/features/channel/Channel/link.ts@@ -3,6 +3,8 @@// replace `block-channel`, and we don't want `channel` to import from// `block-channel` to keep the import tree clean during the transition.+import type { ChannelTargetRequest } from './ChannelSurface';+export const URL_PARAMS = {thread: 'channel_thread_id',message: 'channel_message_id',@@ -25,6 +27,27 @@ export function getChannelParams(return params;}+/**+ * Decode channel target params into a surface request. A bare `thread` param+ * becomes a request whose message is the thread root itself, which the surface+ * collapses to a top-level target.+ */+export function toChannelTargetRequest(+ params: Record<string, unknown>+): ChannelTargetRequest | undefined {+ const messageId = params[URL_PARAMS.message];+ const threadId = params[URL_PARAMS.thread];+ const primary = typeof messageId === 'string' ? messageId : undefined;+ const thread = typeof threadId === 'string' ? threadId : undefined;+ const target = primary ?? thread;+ if (!target) return undefined;+ return {+ kind: 'message',+ messageId: target,+ ...(thread ? { threadId: thread } : {}),+ };+}+/** True when a `join_call` param value means "please join the call". */export function isJoinCallRequested(value: unknown): boolean {return value === 'true' || value === true;diff --git a/apps/web/src/features/channel/Channel/tests/channel-detail-navigation.test.tsx b/apps/web/src/features/channel/Channel/tests/channel-detail-navigation.test.tsxnew file mode 100644index 0000000000..f62a762e67--- /dev/null+++ b/apps/web/src/features/channel/Channel/tests/channel-detail-navigation.test.tsx@@ -0,0 +1,209 @@+import { createBlockOrchestrator } from '@core/orchestrator';+import { cleanup, render } from '@solidjs/testing-library';+import { type Accessor, createComputed, type JSX } from 'solid-js';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type { ChannelTargetRequest } from '../ChannelSurface';+import { useChannelTab } from '../ChannelTabContext';+import { type ChannelTabId, DEFAULT_CHANNEL_TAB } from '../channel-tabs';++const orchestrator = createBlockOrchestrator();+const mocks = vi.hoisted(() => ({+ pass: (props: { children?: JSX.Element }) => props.children,+ requests: [] as (ChannelTargetRequest | undefined)[],+ joinRequested: false,+}));++vi.mock('@channel/Channel/ChannelSurface', () => ({+ ChannelSurface: (props: {+ targetRequest?: ChannelTargetRequest;+ children?: JSX.Element;+ }) => {+ // The real surface navigates on each fresh request object; record them all.+ createComputed(() => mocks.requests.push(props.targetRequest));+ return props.children;+ },+ ChannelMessages: () => null,+}));+vi.mock('@app/components/view-shell', () => ({+ ViewShell: { TopBar: mocks.pass },+}));+vi.mock('@app/features/chat/ChatWithAgentButton', () => ({+ ChatWithAgentButton: () => null,+}));+vi.mock('@channel/Attachments/ChannelAttachmentsTab', () => ({+ ChannelAttachmentsTab: () => null,+}));+vi.mock('@channel/Bots/use-channel-bot-management', () => ({+ useChannelBotManagement: () => ({+ enabled: () => false,+ openCreateBot: vi.fn(),+ openBot: vi.fn(),+ inviteFocusRequest: () => undefined,+ }),+}));+vi.mock('@channel/Call/CallContext', () => ({+ useCallContextOptional: () => undefined,+}));+vi.mock('@channel/Call/CallEventSync', () => ({ CallEventSync: () => null }));+vi.mock('@channel/Call/ChannelCallAutoJoin', () => ({+ ChannelCallAutoJoin: (props: { pendingJoinCall: () => boolean }) => {+ createComputed(() => {+ if (props.pendingJoinCall()) mocks.joinRequested = true;+ });+ return null;+ },+}));+vi.mock('@channel/Call/ChannelCallButton', () => ({+ ChannelCallButton: () => null,+}));+vi.mock('@channel/Call/ChannelCallTab', () => ({ ChannelCallTab: () => null }));+vi.mock('@channel/Call/use-call', () => ({+ useCall: () => ({ isInThisChannel: () => false }),+}));+vi.mock('@channel/Calls/ChannelCallsTab', () => ({+ ChannelCallsTab: () => null,+}));+vi.mock('@channel/components/ChannelTopIcon', () => ({+ ChannelTopIcon: () => null,+}));+vi.mock('@channel/Participants/ChannelParticipantsTab', () => ({+ ChannelParticipantsTab: () => null,+}));+vi.mock('@components/app/GlobalAppState', () => ({+ useGlobalBlockOrchestrator: () => orchestrator,+}));+vi.mock(+ '@components/app/split-layout/components/PriorityCollapseOverflowSensor',+ () => ({+ createPriorityCollapseController: () => ({+ setRow: vi.fn(),+ collapser: undefined,+ }),+ PriorityCollapseOverflowSensor: mocks.pass,+ })+);+vi.mock('@components/app/split-layout/layoutUtils', () => ({+ useRegisterPriorityCollapseItem: () => () => false,+ useSplitPanelOrThrow: () => ({ splitHotkeyScope: 'test-scope' }),+}));+vi.mock('@core/component/TabsInset', () => ({ TabsInset: () => null }));+vi.mock('@core/context/channels', () => ({+ useChannelName: () => () => 'channel-name',+ useChannelType: () => () => 'private',+}));+vi.mock('@queries/channel/channel-participants', () => ({+ useChannelParticipantsQuery: () => ({ isSuccess: false, data: undefined }),+}));+// Keep the orchestrator's registry real without pulling every block definition.+vi.mock('@core/constant/allBlocks', () => ({+ blocks: {},+ resolveBlockAlias: (type: string) => type,+}));+// Live viewer indicators open the shared connection's socket, which jsdom+// rejects; the top bar they belong to is the host's, not this test's subject.+vi.mock('../ChannelTopBarLiveIndicators', () => ({+ ChannelLiveIndicators: () => null,+}));+vi.mock('../use-channel-tab-items', () => ({+ canUseInlineCallTab: () => false,+ normalizeChannelTab: (tab: string) => tab,+ useChannelTabItems: () => () => [],+}));++import { ChannelDetail } from '../ChannelDetail';++const CHANNEL_ID = 'channel-1';++const navigate = async (params: Record<string, string>) => {+ const handle = await orchestrator.getBlockHandle(CHANNEL_ID, 'channel');+ await handle?.goToLocationFromParams(params);+};++const messageRequests = () =>+ mocks.requests.filter(+ (request): request is Extract<ChannelTargetRequest, { kind: 'message' }> =>+ request?.kind === 'message'+ );++beforeEach(() => {+ mocks.requests.length = 0;+ mocks.joinRequested = false;+});+afterEach(cleanup);++describe('channel detail navigation', () => {+ it('navigates the surface for every message link click, including a repeat', async () => {+ render(() => (+ <ChannelDetail channelId={CHANNEL_ID}>{() => null}</ChannelDetail>+ ));+ expect(mocks.requests).toEqual([undefined]);++ await navigate({ channel_message_id: 'message-1' });+ expect(messageRequests()).toEqual([+ { kind: 'message', messageId: 'message-1' },+ ]);++ // Clicking the same link again re-aims the target, so a released+ // highlight comes back rather than the second click doing nothing.+ await navigate({ channel_message_id: 'message-1' });+ expect(messageRequests()).toHaveLength(2);+ expect(messageRequests()[0]).not.toBe(messageRequests()[1]);++ await navigate({+ channel_message_id: 'reply-1',+ channel_thread_id: 'message-2',+ });+ expect(messageRequests().at(-1)).toEqual({+ kind: 'message',+ messageId: 'reply-1',+ threadId: 'message-2',+ });+ });++ it('keeps serving the host target when no navigation arrives', async () => {+ render(() => (+ <ChannelDetail+ channelId={CHANNEL_ID}+ target={{ kind: 'message', messageId: 'deep-link' }}+ >+ {() => null}+ </ChannelDetail>+ ));+ expect(messageRequests()).toEqual([+ { kind: 'message', messageId: 'deep-link' },+ ]);+ });++ it('sends call params to the call tab and joins only when asked', async () => {+ let activeTab: Accessor<ChannelTabId> | undefined;+ render(() => (+ <ChannelDetail channelId={CHANNEL_ID}>+ {() => {+ activeTab = useChannelTab().activeTab;+ return null;+ }}+ </ChannelDetail>+ ));+ expect(activeTab?.()).toBe(DEFAULT_CHANNEL_TAB);++ await navigate({ open_call_tab: 'true' });+ expect(activeTab?.()).toBe('call');+ expect(mocks.joinRequested).toBe(false);++ await navigate({ channel_message_id: 'message-1' });+ expect(activeTab?.()).toBe(DEFAULT_CHANNEL_TAB);++ await navigate({ join_call: 'true' });+ expect(activeTab?.()).toBe('call');+ expect(mocks.joinRequested).toBe(true);++ // A message target that arrives alongside a call param is kept, so+ // returning to Messages lands on it.+ await navigate({ open_call_tab: 'true', channel_message_id: 'message-2' });+ expect(activeTab?.()).toBe('call');+ expect(messageRequests().at(-1)).toEqual({+ kind: 'message',+ messageId: 'message-2',+ });+ });+});