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
feat(crm): company and contact discussions on the shared message conversation (#7028)
gbirmand71165a20d9e
diff --git a/apps/web/src/components/app/split-layout/split-router/legacy-route.ts b/apps/web/src/components/app/split-layout/split-router/legacy-route.tsindex 6058dbad47..81f43a8716 100644--- a/apps/web/src/components/app/split-layout/split-router/legacy-route.ts+++ b/apps/web/src/components/app/split-layout/split-router/legacy-route.ts@@ -37,6 +37,7 @@ import {isBlockAlias,resolveBlockAlias,} from '@core/constant/allBlocks';+import { COMMENT_LINK_PARAM } from '@core/messages/comment-link';import { z } from 'zod';import type { SplitContent } from '../layoutManager';@@ -368,6 +369,7 @@ export const legacySplitRoute = defineRoute({const { type } = routeParams(entry.location.route);if (type === 'email') return Object.values(EMAIL_URL_PARAMS);if (type === 'channel') return Object.values(CHANNEL_URL_PARAMS);+ if (type === 'company' || type === 'contact') return [COMMENT_LINK_PARAM];return [];},claim: ({ type, id }) => {diff --git a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts b/apps/web/src/components/app/split-layout/tests/layoutManager.test.tsindex 624a5f9f5f..b9e8557ef7 100644--- a/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts+++ b/apps/web/src/components/app/split-layout/tests/layoutManager.test.ts@@ -1508,6 +1508,22 @@ describe('layoutManager', () => {});+ it.each(['company', 'contact'])(+ 'keeps a %s discussion link comment for the record page',+ async (type) => {+ const { location, router, dispose } = ingressRouter(+ `/${type}/record-1?comment_id=message-1`+ );+ await router.settled();+ expect(location.read().pathname).toBe(`/${type}/record-1`);+ expect(+ new URLSearchParams(location.read().search).get('comment_id')+ ).toBe('message-1');+ router.dispose();+ dispose();+ }+ );+it('upgrades renderable legacy details and preserves repeated raw target values', async () => {let dispose!: () => void;let router!: ReturnType<typeof createSplitRouter<string>>;diff --git a/apps/web/src/features/block-company/component/CompanyBlockAdapter.tsx b/apps/web/src/features/block-company/component/CompanyBlockAdapter.tsxindex 54bcda7f35..6594939476 100644--- a/apps/web/src/features/block-company/component/CompanyBlockAdapter.tsx+++ b/apps/web/src/features/block-company/component/CompanyBlockAdapter.tsx@@ -3,6 +3,12 @@ import { CrmCopyLinkButton } from '@companies/components/CrmCopyLinkButton';import { HeaderIsland } from '@components/app/split-layout/components/HeaderIsland';import { SplitHeaderRight } from '@components/app/split-layout/components/SplitHeader';import { useBlockId } from '@core/block';+import {+ createParamsState,+ ParamsProvider,+} from '@core/component/ParamsProvider';+import { createMethodRegistration } from '@core/orchestrator';+import { blockHandleSignal } from '@core/signal/load';/*** Legacy adapter: bridges the block/split-layout system to the standalone@@ -11,6 +17,10 @@ import { useBlockId } from '@core/block';*/export function CompanyBlockAdapter() {const companyId = useBlockId();+ const params = createParamsState();+ createMethodRegistration(blockHandleSignal.get, {+ goToLocationFromParams: params.navigate,+ });return (<><SplitHeaderRight>@@ -18,7 +28,9 @@ export function CompanyBlockAdapter() {<CrmCopyLinkButton type="company" id={companyId} /></HeaderIsland></SplitHeaderRight>- <Company companyId={companyId} />+ <ParamsProvider state={params}>+ <Company companyId={companyId} />+ </ParamsProvider></>);}diff --git a/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx b/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsxindex b346bf673b..01798a8a58 100644--- a/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx+++ b/apps/web/src/features/block-contact/component/ContactBlockAdapter.tsx@@ -3,6 +3,12 @@ import { HeaderIsland } from '@components/app/split-layout/components/HeaderIslaimport { SplitHeaderRight } from '@components/app/split-layout/components/SplitHeader';import { Contact } from '@contacts/Contact/Contact';import { useBlockId } from '@core/block';+import {+ createParamsState,+ ParamsProvider,+} from '@core/component/ParamsProvider';+import { createMethodRegistration } from '@core/orchestrator';+import { blockHandleSignal } from '@core/signal/load';/*** Legacy adapter: bridges the block/split-layout system to the standalone@@ -11,6 +17,10 @@ import { useBlockId } from '@core/block';*/export function ContactBlockAdapter() {const contactId = useBlockId();+ const params = createParamsState();+ createMethodRegistration(blockHandleSignal.get, {+ goToLocationFromParams: params.navigate,+ });return (<><SplitHeaderRight>@@ -18,7 +28,9 @@ export function ContactBlockAdapter() {<CrmCopyLinkButton type="contact" id={contactId} /></HeaderIsland></SplitHeaderRight>- <Contact contactId={contactId} />+ <ParamsProvider state={params}>+ <Contact contactId={contactId} />+ </ParamsProvider></>);}diff --git a/apps/web/src/features/block-md/component/DocumentDiscussion.test.tsx b/apps/web/src/features/block-md/component/DocumentDiscussion.test.tsxindex 6610f8d54e..f920000b32 100644--- a/apps/web/src/features/block-md/component/DocumentDiscussion.test.tsx+++ b/apps/web/src/features/block-md/component/DocumentDiscussion.test.tsx@@ -12,8 +12,8 @@ vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => true }));vi.mock('@components/app/split-layout/layoutUtils', () => ({useSplitPanel: () => undefined,}));-vi.mock('@core/messages/DocumentConversation', () => ({- DocumentConversation: () => null,+vi.mock('@core/messages/EntityConversation', () => ({+ EntityConversation: () => null,}));vi.mock('@core/signal/permissions', () => ({useCanComment: () => () => true,diff --git a/apps/web/src/features/block-md/component/DocumentDiscussion.tsx b/apps/web/src/features/block-md/component/DocumentDiscussion.tsxindex 2d30eeb731..eed09ca87b 100644--- a/apps/web/src/features/block-md/component/DocumentDiscussion.tsx+++ b/apps/web/src/features/block-md/component/DocumentDiscussion.tsx@@ -6,33 +6,15 @@ import {DiscussionProvider,} from '@core/comments/discussion';import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';-import {- useParamNavigationCount,- useUrlParams,-} from '@core/component/ParamsProvider';import {enableUnifiedDocumentDiscussions,isFeatureEnabled,} from '@core/constant/featureFlags';-import {- DocumentConversation,- DocumentConversationComposer,-} from '@core/messages/DocumentConversation';-import { scrollToRenderedTarget } from '@core/messages/scroll-to-rendered-target';+import { EntityDiscussion } from '@core/messages/EntityDiscussion';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';-import { buildSimpleEntityUrl } from '@core/util/url';-import type { MessageParent } from '@service-storage/messages';-import {- createEffect,- createMemo,- createSignal,- on,- onCleanup,- Show,-} from 'solid-js';+import { Show } from 'solid-js';import { createDocumentDiscussionSource } from '../comments/documentDiscussionSource';-import { URL_PARAMS } from '../constants';import { useMarkdownDocument } from '../context/markdown-document-context';function MobileDiscussionComposer(props: { hidden: boolean }) {@@ -48,28 +30,6 @@ function MobileDiscussionComposer(props: { hidden: boolean }) {);}-function MobileMessageComposer(props: {- parent: MessageParent;- hidden: boolean;-}) {- // Preserve the editor and draft while its placement is hidden.- const input = (- <DocumentConversationComposer- parent={props.parent}- collapsible- blurOnSend- />- );-- return (- <FloatRegion region="accessory">- <Show when={!props.hidden}>- <ChannelInputContainer>{input}</ChannelInputContainer>- </Show>- </FloatRegion>- );-}-/** Unanchored document roots rendered with the shared message components. */export function MessageDocumentDiscussion(props: {label?: string;@@ -84,73 +44,15 @@ export function MessageDocumentDiscussion(props: {const id = documentId();const documentKind = kind();const blockName = documentKind === 'document' ? 'md' : documentKind;- const params = useUrlParams(URL_PARAMS);- const parent: MessageParent = { type: 'document', id };- const floating = () =>- props.floatingComposerOnTouch === true && isTouchDevice();- let container: HTMLDivElement | undefined;- // Scroll to the linked message once per navigation of `comment_id`, as the- // margin does for anchored comments. A repeat navigation to the same message- // still scrolls; the URL value showing through after a navigation cleared it- // does not.- const commentNavigationCount = useParamNavigationCount(URL_PARAMS.commentId);- const scrollRequest = createMemo(- () => {- const commentId = params.commentId();- if (!commentId) return undefined;- const count = commentNavigationCount();- return {- commentId,- key: count === 0 ? `url:${commentId}` : `navigation:${count}`,- };- },- undefined,- { equals: (a, b) => a?.key === b?.key }- );- // Clicking the linked message releases its highlight until the next- // navigation to a comment.- const [clearedKey, setClearedKey] = createSignal<string>();- const targetCleared = () => {- const key = scrollRequest()?.key;- return key !== undefined && key === clearedKey();- };- let scrolledKey: string | undefined;- createEffect(- on(scrollRequest, (request) => {- if (!request || !container || request.key === scrolledKey) return;- scrolledKey = request.key;- onCleanup(scrollToRenderedTarget(container, request.commentId));- })- );return (- <>- <div ref={container} class="contents">- <DocumentConversation- parent={parent}- canWrite={permissions.canComment()}- targetId={params.commentId()}- targetCleared={targetCleared()}- onClearTarget={() => setClearedKey(scrollRequest()?.key)}- label={props.label}- buildLink={(message) =>- buildSimpleEntityUrl(- { type: blockName, id },- { [URL_PARAMS.commentId]: message.id }- )- }- hideComposer={floating()}- hideWhenEmpty={floating()}- />- </div>- <Show when={floating() && permissions.canComment()}>- <StaticMarkdownContext>- <MobileMessageComposer- parent={parent}- hidden={props.editorHasFocus === true && virtualKeyboardVisible()}- />- </StaticMarkdownContext>- </Show>- </>+ <EntityDiscussion+ parent={{ type: 'document', id }}+ canWrite={permissions.canComment()}+ link={{ type: blockName, id }}+ label={props.label}+ floatingComposerOnTouch={props.floatingComposerOnTouch}+ editorHasFocus={props.editorHasFocus}+ />);}diff --git a/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx b/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsxindex b977ca698b..4eacff2ec0 100644--- a/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx+++ b/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx@@ -39,8 +39,8 @@ vi.mock('../context/markdown-document-context', () => ({},}),}));-vi.mock('@core/messages/DocumentConversation', () => ({- DocumentConversation: (props: {+vi.mock('@core/messages/EntityConversation', () => ({+ EntityConversation: (props: {parent: { type: string; id: string };canWrite: boolean;buildLink: (message: { id: string }) => string;@@ -56,7 +56,7 @@ vi.mock('@core/messages/DocumentConversation', () => ({</For>);},- DocumentConversationComposer: () => {+ EntityConversationComposer: () => {mocks.mount();onCleanup(mocks.unmount);return <textarea aria-label="Comment draft" />;diff --git a/apps/web/src/features/channel/use-message-participants.test.ts b/apps/web/src/features/channel/use-message-participants.test.tsnew file mode 100644index 0000000000..9437df8928--- /dev/null+++ b/apps/web/src/features/channel/use-message-participants.test.ts@@ -0,0 +1,60 @@+import type { MessageParent } from '@service-storage/messages';+import { createRoot, createSignal } from 'solid-js';+import { expect, it, vi } from 'vitest';+import { useMessageParticipants } from './use-message-participants';++vi.mock('./use-channel-participants', () => ({+ useChannelParticipants: (channelId: () => string) => ({+ users: () =>+ channelId()+ ? [{ id: 'macro|[email protected]', email: '', name: 'Member' }]+ : [],+ ids: () => [],+ }),+}));+vi.mock('@queries/contacts/contacts', () => ({+ useContacts: () => () => [+ { id: 'macro|[email protected]', email: '', name: 'Contact' },+ ],+}));+vi.mock('@queries/team/teams', () => ({+ useCurrentTeamQuery: () => ({+ isPending: false,+ data: {+ members: [+ { user_id: 'macro|[email protected]' },+ { user_id: 'macro|[email protected]' },+ ],+ },+ }),+}));++it('offers the owning team on CRM records and contacts on documents', () => {+ createRoot((dispose) => {+ const [parent, setParent] = createSignal<MessageParent>({+ type: 'crm_company',+ id: 'company',+ });+ const participants = useMessageParticipants(parent);+ const ids = () => participants().map((user) => user.id);++ expect(ids()).toEqual([+ 'macro|[email protected]',+ 'macro|[email protected]',+ ]);+ expect(participants()[0].email).toBe('[email protected]');++ setParent({ type: 'crm_contact', id: 'contact' });+ expect(ids()).toEqual([+ 'macro|[email protected]',+ 'macro|[email protected]',+ ]);++ setParent({ type: 'document', id: 'document' });+ expect(ids()).toEqual(['macro|[email protected]']);++ setParent({ type: 'channel', id: 'channel' });+ expect(ids()).toEqual(['macro|[email protected]']);+ dispose();+ });+});diff --git a/apps/web/src/features/channel/use-message-participants.ts b/apps/web/src/features/channel/use-message-participants.tsindex 90828821fa..a4a47b1ea2 100644--- a/apps/web/src/features/channel/use-message-participants.ts+++ b/apps/web/src/features/channel/use-message-participants.ts@@ -1,26 +1,46 @@import type { IUser } from '@core/user/types';+import { idToDisplayName, idToEmail } from '@core/user/util';import { useContacts } from '@queries/contacts/contacts';+import { queryReadyGate } from '@queries/gate';+import { useCurrentTeamQuery } from '@queries/team/teams';import type { MessageParent } from '@service-storage/messages';import { type Accessor, createMemo } from 'solid-js';+import { match, P } from 'ts-pattern';import { useChannelParticipants } from './use-channel-participants';/*** The people a composer on `parent` offers in the `@`-mention typeahead: a- * channel's participants, or, on a document, the workspace contacts the- * legacy comment input suggested. Mirrors `useMessageBotMentionUsers` so that- * every composer on a parent — root, reply, and edit — suggests the same+ * channel's participants; on a document or project, the workspace contacts the+ * legacy comment input suggested; on a CRM record, the team that owns it, the only+ * people who can read its discussion. Mirrors `useMessageBotMentionUsers` so+ * that every composer on a parent — root, reply, and edit — suggests the same* people without each one resolving them again.*/export function useMessageParticipants(parent: Accessor<MessageParent>): Accessor<IUser[]> {const isChannel = () => parent().type === 'channel';+ const isCrm = () =>+ parent().type === 'crm_company' || parent().type === 'crm_contact';const channelParticipants = useChannelParticipants(() =>isChannel() ? parent().id : '');- const contacts = useContacts(() => !isChannel());+ const contacts = useContacts(() => !isChannel() && !isCrm());+ const team = useCurrentTeamQuery(isCrm);+ const teamMembers = (): IUser[] =>+ queryReadyGate(team) && team.data+ ? team.data.members.map((member) => ({+ id: member.user_id,+ email: idToEmail(member.user_id),+ name: idToDisplayName(member.user_id),+ }))+ : [];return createMemo(() =>- isChannel() ? channelParticipants.users() : contacts()+ match(parent().type)+ .with('channel', () => channelParticipants.users())+ .with(P.union('document', 'initiative'), () => contacts())+ .with(P.union('crm_company', 'crm_contact'), () => teamMembers())+ .exhaustive());}diff --git a/apps/web/src/features/companies/Company/CompanyDiscussionSection.tsx b/apps/web/src/features/companies/Company/CompanyDiscussionSection.tsxindex 75dfd9ae87..67aa85fb6c 100644--- a/apps/web/src/features/companies/Company/CompanyDiscussionSection.tsx+++ b/apps/web/src/features/companies/Company/CompanyDiscussionSection.tsx@@ -1,16 +1,14 @@-import { Discussion, DiscussionProvider } from '@core/comments/discussion';-import { CrmCommentEntityType } from '@service-storage/generated/schemas/crmCommentEntityType';-import { useCrmDiscussionSource } from './crmDiscussionSource';+import { useUserId } from '@core/context/user';+import { EntityDiscussion } from '@core/messages/EntityDiscussion';-/** Comment discussion for a CRM company, reusing the shared discussion UI. */+/** Discussion on a CRM company, on the shared message components. */export function CompanyDiscussionSection(props: { companyId: string }) {- const source = useCrmDiscussionSource(- CrmCommentEntityType.crm_company,- () => props.companyId- );+ const userId = useUserId();return (- <DiscussionProvider source={source}>- <Discussion />- </DiscussionProvider>+ <EntityDiscussion+ parent={{ type: 'crm_company', id: props.companyId }}+ canWrite={!!userId()}+ link={{ type: 'company', id: props.companyId }}+ />);}diff --git a/apps/web/src/features/companies/Company/crmDiscussionSource.ts b/apps/web/src/features/companies/Company/crmDiscussionSource.tsdeleted file mode 100644index 11d0154b4e..0000000000--- a/apps/web/src/features/companies/Company/crmDiscussionSource.ts+++ /dev/null@@ -1,183 +0,0 @@-import type {- DiscussionComment,- DiscussionSource,- DiscussionThread,-} from '@core/comments/discussion';-import { toast } from '@core/component/Toast/Toast';-import { useUserId } from '@core/context/user';-import { compareDateAsc } from '@core/util/date';-import {- useCreateCrmCommentMutation,- useCrmCommentsQuery,- useDeleteCrmCommentMutation,- useEditCrmCommentMutation,-} from '@queries/crm/comments';-import { crmKeys } from '@queries/crm/keys';-import type { CrmComment } from '@service-storage/generated/schemas/crmComment';-import type { CrmCommentEntityType } from '@service-storage/generated/schemas/crmCommentEntityType';-import type { CrmCommentThread } from '@service-storage/generated/schemas/crmCommentThread';-import { useQueryClient } from '@tanstack/solid-query';-import { type Accessor, createMemo } from 'solid-js';--/** Maps a server `CrmCommentThread` (uuid ids) to the normalized view model. */-function toViewThread(ct: CrmCommentThread): DiscussionThread {- const comments: DiscussionComment[] = [...ct.comments]- .sort((a, b) => compareDateAsc(a.createdAt, b.createdAt))- .map((c) => ({- id: c.commentId,- threadId: c.threadId,- authorId: c.sender ?? c.owner,- text: c.text,- createdAt: c.createdAt,- updatedAt: c.updatedAt,- deletedAt: c.deletedAt ?? null,- }));- return {- id: ct.thread.threadId,- resolved: ct.thread.resolved,- comments,- };-}--/** Replaces the matching thread or appends it when new. */-function upsertThread(- prev: CrmCommentThread[],- next: CrmCommentThread-): CrmCommentThread[] {- let replaced = false;- const out = prev.map((t) => {- if (t.thread.threadId === next.thread.threadId) {- replaced = true;- return next;- }- return t;- });- if (!replaced) out.push(next);- return out;-}--/**- * [`DiscussionSource`] backed by the CRM comments API for a company or- * contact. Ids are already uuid strings, so no id adaptation is needed; the- * `DISCUSSION:` mark filter doesn't apply either (every CRM thread is a- * discussion). Backed by the `@queries/crm/comments` TanStack query with- * point cache updates after each mutation. Must be called within a- * component owner.- */-export function useCrmDiscussionSource(- entityType: CrmCommentEntityType,- entityId: Accessor<string | undefined>-): DiscussionSource {- const userId = useUserId();- const queryClient = useQueryClient();-- const commentsQuery = useCrmCommentsQuery(entityType, entityId);- const createMutation = useCreateCrmCommentMutation();- const editMutation = useEditCrmCommentMutation();- const deleteMutation = useDeleteCrmCommentMutation();-- const threads = createMemo<DiscussionThread[]>(() =>- (commentsQuery.data ?? []).map(toViewThread)- );-- const setThreads = (- updater: (prev: CrmCommentThread[]) => CrmCommentThread[]- ) => {- const id = entityId();- if (!id) return;- queryClient.setQueryData<CrmCommentThread[]>(- crmKeys.comments(entityType, id).queryKey,- (prev) => updater(prev ?? [])- );- };-- const replaceComment = (updated: CrmComment) =>- setThreads((prev) =>- prev.map((ct) =>- ct.thread.threadId === updated.threadId- ? {- ...ct,- comments: ct.comments.map((c) =>- c.commentId === updated.commentId ? updated : c- ),- }- : ct- )- );-- return {- threads,- canEdit: () => !!userId(),- currentUserId: userId,- // CRM comments aren't deep-linked yet: no target to highlight, and- // `buildCommentLink` is omitted so the copy-link affordance stays hidden.- targetCommentId: () => null,- async createThread(text) {- const id = entityId();- if (!id) return;- try {- const thread = await createMutation.mutateAsync({- entityType,- entityId: id,- text,- });- setThreads((prev) => upsertThread(prev, thread));- } catch (error) {- console.error('Unable to create CRM comment', error);- toast.failure('Could not post comment');- }- },- async createReply(threadId, text) {- const id = entityId();- if (!id) return;- try {- const thread = await createMutation.mutateAsync({- entityType,- entityId: id,- text,- threadId,- });- setThreads((prev) => upsertThread(prev, thread));- } catch (error) {- console.error('Unable to reply to CRM comment', error);- toast.failure('Could not post reply');- }- },- async editComment(comment, text) {- try {- const updated = await editMutation.mutateAsync({- commentId: comment.id,- text,- });- replaceComment(updated);- } catch (error) {- console.error('Unable to edit CRM comment', error);- toast.failure('Could not edit comment');- }- },- async deleteComment(comment) {- try {- const { threadId, threadDeleted } = await deleteMutation.mutateAsync({- commentId: comment.id,- });- setThreads((prev) =>- threadDeleted- ? prev.filter((ct) => ct.thread.threadId !== threadId)- : prev.map((ct) =>- ct.thread.threadId === threadId- ? {- ...ct,- comments: ct.comments.filter(- (c) => c.commentId !== comment.id- ),- }- : ct- )- );- } catch (error) {- console.error('Unable to delete CRM comment', error);- toast.failure('Could not delete comment');- }- },- };-}diff --git a/apps/web/src/features/contacts/Contact/ContactDiscussionSection.tsx b/apps/web/src/features/contacts/Contact/ContactDiscussionSection.tsxindex e67ed79382..83d3cee6fd 100644--- a/apps/web/src/features/contacts/Contact/ContactDiscussionSection.tsx+++ b/apps/web/src/features/contacts/Contact/ContactDiscussionSection.tsx@@ -1,16 +1,14 @@-import { useCrmDiscussionSource } from '@companies/Company/crmDiscussionSource';-import { Discussion, DiscussionProvider } from '@core/comments/discussion';-import { CrmCommentEntityType } from '@service-storage/generated/schemas/crmCommentEntityType';+import { useUserId } from '@core/context/user';+import { EntityDiscussion } from '@core/messages/EntityDiscussion';-/** Comment discussion for a CRM contact, reusing the shared CRM discussion source. */+/** Discussion on a CRM contact, on the shared message components. */export function ContactDiscussionSection(props: { contactId: string }) {- const source = useCrmDiscussionSource(- CrmCommentEntityType.crm_contact,- () => props.contactId- );+ const userId = useUserId();return (- <DiscussionProvider source={source}>- <Discussion />- </DiscussionProvider>+ <EntityDiscussion+ parent={{ type: 'crm_contact', id: props.contactId }}+ canWrite={!!userId()}+ link={{ type: 'contact', id: props.contactId }}+ />);}diff --git a/apps/web/src/features/notifications/notification-navigation.ts b/apps/web/src/features/notifications/notification-navigation.tsindex ddf5aee532..8fd1fff083 100644--- a/apps/web/src/features/notifications/notification-navigation.ts+++ b/apps/web/src/features/notifications/notification-navigation.ts@@ -17,6 +17,7 @@ import {isFeatureEnabled,USE_MACRO_PR_SUMMARY_BLOCK,} from '@core/constant/featureFlags';+import { COMMENT_LINK_PARAM } from '@core/messages/comment-link';import type { EntityType, NotificationType } from '@core/types';import { openExternalUrl } from '@core/util/url';import { getNotificationById } from '@queries/notification/user-notifications';@@ -371,11 +372,14 @@ function getSupportedHandler(};}).with('crm_discussion', () => {+ const meta = notification.notification_metadata;+ if (meta.tag !== 'crm_discussion') return null;const blockName =notification.entity_type === 'crm_contact' ? 'contact' : 'company';return async (lm: SplitManager, newSplit: boolean = false) =>openSplitIfNotOpen(lm, blockName, notification.entity_id, {newSplit,+ params: { [COMMENT_LINK_PARAM]: meta.content.messageId },sourceHandle,});})diff --git a/apps/web/src/features/notifications/tests/crm-discussion-navigation.test.ts b/apps/web/src/features/notifications/tests/crm-discussion-navigation.test.tsnew file mode 100644index 0000000000..8a967e9373--- /dev/null+++ b/apps/web/src/features/notifications/tests/crm-discussion-navigation.test.ts@@ -0,0 +1,90 @@+vi.mock('../notification-helpers', () => ({+ isChannelNotification: () => false,+}));+vi.mock('../notification-source', () => ({+ CHANNEL_EVENT_TYPES: [+ 'channel_mention',+ 'channel_message_send',+ 'channel_message_reply',+ 'document_mention',+ ],+}));+vi.mock('../notification-stacking', () => ({+ getMostRecentNotification: vi.fn(),+ stackNotifications: vi.fn(),+}));++import type { SplitManager } from '@components/app/split-layout/layoutManager';+import { expect, it, vi } from 'vitest';+import type { UnifiedNotification } from '../types';++vi.mock('@app/features/calendar-view/calendar-range', () => ({+ createCalendarRange: vi.fn(),+}));+vi.mock('@app/features/calendar-view/calendar-navigation', () => ({+ openCalendarView: vi.fn(),+}));+vi.mock('@block-channel/utils/link', () => ({+ getChannelParams: vi.fn(),+ navigateToChannelMessage: vi.fn(),+}));+vi.mock('@core/constant/allBlocks', () => ({+ itemToBlockName: (value: { fileType: string }) => value.fileType,+ resolveBlockAlias: (type: string) => (type === 'task' ? 'md' : type),+}));+vi.mock('@core/constant/featureFlags', () => ({+ enableCalendarUi: false,+ enableReminders: false,+ isFeatureEnabled: vi.fn(),+ USE_MACRO_PR_SUMMARY_BLOCK: true,+}));+vi.mock('@core/util/url', () => ({ openExternalUrl: vi.fn() }));+vi.mock('@queries/notification/user-notifications', () => ({+ getNotificationById: vi.fn(),+}));+vi.mock('@queries/reminders/reminders', () => ({ getReminderById: vi.fn() }));+vi.mock('../notification-resolvers', () => ({+ DefaultNotificationBlockNameResolver: vi.fn(),+}));++import { openNotification } from '../notification-navigation';++it.each([+ ['crm_company', 'company'],+ ['crm_contact', 'contact'],+] as const)(+ 'opens a %s discussion notification at its message',+ async (entityType, blockName) => {+ const navigate = vi.fn();+ const open = vi.fn();+ const layout = {+ getSplitByContent: vi.fn(() => undefined as unknown),+ openWithSplit: open,+ getOrchestrator: () => ({+ getBlockHandle: async () => ({ goToLocationFromParams: navigate }),+ }),+ };+ const notification = {+ entity_id: 'record',+ entity_type: entityType,+ notification_metadata: {+ tag: 'crm_discussion',+ content: { messageId: 'message', threadId: 'root', reason: 'reply' },+ },+ } as UnifiedNotification;++ const result = await openNotification(+ notification,+ layout as unknown as SplitManager+ );++ expect(result.isOk()).toBe(true);+ expect(open).toHaveBeenCalledWith(+ { type: blockName, id: 'record' },+ expect.anything()+ );+ await vi.waitFor(() =>+ expect(navigate).toHaveBeenCalledWith({ comment_id: 'message' })+ );+ }+);diff --git a/apps/web/src/features/notifications/use-notification-updates.ts b/apps/web/src/features/notifications/use-notification-updates.tsindex 4d31c268f1..6aaf653071 100644--- a/apps/web/src/features/notifications/use-notification-updates.ts+++ b/apps/web/src/features/notifications/use-notification-updates.ts@@ -1,5 +1,4 @@import { queryClient } from '@queries/client';-import { crmKeys } from '@queries/crm/keys';import { emailKeys } from '@queries/email/keys';import { invalidateEmailLinks } from '@queries/email/link';import { messageKeys } from '@queries/messages/keys';@@ -93,7 +92,6 @@ export function handleNotificationUpdate(notification: UnifiedNotification) {]) {void queryClient.invalidateQueries({ queryKey: [...key._def, parent] });}- void queryClient.invalidateQueries({ queryKey: crmKeys.comments._def });void invalidateEntityNotifications(notification.entity_id);}).with({ tag: 'channel_invite' }, () => {diff --git a/apps/web/src/features/projects/project-collaboration.tsx b/apps/web/src/features/projects/project-collaboration.tsxindex 37b01a267c..881f902503 100644--- a/apps/web/src/features/projects/project-collaboration.tsx+++ b/apps/web/src/features/projects/project-collaboration.tsx@@ -1,4 +1,4 @@-import { DocumentConversation } from '@core/messages/DocumentConversation';+import { EntityConversation } from '@core/messages/EntityConversation';import { buildSimpleEntityUrl } from '@core/util/url';import { projectRouteId } from './core/route';@@ -9,7 +9,7 @@ export function ProjectDiscussion(props: {targetId?: string;}) {return (- <DocumentConversation+ <EntityConversationparent={{ type: 'initiative', id: props.projectId }}canWrite={props.canWrite}targetId={props.targetId}diff --git a/apps/web/src/lib/core/messages/DocumentConversation.test.tsx b/apps/web/src/lib/core/messages/EntityConversation.test.tsxsimilarity index 97%rename from apps/web/src/lib/core/messages/DocumentConversation.test.tsxrename to apps/web/src/lib/core/messages/EntityConversation.test.tsxindex c8233b832f..e4af16708e 100644--- a/apps/web/src/lib/core/messages/DocumentConversation.test.tsx+++ b/apps/web/src/lib/core/messages/EntityConversation.test.tsx@@ -3,7 +3,7 @@ import type { MessageListItem } from '@service-storage/messages';import { cleanup, fireEvent, render } from '@solidjs/testing-library';import { type Accessor, createSignal, For, type ParentProps } from 'solid-js';import { afterEach, describe, expect, it, vi } from 'vitest';-import { DocumentConversation } from './DocumentConversation';+import { EntityConversation } from './EntityConversation';const mocks = vi.hoisted(() => ({timeline: vi.fn(),@@ -124,7 +124,7 @@ function discussion(return {setPages,...render(() => (- <DocumentConversation+ <EntityConversationparent={{ type: 'document', id: 'document' }}canWrite={options.canWrite ?? false}targetId={targetId}@@ -135,7 +135,7 @@ function discussion(};}-describe('DocumentConversation placement', () => {+describe('EntityConversation placement', () => {it('renders the Discussion disclosure as an icon instead of a text glyph', () => {const view = discussion([[]]);const button = view.getByRole('button', { name: 'Discussion' });@@ -248,7 +248,7 @@ describe('DocumentConversation placement', () => {});});-describe('DocumentConversation linked message highlight', () => {+describe('EntityConversation linked message highlight', () => {it('releases the highlight while keeping the linked view around its root', () => {const [cleared, setCleared] = createSignal(false);mocks.timeline.mockReturnValue({@@ -256,7 +256,7 @@ describe('DocumentConversation linked message highlight', () => {data: { pages: [{ items: [thread('root-of-reply', null)] }] },});const view = render(() => (- <DocumentConversation+ <EntityConversationparent={{ type: 'document', id: 'document' }}canWrite={false}targetId="reply"@@ -293,7 +293,7 @@ it('retains loaded comments on a pagination failure and removes them immediatelyfetchNextPage: loadMore,});const view = render(() => (- <DocumentConversation+ <EntityConversationparent={{ type: 'initiative', id: 'project' }}canWrite/>@@ -330,7 +330,7 @@ it('hides cached comments when a linked message denies access and retries the lirefetch,});const view = render(() => (- <DocumentConversation+ <EntityConversationparent={{ type: 'initiative', id: 'project' }}targetId="linked-message"canWritediff --git a/apps/web/src/lib/core/messages/DocumentConversation.tsx b/apps/web/src/lib/core/messages/EntityConversation.tsxsimilarity index 96%rename from apps/web/src/lib/core/messages/DocumentConversation.tsxrename to apps/web/src/lib/core/messages/EntityConversation.tsxindex 2cfd4d44d0..dd750ccaae 100644--- a/apps/web/src/lib/core/messages/DocumentConversation.tsx+++ b/apps/web/src/lib/core/messages/EntityConversation.tsx@@ -18,7 +18,7 @@ import { MessageThread } from './MessageThread';import type { MessageData } from './types';/** The root composer, inline below the roots or floating on touch devices. */-export function DocumentConversationComposer(props: {+export function EntityConversationComposer(props: {parent: MessageParent;collapsible?: boolean;/** Dismiss the keyboard after submitting from a floating mobile composer. */@@ -53,7 +53,7 @@ export function DocumentConversationComposer(props: {);}-export function DocumentConversation(props: {+export function EntityConversation(props: {parent: MessageParent;canWrite: boolean;targetId?: string | null;@@ -102,7 +102,7 @@ export function DocumentConversation(props: {);return (<Show when={!props.hideWhenEmpty || messages().length > 0}>- <section class="mt-3 pb-12" data-document-conversation>+ <section class="mt-3 pb-12" data-entity-conversation><buttontype="button"class="flex items-center gap-1"@@ -167,7 +167,7 @@ export function DocumentConversation(props: {when={props.canWrite && !props.hideComposer && !unavailable()}><div class="mt-4">- <DocumentConversationComposer parent={props.parent} />+ <EntityConversationComposer parent={props.parent} /></div></Show></StaticMarkdownContext>diff --git a/apps/web/src/lib/core/messages/EntityDiscussion.tsx b/apps/web/src/lib/core/messages/EntityDiscussion.tsxnew file mode 100644index 0000000000..92e6a9a2aa--- /dev/null+++ b/apps/web/src/lib/core/messages/EntityDiscussion.tsx@@ -0,0 +1,128 @@+import { ChannelInputContainer } from '@channel/Input/ChannelInputContainer';+import { FloatRegion } from '@components/app/mobile/float-regions/FloatRegion';+import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';+import {+ useParamNavigationCount,+ useUrlParams,+} from '@core/component/ParamsProvider';+import { isTouchDevice } from '@core/mobile/isTouchDevice';+import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';+import { buildSimpleEntityUrl } from '@core/util/url';+import type { MessageParent } from '@service-storage/messages';+import {+ createEffect,+ createMemo,+ createSignal,+ on,+ onCleanup,+ Show,+} from 'solid-js';+import { COMMENT_LINK_PARAM } from './comment-link';+import {+ EntityConversation,+ EntityConversationComposer,+} from './EntityConversation';+import { scrollToRenderedTarget } from './scroll-to-rendered-target';++function MobileMessageComposer(props: {+ parent: MessageParent;+ hidden: boolean;+}) {+ // Preserve the editor and draft while its placement is hidden.+ const input = (+ <EntityConversationComposer parent={props.parent} collapsible blurOnSend />+ );++ return (+ <FloatRegion region="accessory">+ <Show when={!props.hidden}>+ <ChannelInputContainer>{input}</ChannelInputContainer>+ </Show>+ </FloatRegion>+ );+}++/**+ * An entity's unanchored discussion on the shared message components, opened+ * at the message a `comment_id` link names.+ */+export function EntityDiscussion(props: {+ parent: MessageParent;+ canWrite: boolean;+ /** Where copied message links open: the entity's block and id. */+ link: { type: string; id: string };+ label?: string;+ /**+ * On touch devices, move the composer to the floating accessory region and+ * show the conversation only once it has roots, as the editor page does.+ */+ floatingComposerOnTouch?: boolean;+ editorHasFocus?: boolean;+}) {+ const params = useUrlParams({ commentId: COMMENT_LINK_PARAM });+ const floating = () =>+ props.floatingComposerOnTouch === true && isTouchDevice();+ let container: HTMLDivElement | undefined;+ // Scroll to the linked message once per navigation of `comment_id`, as the+ // margin does for anchored comments. A repeat navigation to the same message+ // still scrolls; the URL value showing through after a navigation cleared it+ // does not.+ const commentNavigationCount = useParamNavigationCount(COMMENT_LINK_PARAM);+ const scrollRequest = createMemo(+ () => {+ const commentId = params.commentId();+ if (!commentId) return undefined;+ const count = commentNavigationCount();+ return {+ commentId,+ key: count === 0 ? `url:${commentId}` : `navigation:${count}`,+ };+ },+ undefined,+ { equals: (a, b) => a?.key === b?.key }+ );+ // Clicking the linked message releases its highlight until the next+ // navigation to a comment.+ const [clearedKey, setClearedKey] = createSignal<string>();+ const targetCleared = () => {+ const key = scrollRequest()?.key;+ return key !== undefined && key === clearedKey();+ };+ let scrolledKey: string | undefined;+ createEffect(+ on(scrollRequest, (request) => {+ if (!request || !container || request.key === scrolledKey) return;+ scrolledKey = request.key;+ onCleanup(scrollToRenderedTarget(container, request.commentId));+ })+ );+ return (+ <>+ <div ref={container} class="contents">+ <EntityConversation+ parent={props.parent}+ canWrite={props.canWrite}+ targetId={params.commentId()}+ targetCleared={targetCleared()}+ onClearTarget={() => setClearedKey(scrollRequest()?.key)}+ label={props.label}+ buildLink={(message) =>+ buildSimpleEntityUrl(props.link, {+ [COMMENT_LINK_PARAM]: message.id,+ })+ }+ hideComposer={floating()}+ hideWhenEmpty={floating()}+ />+ </div>+ <Show when={floating() && props.canWrite}>+ <StaticMarkdownContext>+ <MobileMessageComposer+ parent={props.parent}+ hidden={props.editorHasFocus === true && virtualKeyboardVisible()}+ />+ </StaticMarkdownContext>+ </Show>+ </>+ );+}diff --git a/apps/web/src/lib/core/messages/comment-link.ts b/apps/web/src/lib/core/messages/comment-link.tsnew file mode 100644index 0000000000..16241d2265--- /dev/null+++ b/apps/web/src/lib/core/messages/comment-link.ts@@ -0,0 +1,2 @@+/** The URL parameter a discussion link uses to name its message. */+export const COMMENT_LINK_PARAM = 'comment_id';diff --git a/apps/web/src/lib/queries/crm/comments.ts b/apps/web/src/lib/queries/crm/comments.tsdeleted file mode 100644index e64eca9b2b..0000000000--- a/apps/web/src/lib/queries/crm/comments.ts+++ /dev/null@@ -1,84 +0,0 @@-import { throwOnErr } from '@core/util/result';-import { storageServiceClient } from '@service-storage/client';-import type { CrmCommentEntityType } from '@service-storage/generated/schemas/crmCommentEntityType';-import { useMutation, useQuery } from '@tanstack/solid-query';-import type { Accessor } from 'solid-js';-import { crmKeys } from './keys';--const CRM_COMMENTS_STALE_TIME = 60 * 1000;--/**- * Comment threads for a CRM company or contact via- * `GET /crm/comments/{entityType}/{entityId}`. Disabled until an entity- * id is available.- */-export function useCrmCommentsQuery(- entityType: CrmCommentEntityType,- entityId: Accessor<string | undefined>-) {- return useQuery(() => {- const id = entityId();- return {- queryKey: crmKeys.comments(entityType, id ?? '').queryKey,- queryFn: () => {- if (!id) {- throw new Error('entity id is required to fetch comments');- }- return throwOnErr(() =>- storageServiceClient.crmComments.list({ entityType, entityId: id })- );- },- enabled: !!id,- staleTime: CRM_COMMENTS_STALE_TIME,- };- });-}--/**- * Creates a CRM comment — a new thread when `threadId` is omitted, a reply- * otherwise. Returns the updated thread; cache reconciliation is left to- * the caller (the discussion source does point updates).- */-export function useCreateCrmCommentMutation() {- return useMutation(() => ({- mutationFn: ({- entityType,- entityId,- text,- threadId,- }: {- entityType: CrmCommentEntityType;- entityId: string;- text: string;- threadId?: string;- }) =>- throwOnErr(() =>- storageServiceClient.crmComments.create({- entityType,- entityId,- body: { text, threadId },- })- ),- }));-}--/** Edits a CRM comment's text; returns the updated comment. */-export function useEditCrmCommentMutation() {- return useMutation(() => ({- mutationFn: ({ commentId, text }: { commentId: string; text: string }) =>- throwOnErr(() =>- storageServiceClient.crmComments.edit({ commentId, body: { text } })- ),- }));-}--/**- * Deletes a CRM comment; the result reports whether the whole thread- * went with it (last comment deleted).- */-export function useDeleteCrmCommentMutation() {- return useMutation(() => ({- mutationFn: ({ commentId }: { commentId: string }) =>- throwOnErr(() => storageServiceClient.crmComments.delete({ commentId })),- }));-}diff --git a/apps/web/src/lib/queries/crm/keys.ts b/apps/web/src/lib/queries/crm/keys.tsindex bfbed8f47a..5fc75eb5c8 100644--- a/apps/web/src/lib/queries/crm/keys.ts+++ b/apps/web/src/lib/queries/crm/keys.ts@@ -1,13 +1,8 @@import { createQueryKeys } from '@lukemorales/query-key-factory';-import type { CrmCommentEntityType } from '@service-storage/generated/schemas/crmCommentEntityType';export const crmKeys = createQueryKeys('crm', {lists: null,company: (companyId: string) => [companyId],contact: (contactId: string) => [contactId],contactByEmail: (teamId: string, email: string) => [teamId, email],- comments: (entityType: CrmCommentEntityType, entityId: string) => [- entityType,- entityId,- ],});diff --git a/apps/web/src/lib/queries/messages/sync.ts b/apps/web/src/lib/queries/messages/sync.tsindex 6454449b07..7539d5092f 100644--- a/apps/web/src/lib/queries/messages/sync.ts+++ b/apps/web/src/lib/queries/messages/sync.ts@@ -88,6 +88,8 @@ export function applyMessage(created_at: message.created_at,updated_at: message.created_at,resolved: false,+ // Only document roots can be anchored; theirs load with the thread.+ ...(parent.type !== 'document' && { anchor: null }),},thread: { reply_count: 0, preview: [], latest_reply_at: null },};diff --git a/apps/web/src/lib/queries/messages/tests/sync.test.ts b/apps/web/src/lib/queries/messages/tests/sync.test.tsindex 1d843a74c0..d7500fc79a 100644--- a/apps/web/src/lib/queries/messages/tests/sync.test.ts+++ b/apps/web/src/lib/queries/messages/tests/sync.test.ts@@ -76,7 +76,7 @@ afterEach(() => {testQueryClient.clear();clearTypingIndicators();});-describe.each(['channel', 'document', 'initiative'] as const)(+describe.each(['channel', 'document', 'initiative', 'crm_company'] as const)('%s uses the shared live cache',(type) => {const parent: MessageParent = { type, id: 'source' };@@ -404,6 +404,7 @@ describe.each(['channel', 'document', 'initiative'] as const)(} else {expect(mocks.thread).not.toHaveBeenCalled();expect(newestRoot().id).toBe('newer-root');+ expect(newestRoot().state.anchor).toBeNull();}// Only the soft invalidation that leaves mounted timelines alone may run.for (const [filters] of invalidate.mock.calls) {diff --git a/apps/web/src/lib/service-clients/service-storage/client.ts b/apps/web/src/lib/service-clients/service-storage/client.tsindex 14d8ea3d52..0ed8cf349f 100644--- a/apps/web/src/lib/service-clients/service-storage/client.ts+++ b/apps/web/src/lib/service-clients/service-storage/client.ts@@ -60,7 +60,6 @@ import type { CreateChannelResponse } from './generated/schemas/createChannelResimport type { CreateChannelScopedBotRequest } from './generated/schemas/createChannelScopedBotRequest';import type { CreateChannelScopedBotResponse } from './generated/schemas/createChannelScopedBotResponse';import type { CreateCommentResponse } from './generated/schemas/createCommentResponse';-import type { CreateCrmCommentRequest } from './generated/schemas/createCrmCommentRequest';import type { CreateCrmCompanyRequest } from './generated/schemas/createCrmCompanyRequest';import type { CreateCrmContactRequest } from './generated/schemas/createCrmContactRequest';import type { CreateDocument200 as CreateDocumentResponse } from './generated/schemas/createDocument200';@@ -80,15 +79,11 @@ import type { CreateSnippetRequest } from './generated/schemas/createSnippetRequimport type { CreateTaskHandler200 } from './generated/schemas/createTaskHandler200';import type { CreateTaskRequest } from './generated/schemas/createTaskRequest';import type { CreateUnthreadedAnchorResponse } from './generated/schemas/createUnthreadedAnchorResponse';-import type { CrmComment } from './generated/schemas/crmComment';-import type { CrmCommentEntityType } from './generated/schemas/crmCommentEntityType';-import type { CrmCommentThread } from './generated/schemas/crmCommentThread';import type { CrmCompanyResponse } from './generated/schemas/crmCompanyResponse';import type { CrmContactResponse } from './generated/schemas/crmContactResponse';import type { CrmStagesResponse } from './generated/schemas/crmStagesResponse';import type { CrmTeamSettingsResponse } from './generated/schemas/crmTeamSettingsResponse';import type { DeleteCommentResponse } from './generated/schemas/deleteCommentResponse';-import type { DeleteCrmCommentResult } from './generated/schemas/deleteCrmCommentResult';import type { DeleteEntityMentionResponse } from './generated/schemas/deleteEntityMentionResponse';import type { DeleteUnthreadedAnchorResponse } from './generated/schemas/deleteUnthreadedAnchorResponse';import type { DocumentMetadata } from './generated/schemas/documentMetadata';@@ -97,7 +92,6 @@ import type { DocumentResponseMetadataWithContent } from './generated/schemas/doimport type { DocumentTeamShareResponse } from './generated/schemas/documentTeamShareResponse';import type { EditAnchorResponse } from './generated/schemas/editAnchorResponse';import type { EditCommentResponse } from './generated/schemas/editCommentResponse';-import type { EditCrmCommentRequest } from './generated/schemas/editCrmCommentRequest';import type { ExportDocumentResponse } from './generated/schemas/exportDocumentResponse';import type { Favorite } from './generated/schemas/favorite';import type { FavoritesList } from './generated/schemas/favoritesList';@@ -2608,52 +2602,6 @@ export const storageServiceClient = {async resetCrmTeamStages() {return await dssFetch('/crm/stages', { method: 'DELETE' });},- crmComments: {- async list({- entityType,- entityId,- }: {- entityType: CrmCommentEntityType;- entityId: string;- }) {- return await dssFetch<CrmCommentThread[]>(- `/crm/comments/${entityType}/${entityId}`,- { method: 'GET' }- );- },- async create({- entityType,- entityId,- body,- }: {- entityType: CrmCommentEntityType;- entityId: string;- body: CreateCrmCommentRequest;- }) {- return await dssFetch<CrmCommentThread>(- `/crm/comments/${entityType}/${entityId}`,- { method: 'POST', body: JSON.stringify(body) }- );- },- async edit({- commentId,- body,- }: {- commentId: string;- body: EditCrmCommentRequest;- }) {- return await dssFetch<CrmComment>(`/crm/comment/${commentId}`, {- method: 'PATCH',- body: JSON.stringify(body),- });- },- async delete({ commentId }: { commentId: string }) {- return await dssFetch<DeleteCrmCommentResult>(- `/crm/comment/${commentId}`,- { method: 'DELETE' }- );- },- },} satisfies StorageServiceClient &typeof enhancements &Record<string, unknown>;diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex 68a8c83510..ef335e26ea 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -1161,6 +1161,13 @@ Company and contact headers have `Copy link` beside the side-panel toggle.It copies the record's direct URL and shows a confirmation toast; this is alsoavailable in the embedded company and contact breadcrumb header.+Company and contact pages have a **Discussion** section built from the same+message conversation as a document's Discussion: threaded replies, reactions,+attachments, and edit/delete from the message menu. `@` suggests the team's+members and agents. A message's copied link is the standalone record URL+with `comment_id`; opening it, or a CRM discussion notification, scrolls to and+highlights that message. Deleting a thread's first comment deletes the thread.+Company selection actions **Set owner** and **Set revenue** remain availablewhile team deal-stage definitions are loading. **Set stage** waits for the activeteam definition rather than opening an editor with system defaults. Check both