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.

feat(notifications): open comment notifications at their comment from inbox rows (#6869)

gbirmanfc7be15d95d3
diff --git a/apps/web/src/components/app/PreviewPanel.tsx b/apps/web/src/components/app/PreviewPanel.tsx
index a1b763e5e2..10245a55c1 100644
--- a/apps/web/src/components/app/PreviewPanel.tsx
+++ b/apps/web/src/components/app/PreviewPanel.tsx
@@ -1,6 +1,8 @@
import {
+ getDocumentCommentTarget,
navigateCalendarPreviewToTarget,
navigateChannelEntityToTarget,
+ navigateDocumentEntityToComment,
} from '@app/features/next-soup/utils';
import { useHotkeyDOMScope } from '@core/hotkey/hotkeys';
import type { BlockOrchestrator } from '@core/orchestrator';
@@ -103,6 +105,13 @@ function PreviewPanelContent(
entity.target?.threadId,
]);
}
+ if (entity.type === 'document') {
+ return JSON.stringify([
+ entity.type,
+ entity.id,
+ getDocumentCommentTarget(entity)?.commentId,
+ ]);
+ }
return entity;
});
@@ -119,6 +128,8 @@ function PreviewPanelContent(
void navigateChannelEntityToTarget(entity, props.orchestrator);
} else if (entity.type === 'calendar_event') {
void navigateCalendarPreviewToTarget(entity, props.orchestrator);
+ } else if (entity.type === 'document') {
+ void navigateDocumentEntityToComment(entity, props.orchestrator);
}
})
);
diff --git a/apps/web/src/components/app/previewTarget.ts b/apps/web/src/components/app/previewTarget.ts
index dfeefb37c7..6978314eff 100644
--- a/apps/web/src/components/app/previewTarget.ts
+++ b/apps/web/src/components/app/previewTarget.ts
@@ -3,6 +3,7 @@ import {
type ChannelPreviewSelection,
calendarViewTargetForEntity,
getChannelEntityTarget,
+ getDocumentCommentTarget,
type ReminderPreviewSelection,
reminderSplitTarget,
} from '@app/features/next-soup/utils';
@@ -15,7 +16,11 @@ import type {
} from '@core/block';
import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';
import { USE_MACRO_PR_SUMMARY_BLOCK } from '@core/constant/featureFlags';
-import type { DocumentEntity, ForeignEntity } from '@entity';
+import type {
+ DocumentCommentTarget,
+ DocumentEntity,
+ ForeignEntity,
+} from '@entity';
import { untrack } from 'solid-js';
import { match, P } from 'ts-pattern';
@@ -35,7 +40,7 @@ type IdOnlyPreviewSelection = {
type DocumentPreviewSelection = Pick<
DocumentEntity,
'id' | 'type' | 'fileType' | 'subType'
->;
+> & { commentTarget?: DocumentCommentTarget };
type ForeignPreviewSelection = Pick<
ForeignEntity,
@@ -57,6 +62,9 @@ type PreviewBlockTarget = {
params?: BlockComponentProps[BlockName];
};
+const documentCommentParams = (document: DocumentPreviewSelection) =>
+ untrack(() => getDocumentCommentTarget(document)?.params);
+
export function previewBlockTarget(
entity: PreviewPanelSelection
): PreviewBlockTarget {
@@ -71,6 +79,7 @@ export function previewBlockTarget(
alias: 'task',
baseType: 'md',
} satisfies BlockAliasContext,
+ params: documentCommentParams(task),
})
)
.with(
@@ -82,12 +91,14 @@ export function previewBlockTarget(
alias: 'snippet',
baseType: 'md',
} satisfies BlockAliasContext,
+ params: documentCommentParams(snippet),
})
)
.with({ type: 'document' }, (document) => ({
blockType: fileTypeToResolvedBlockName(document.fileType),
blockId: document.id,
aliasContext: undefined,
+ params: documentCommentParams(document),
}))
.with({ type: P.union('channel_message', 'channel_thread') }, (message) => {
const channelTarget = untrack(() => getChannelEntityTarget(message));
diff --git a/apps/web/src/features/entity/extractors-notification/notification-description-helpers.ts b/apps/web/src/features/entity/extractors-notification/notification-description-helpers.ts
index 7d7c685e7b..0bb115152c 100644
--- a/apps/web/src/features/entity/extractors-notification/notification-description-helpers.ts
+++ b/apps/web/src/features/entity/extractors-notification/notification-description-helpers.ts
@@ -101,8 +101,8 @@ export function getActionVerb(type: NotificationType): string {
match(type)
.with('channel_mention', () => 'mentioned you')
.with('document_mention', () => 'shared with you')
- .with('mentioned_in_document_comment', () => 'mentioned you')
- .with('replied_to_document_comment_thread', () => 'replied')
+ .with('mentioned_in_document_comment', () => 'mentioned you in a comment')
+ .with('replied_to_document_comment_thread', () => 'replied to a comment')
.with('commented_on_document', () => 'commented')
.with('channel_message_reply', () => 'replied')
.with('channel_message_send', () => 'sent a message')
diff --git a/apps/web/src/features/entity/extractors-notification/notification-icon.tsx b/apps/web/src/features/entity/extractors-notification/notification-icon.tsx
index 6b12644275..e03fd03a96 100644
--- a/apps/web/src/features/entity/extractors-notification/notification-icon.tsx
+++ b/apps/web/src/features/entity/extractors-notification/notification-icon.tsx
@@ -6,6 +6,7 @@ import AtIcon from '@phosphor/at.svg';
import BellIcon from '@phosphor/bell-simple.svg';
import CalendarBlankIcon from '@phosphor/calendar-blank.svg';
import ChatIcon from '@phosphor/chat.svg';
+import ChatTeardropIcon from '@phosphor/chat-teardrop.svg';
import CheckIcon from '@phosphor/check.svg';
import EnvelopeIcon from '@phosphor/envelope.svg';
import FilesIcon from '@phosphor/files.svg';
@@ -34,9 +35,14 @@ function getNotificationIcon(
return match(type)
.with('channel_mention', () => AtIcon)
.with('document_mention', () => FilesIcon)
- .with('mentioned_in_document_comment', () => AtIcon)
- .with('replied_to_document_comment_thread', () => ArrowBendUpLeftIcon)
- .with('commented_on_document', () => ChatIcon)
+ .with(
+ P.union(
+ 'mentioned_in_document_comment',
+ 'replied_to_document_comment_thread',
+ 'commented_on_document'
+ ),
+ () => ChatTeardropIcon
+ )
.with('channel_message_reply', () => ArrowBendUpLeftIcon)
.with('channel_message_send', () => ChatIcon)
.with('new_email', () => EnvelopeIcon)
diff --git a/apps/web/src/features/entity/tests/notification-description.test.ts b/apps/web/src/features/entity/tests/notification-description.test.ts
index 25ecc350d5..8053791e4b 100644
--- a/apps/web/src/features/entity/tests/notification-description.test.ts
+++ b/apps/web/src/features/entity/tests/notification-description.test.ts
@@ -198,7 +198,7 @@ describe('notification-description helpers', () => {
it('returns correct verb for mentioned_in_document_comment', () => {
expect(getActionVerb('mentioned_in_document_comment')).toBe(
- 'mentioned you'
+ 'mentioned you in a comment'
);
});
diff --git a/apps/web/src/features/entity/types/entity.ts b/apps/web/src/features/entity/types/entity.ts
index a3fe809674..21bb76be3c 100644
--- a/apps/web/src/features/entity/types/entity.ts
+++ b/apps/web/src/features/entity/types/entity.ts
@@ -92,6 +92,14 @@ export type ChannelEntityTarget = {
threadId?: string;
};
+/**
+ * The comment a document row opens at when it is not derived from the row's
+ * notifications, e.g. a preview rebuilt from its route.
+ */
+export type DocumentCommentTarget = {
+ commentId: string;
+};
+
/**
* The resolved click intent for a channel-family row. Either a specific
* message to jump to and highlight, or `latest` — open the channel at its
diff --git a/apps/web/src/features/inbox-view/components/HomeListEntity.tsx b/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
index e0fd68692f..c4f97b96bc 100644
--- a/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
+++ b/apps/web/src/features/inbox-view/components/HomeListEntity.tsx
@@ -5,10 +5,14 @@ import { getDisplayName, tryMacroId } from '@core/user';
import { Entity, MaybeEntityRow } from '@entity';
import type { BaseListEntityProps } from '@entity/composed/list-entity/shared';
import { unreadFilterFn } from '@entity/utils/filter';
+import { getDocumentCommentNotification } from '@notifications/document-comment-notification';
+import type { UnifiedNotification } from '@notifications/types';
import ArrowBendUpLeftIcon from '@phosphor-icons/core/regular/arrow-bend-up-left.svg?component-solid';
+import ChatTeardropIcon from '@phosphor-icons/core/regular/chat-teardrop.svg?component-solid';
import { getBotDisplayName } from '@queries/messages/message-sender';
import { cn, pressHandlers } from '@ui';
-import { Show } from 'solid-js';
+import { Match, Show, Switch } from 'solid-js';
+import { match } from 'ts-pattern';
import { HomeEntityIcon } from './HomeEntityIcon';
type HomeListEntityProps = BaseListEntityProps & {
@@ -20,6 +24,10 @@ type HomeListEntityProps = BaseListEntityProps & {
export function HomeListEntity(props: HomeListEntityProps) {
const threadEntity = () =>
props.entity.type === 'channel_thread' ? props.entity : undefined;
+ // A document announcing an unread comment reads like a thread row: the
+ // comment glyph, who did what, and where. Opening it lands on the comment.
+ const commentNotification = () =>
+ getDocumentCommentNotification(props.entity);
const unread = () => unreadFilterFn(props.entity);
return (
@@ -41,22 +49,25 @@ export function HomeListEntity(props: HomeListEntityProps) {
})}
data-home-item
>
- <Show
- when={threadEntity()}
- fallback={<HomeEntityIcon entity={props.entity} />}
- >
- <ViewSidebar.Icon>
- <ArrowBendUpLeftIcon class="size-4" />
- </ViewSidebar.Icon>
- </Show>
+ <Switch fallback={<HomeEntityIcon entity={props.entity} />}>
+ <Match when={threadEntity()}>
+ <ViewSidebar.Icon>
+ <ArrowBendUpLeftIcon class="size-4" />
+ </ViewSidebar.Icon>
+ </Match>
+ <Match when={commentNotification()}>
+ <ViewSidebar.Icon>
+ <ChatTeardropIcon class="size-4" />
+ </ViewSidebar.Icon>
+ </Match>
+ </Switch>
<span
class={cn(
'block min-w-0 flex-1 truncate font-normal',
unread() && 'text-ink'
)}
>
- <Show
- when={threadEntity()}
+ <Switch
fallback={
<Show
when={props.channelName}
@@ -66,13 +77,23 @@ export function HomeListEntity(props: HomeListEntityProps) {
</Show>
}
>
- {(thread) => (
- <HomeThreadTitle
- entity={thread()}
- channelName={props.channelName}
- />
- )}
- </Show>
+ <Match when={threadEntity()}>
+ {(thread) => (
+ <HomeThreadTitle
+ entity={thread()}
+ channelName={props.channelName}
+ />
+ )}
+ </Match>
+ <Match when={commentNotification()}>
+ {(notification) => (
+ <HomeCommentTitle
+ entity={props.entity}
+ notification={notification()}
+ />
+ )}
+ </Match>
+ </Switch>
</span>
<span
data-home-timestamp
@@ -152,3 +173,30 @@ function HomeThreadTitle(
</span>
);
}
+
+function HomeCommentTitle(props: {
+ entity: HomeListEntityProps['entity'];
+ notification: UnifiedNotification;
+}) {
+ const sender = () => {
+ const senderId = props.notification.sender_id;
+ return senderId
+ ? getDisplayName(tryMacroId(senderId), { emailFallback: 'local-part' }) ||
+ 'Someone'
+ : 'Someone';
+ };
+ const action = () =>
+ match(props.notification.notification_metadata.tag)
+ .with('mentioned_in_document_comment', () => ' mentioned you on ')
+ .with('replied_to_document_comment_thread', () => ' replied on ')
+ .otherwise(() => ' commented on ');
+ return (
+ <span class="flex min-w-0 items-center">
+ <span class="max-w-1/2 shrink-0 truncate">{sender()}</span>
+ <span class="shrink-0 whitespace-pre">{action()}</span>
+ <span class="min-w-0 truncate">
+ <Entity.Title entity={props.entity} />
+ </span>
+ </span>
+ );
+}
diff --git a/apps/web/src/features/inbox-view/components/home-press.test.tsx b/apps/web/src/features/inbox-view/components/home-press.test.tsx
index d70ea01ce8..65e36e3be0 100644
--- a/apps/web/src/features/inbox-view/components/home-press.test.tsx
+++ b/apps/web/src/features/inbox-view/components/home-press.test.tsx
@@ -84,3 +84,45 @@ describe.each(['recent', 'new chat'] as const)('Home %s press', (kind) => {
expect(activate).not.toHaveBeenCalled();
});
});
+
+describe('Home document comment row', () => {
+ const commentNotification = (state: 'unseen' | 'seen') => ({
+ id: 'n1',
+ entity_id: 'doc-1',
+ entity_type: 'document',
+ sender_id: 'macro|[email protected]',
+ state,
+ created_at: '2026-09-23T00:00:00Z',
+ notification_metadata: {
+ tag: 'mentioned_in_document_comment',
+ content: { commentId: 'comment-1', documentName: 'Plan' },
+ },
+ });
+
+ const renderRow = (state: 'unseen' | 'seen') =>
+ render(() => (
+ <HomeListEntity
+ entity={
+ {
+ type: 'document',
+ id: 'doc-1',
+ name: 'Plan',
+ ownerId: 'test-user',
+ fileType: 'md',
+ notifications: () => [commentNotification(state)],
+ } as never
+ }
+ occurrenceKey="doc-1"
+ />
+ )).container.querySelector<HTMLElement>('[data-home-item]')!;
+
+ it('announces an unread comment mention', () => {
+ expect(renderRow('unseen').textContent).toContain(
+ 'Peter mentioned you on Recent chat'
+ );
+ });
+
+ it('reads as the plain document once the comment is read', () => {
+ expect(renderRow('seen').textContent).not.toContain('mentioned you');
+ });
+});
diff --git a/apps/web/src/features/inbox-view/inbox-preview-navigation.ts b/apps/web/src/features/inbox-view/inbox-preview-navigation.ts
index fb7d5b6bdd..d876486222 100644
--- a/apps/web/src/features/inbox-view/inbox-preview-navigation.ts
+++ b/apps/web/src/features/inbox-view/inbox-preview-navigation.ts
@@ -1,4 +1,7 @@
-import { getChannelEntityTarget } from '@app/features/next-soup/utils';
+import {
+ getChannelEntityTarget,
+ getDocumentCommentTarget,
+} from '@app/features/next-soup/utils';
import type { CalendarBlockProps } from '@block-calendar/types';
import {
type PreviewPanelSelection,
@@ -70,6 +73,7 @@ function selectionSearch(
...base,
fileType: selection.fileType ?? '',
subType: selection.subType?.type ?? '',
+ targetCommentId: getDocumentCommentTarget(selection)?.commentId ?? '',
};
case 'foreign':
return { ...base, foreignSource: selection.foreignSource };
diff --git a/apps/web/src/features/inbox-view/inbox-route.ts b/apps/web/src/features/inbox-view/inbox-route.ts
index 06dda12986..94a3749e6a 100644
--- a/apps/web/src/features/inbox-view/inbox-route.ts
+++ b/apps/web/src/features/inbox-view/inbox-route.ts
@@ -7,6 +7,7 @@ import type { SplitContent } from '@components/app/split-layout/layoutManager';
import type { BlockName } from '@core/block';
import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';
import { USE_MACRO_PR_SUMMARY_BLOCK } from '@core/constant/featureFlags';
+import { documentCommentLocation } from '@notifications/document-comment-location';
import { match } from 'ts-pattern';
import { z } from 'zod';
import type { InboxPreviewRouteParams } from './inbox-route-schema';
@@ -64,6 +65,7 @@ export const inboxPreviewSearch = {
sourceThreadId: z.string(),
targetMessageId: z.string(),
targetThreadId: z.string(),
+ targetCommentId: z.string(),
eventId: z.string(),
occurrenceKey: z.string(),
calendarTimeKind: z.enum(calendarTimeKinds),
@@ -86,6 +88,7 @@ export const inboxPreviewSearch = {
sourceThreadId: '',
targetMessageId: '',
targetThreadId: '',
+ targetCommentId: '',
eventId: '',
occurrenceKey: '',
calendarTimeKind: '' as const,
@@ -244,6 +247,9 @@ function decodedSelection(
},
}
: {}),
+ ...(search.targetCommentId
+ ? { commentTarget: { commentId: search.targetCommentId } }
+ : {}),
}))
.with('foreign', () => ({
type: 'foreign',
@@ -324,6 +330,15 @@ export function inboxPreviewSelection(
: fallbackSelection(params);
}
+function legacyCommentParams(search: InboxPreviewSearchParams) {
+ return search.targetCommentId
+ ? documentCommentLocation(search.targetCommentId, {
+ fileType: search.fileType,
+ subType: search.subType ? { type: search.subType } : undefined,
+ }).params
+ : undefined;
+}
+
/** Full-block compatibility target for disabled or touch-only view surfaces. */
export function inboxPreviewLegacyTarget(
params: InboxPreviewRouteParams,
@@ -341,7 +356,18 @@ export function inboxPreviewLegacyTarget(
documentSubType === 'snippet' ||
documentSubType === 'skill')
) {
- return { type: documentSubType, id: params.previewId };
+ return {
+ type: documentSubType,
+ id: params.previewId,
+ params: legacyCommentParams(search),
+ };
+ }
+ if (search.selectionType === 'document' && search.targetCommentId) {
+ return {
+ type: params.blockType,
+ id: params.previewId,
+ params: legacyCommentParams(search),
+ };
}
if (params.blockType === 'channel' && search.targetMessageId) {
return {
diff --git a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
index 6da9d71c4c..741255770b 100644
--- a/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
+++ b/apps/web/src/features/next-soup/soup-view/views/inbox/inbox-card-layouts.tsx
@@ -36,7 +36,7 @@ import ArrowBendUpLeftIcon from '@phosphor-icons/core/regular/arrow-bend-up-left
import AtIcon from '@phosphor-icons/core/regular/at.svg?component-solid';
import BellSimpleIcon from '@phosphor-icons/core/regular/bell-simple.svg?component-solid';
import CalendarBlankIcon from '@phosphor-icons/core/regular/calendar-blank.svg?component-solid';
-import ChatCircleIcon from '@phosphor-icons/core/regular/chat-circle.svg?component-solid';
+import ChatTeardropIcon from '@phosphor-icons/core/regular/chat-teardrop.svg?component-solid';
import ChatTextIcon from '@phosphor-icons/core/regular/chat-text.svg?component-solid';
import PaperclipIcon from '@phosphor-icons/core/regular/paperclip.svg?component-solid';
import PhoneIcon from '@phosphor-icons/core/regular/phone.svg?component-solid';
@@ -269,19 +269,18 @@ const tagBubbleIcon = (tag: NotificationTag) =>
.with('ai_response', () => () => (
<EntityIcon class={AVATAR_GLYPH_CLASS} targetType="chat" size="fill" />
))
- .with('channel_mention', 'mentioned_in_document_comment', () => () => (
- <AtIcon class={AVATAR_GLYPH_CLASS} />
- ))
- .with('document_mention', () => () => (
- <FilesIcon class={AVATAR_GLYPH_CLASS} />
- ))
+ .with('channel_mention', () => () => <AtIcon class={AVATAR_GLYPH_CLASS} />)
.with(
- 'channel_message_reply',
+ 'mentioned_in_document_comment',
'replied_to_document_comment_thread',
- () => () => <ArrowBendUpLeftIcon class={AVATAR_GLYPH_CLASS} />
+ 'commented_on_document',
+ () => () => <ChatTeardropIcon class={AVATAR_GLYPH_CLASS} />
)
- .with('commented_on_document', () => () => (
- <ChatCircleIcon class={AVATAR_GLYPH_CLASS} />
+ .with('document_mention', () => () => (
+ <FilesIcon class={AVATAR_GLYPH_CLASS} />
+ ))
+ .with('channel_message_reply', () => () => (
+ <ArrowBendUpLeftIcon class={AVATAR_GLYPH_CLASS} />
))
.with('channel_message_send', () => () => (
<ChatTextIcon class={AVATAR_GLYPH_CLASS} />
@@ -1019,7 +1018,7 @@ export function DocumentCardLayout(props: InboxCardLayoutProps) {
return {
action: buildActionLabel({
sender: senderName(),
- action: 'mentioned you',
+ action: 'mentioned you in a comment',
}),
content,
};
@@ -1027,7 +1026,10 @@ export function DocumentCardLayout(props: InboxCardLayoutProps) {
if (metadata?.tag === 'replied_to_document_comment_thread') {
return {
- action: buildActionLabel({ sender: senderName(), action: 'replied' }),
+ action: buildActionLabel({
+ sender: senderName(),
+ action: 'replied to a comment',
+ }),
content,
};
}
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index 92eaa4ee52..a2b01155b5 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -1,3 +1,4 @@
+import { previewBlockTarget } from '@components/app/previewTarget';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { inboxPreviewNavigation } from '../inbox-view/inbox-preview-navigation';
@@ -111,6 +112,7 @@ import type { NotificationSource, UnifiedNotification } from '@notifications';
import {
executeMarkEntitiesDone,
getChannelEntityTarget,
+ getDocumentCommentTarget,
getRowClickFallbackLocation,
markChannelNotificationsSeenOnOpen,
openEntityInSplitFromUnifiedList,
@@ -865,6 +867,126 @@ describe('getChannelEntityTarget', () => {
});
});
+const commentNotification = (
+ id: string,
+ commentId: string,
+ overrides: Partial<UnifiedNotification> = {}
+) =>
+ ({
+ id,
+ entity_id: 'doc-1',
+ entity_type: 'document',
+ state: 'unseen',
+ notification_metadata: {
+ tag: 'mentioned_in_document_comment',
+ content: {
+ documentName: 'Plan',
+ fileType: 'md',
+ commentId,
+ threadId: 'thread-1',
+ text: 'hey @you',
+ },
+ },
+ ...overrides,
+ }) as unknown as UnifiedNotification;
+
+const documentRow = (notifications: UnifiedNotification[]) =>
+ ({
+ type: 'document',
+ id: 'doc-1',
+ fileType: 'md',
+ notifications: () => notifications,
+ }) as unknown as EntityData;
+
+describe('getDocumentCommentTarget', () => {
+ it('targets the newest unread comment notification', () => {
+ expect(
+ getDocumentCommentTarget(
+ documentRow([
+ commentNotification('older', 'comment-older', {
+ created_at: '2026-09-20T00:00:00Z',
+ }),
+ commentNotification('read', 'comment-read', {
+ state: 'seen',
+ created_at: '2026-09-23T00:00:00Z',
+ }),
+ commentNotification('done', 'comment-done', {
+ state: 'done',
+ created_at: '2026-09-23T00:00:00Z',
+ }),
+ commentNotification('newest', 'comment-newest', {
+ created_at: '2026-09-22T00:00:00Z',
+ }),
+ ])
+ )?.params
+ ).toEqual({ comment_id: 'comment-newest' });
+ });
+
+ it('opens a document normally once its comment notifications are read', () => {
+ expect(
+ getDocumentCommentTarget(
+ documentRow([commentNotification('n1', 'comment-1', { state: 'seen' })])
+ )
+ ).toBeUndefined();
+ });
+
+ it('ignores documents without notifications', () => {
+ expect(
+ getDocumentCommentTarget({ type: 'document', fileType: 'md' })
+ ).toBeUndefined();
+ });
+
+ it('opens the row at its comment like a comment link', async () => {
+ const openWithSplit = vi.fn(() => ({ status: 'unavailable' }));
+ const goToLocationFromParams = vi.fn();
+ const getBlockHandle = vi.fn(async () => ({ goToLocationFromParams }));
+ setGlobalSplitManager({
+ activeSplit: vi.fn(),
+ getOrchestrator: vi.fn(() => ({ getBlockHandle })),
+ getSplitByContent: vi.fn(),
+ openWithSplit,
+ } as unknown as SplitManager);
+
+ await openEntityInSplitFromUnifiedList(
+ documentRow([commentNotification('n1', 'comment-1')]),
+ {}
+ );
+
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: 'md', id: 'doc-1', params: { comment_id: 'comment-1' } },
+ expect.objectContaining({ activate: true })
+ );
+ expect(getBlockHandle).toHaveBeenCalledWith('doc-1', 'md');
+ expect(goToLocationFromParams).toHaveBeenCalledWith({
+ comment_id: 'comment-1',
+ });
+ });
+
+ it('carries the comment through the Inbox preview route', () => {
+ const result = inboxPreviewNavigation(
+ documentRow([commentNotification('n1', 'comment-1')]) as never
+ );
+ expect(result.search.targetCommentId).toBe('comment-1');
+ const selection = inboxPreviewSelection(result.params, result.search);
+ expect(selection).toMatchObject({
+ type: 'document',
+ id: 'doc-1',
+ commentTarget: { commentId: 'comment-1' },
+ });
+ expect(previewBlockTarget(selection!).params).toEqual({
+ comment_id: 'comment-1',
+ });
+ });
+
+ it('passes the comment to a document preview', () => {
+ expect(
+ previewBlockTarget(
+ documentRow([commentNotification('n1', 'comment-1')]) as never
+ ).params
+ ).toEqual({ comment_id: 'comment-1' });
+ });
+});
+
const emailHit = (messageId: string, content: string) => ({
type: 'email' as const,
content,
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 6333f7ddd6..2990534ad7 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -36,7 +36,10 @@ import type {
} from '@components/app/split-layout/layoutManager';
import { driveSplitContent } from '@components/app/split-layout/split-router/legacy-route';
import { toast } from '@core/component/Toast/Toast';
-import { fileTypeToBlockName } from '@core/constant/allBlocks';
+import {
+ fileTypeToBlockName,
+ resolveBlockAlias,
+} from '@core/constant/allBlocks';
import {
enableCalendarUi,
enableGraphqlSoup,
@@ -59,6 +62,8 @@ import {
type ChannelEntity,
type ChannelMessageEntity,
type ChannelThreadEntity,
+ type DocumentCommentTarget,
+ type DocumentEntity,
type EntityData,
emailQueryKeyExcludesDone,
getSnippetHit,
@@ -77,7 +82,10 @@ import {
} from '@entity';
import {
compositeEntity,
+ documentCommentLocation,
getChannelNotificationParams,
+ getDocumentCommentLocation,
+ getDocumentCommentNotification,
markNotificationsForEntityAsReadInBackground,
type NotificationSource,
notificationIsRead,
@@ -511,6 +519,32 @@ export function getChannelEntityTarget(
return fallback;
}
+/**
+ * Resolve the comment a document row opens at. A stamped `commentTarget` (the
+ * Inbox preview route carries one, since it keeps no notifications) wins;
+ * otherwise it is the row's newest unread comment notification, the one the
+ * row announces, so opening it lands on that comment exactly like a copied
+ * comment link. Read ones are skipped for the same reason as on a
+ * whole-`channel` row: once the document looks caught up it should open
+ * normally rather than scroll to an old comment.
+ */
+export function getDocumentCommentTarget(entity: {
+ type: string;
+ fileType?: string;
+ subType?: DocumentEntity['subType'];
+ commentTarget?: DocumentCommentTarget;
+}) {
+ if (entity.type !== 'document') return undefined;
+ const document = { fileType: entity.fileType, subType: entity.subType };
+ if (entity.commentTarget) {
+ return documentCommentLocation(entity.commentTarget.commentId, document);
+ }
+ if (!isWithNotification(entity)) return undefined;
+
+ const notification = getDocumentCommentNotification(entity);
+ return notification && getDocumentCommentLocation(notification, document);
+}
+
/**
* Activate a channel row's target message in its (already-open) channel block.
*
@@ -542,6 +576,21 @@ export async function navigateChannelEntityToTarget(
);
}
+/** Scrolls an already-open document block to the row's comment target. */
+export async function navigateDocumentEntityToComment(
+ entity: Pick<DocumentEntity, 'id' | 'type' | 'fileType' | 'subType'>,
+ blockOrchestrator: BlockOrchestrator
+): Promise<void> {
+ const target = getDocumentCommentTarget(entity);
+ if (!target?.params) return;
+
+ const handle = await blockOrchestrator.getBlockHandle(
+ entity.id,
+ resolveBlockAlias(target.blockName)
+ );
+ await handle?.goToLocationFromParams(target.params);
+}
+
export type CalendarPreviewSelection = WithNotification<
Pick<CalendarEventEntity, 'id' | 'type' | 'time' | 'occurrenceKey'>
>;
@@ -678,6 +727,11 @@ export const openEntityInSplitFromUnifiedList = async (
} else if (entity.type === 'call' && location?.type === 'call_record') {
params = { [CALL_PARAMS.transcriptId]: location.transcriptId };
}
+ const commentParams =
+ !location && entity.type === 'document'
+ ? getDocumentCommentTarget(entity)?.params
+ : undefined;
+ params ??= commentParams;
const sourceContent =
splitHandle?.content() ?? splitManager.activeSplit()?.content();
@@ -691,9 +745,12 @@ export const openEntityInSplitFromUnifiedList = async (
// Documents are hosted by Drive. Construct the canonical routed content
// before opening the split so the layout manager does not mount a legacy
// block and immediately replace it during router feedback.
- const driveDocument = !isTouchDevice()
- ? driveDocumentFromContent(content)
- : undefined;
+ // A comment target opens the document block itself, exactly like a copied
+ // comment link, because Drive-hosted documents cannot take a comment target.
+ const driveDocument =
+ !isTouchDevice() && !commentParams
+ ? driveDocumentFromContent(content)
+ : undefined;
let splitContent: SplitContent = driveDocument
? driveSplitContent({ kind: 'tab', tab: 'owned' }, driveDocument)
: { ...content, params };
@@ -735,6 +792,9 @@ export const openEntityInSplitFromUnifiedList = async (
},
blockOrchestrator
);
+ } else if (commentParams && entity.type === 'document') {
+ // An already-open document ignores new split params.
+ await navigateDocumentEntityToComment(entity, blockOrchestrator);
} else if (openChannelAtLatest) {
// Force the scroll-to-bottom even when the channel is already open in a
// (preview) split, where reopen: 'latest' only reactivates the parked
diff --git a/apps/web/src/features/notifications/document-comment-location.ts b/apps/web/src/features/notifications/document-comment-location.ts
new file mode 100644
index 0000000000..aa9c773013
--- /dev/null
+++ b/apps/web/src/features/notifications/document-comment-location.ts
@@ -0,0 +1,82 @@
+import { URL_PARAMS as MD_URL_PARAMS } from '@block-md/constants';
+import { URL_PARAMS as PDF_URL_PARAMS } from '@block-pdf/constants';
+import type { BlockAlias, BlockName } from '@core/block';
+import {
+ type ItemLike,
+ itemToBlockName,
+ resolveBlockAlias,
+} from '@core/constant/allBlocks';
+import type { UnifiedNotification } from './types';
+
+// Minimal entity shape — the live entity from the UI is authoritative when
+// available (notification metadata is a snapshot at notification time and may
+// lack `subType` for older events).
+export type NotificationEntityOverride = {
+ fileType?: string | null;
+ subType?: { type: string } | null;
+};
+
+// Resolve the block type for a document notification, honoring `subType` so
+// that e.g. a markdown doc with `subType: { type: 'task' }` routes to the
+// 'task' block alias instead of raw 'md'. Prefers the live entity's fields
+// over the notification-metadata snapshot when provided.
+function safeDocumentContentToBlockName(
+ content: NotificationEntityOverride,
+ entity?: NotificationEntityOverride
+) {
+ return itemToBlockName({
+ type: 'document',
+ fileType: entity?.fileType ?? content.fileType ?? undefined,
+ subType: entity?.subType ?? content.subType ?? undefined,
+ } as ItemLike);
+}
+
+function resolveBlockCommentParamName(type: BlockName | BlockAlias) {
+ const resolved = resolveBlockAlias(type);
+ if (resolved === 'md' || resolved === 'spreadsheet')
+ return MD_URL_PARAMS.commentId;
+ if (resolved === 'pdf') return PDF_URL_PARAMS.annotationId;
+}
+
+type DocumentCommentLocation = {
+ blockName: BlockName | BlockAlias;
+ commentId: string;
+ params?: Record<string, string>;
+};
+
+/**
+ * The block and params that open a document at one of its comments, the same
+ * target a copied comment link resolves to.
+ */
+export function documentCommentLocation(
+ commentId: string,
+ document: NotificationEntityOverride
+): DocumentCommentLocation {
+ const blockName = safeDocumentContentToBlockName(document);
+ const commentParamName = resolveBlockCommentParamName(blockName);
+ return {
+ blockName,
+ commentId,
+ params: commentParamName ? { [commentParamName]: commentId } : undefined,
+ };
+}
+
+/** {@link documentCommentLocation} for a document comment notification. */
+export function getDocumentCommentLocation(
+ notification: UnifiedNotification,
+ entity?: NotificationEntityOverride
+): DocumentCommentLocation | undefined {
+ const meta = notification.notification_metadata;
+ if (
+ meta.tag !== 'mentioned_in_document_comment' &&
+ meta.tag !== 'replied_to_document_comment_thread' &&
+ meta.tag !== 'commented_on_document'
+ ) {
+ return undefined;
+ }
+
+ return documentCommentLocation(meta.content.commentId.toString(), {
+ fileType: entity?.fileType ?? meta.content.fileType,
+ subType: entity?.subType ?? meta.content.subType,
+ });
+}
diff --git a/apps/web/src/features/notifications/document-comment-notification.ts b/apps/web/src/features/notifications/document-comment-notification.ts
new file mode 100644
index 0000000000..27dac33bff
--- /dev/null
+++ b/apps/web/src/features/notifications/document-comment-notification.ts
@@ -0,0 +1,26 @@
+import { compareDateDesc } from '@core/util/date';
+import type { UnifiedNotification } from './types';
+
+export const DOCUMENT_COMMENT_EVENT_TYPES = [
+ 'mentioned_in_document_comment',
+ 'replied_to_document_comment_thread',
+ 'commented_on_document',
+] as const;
+
+const isDocumentCommentTag = (tag: string) =>
+ (DOCUMENT_COMMENT_EVENT_TYPES as readonly string[]).includes(tag);
+
+/** The newest unread comment notification a document row announces. */
+export function getDocumentCommentNotification(entity: {
+ type: string;
+ notifications?: () => UnifiedNotification[];
+}): UnifiedNotification | undefined {
+ if (entity.type !== 'document') return undefined;
+ return (entity.notifications?.() ?? [])
+ .filter(
+ (n) =>
+ n.state === 'unseen' &&
+ isDocumentCommentTag(n.notification_metadata.tag)
+ )
+ .sort((a, b) => compareDateDesc(a.created_at, b.created_at))[0];
+}
diff --git a/apps/web/src/features/notifications/index.ts b/apps/web/src/features/notifications/index.ts
index 6142a44b9c..9463036594 100644
--- a/apps/web/src/features/notifications/index.ts
+++ b/apps/web/src/features/notifications/index.ts
@@ -16,11 +16,17 @@ export {
usePlatformNotificationState,
} from './components/PlatformNotificationProvider';
export { NotificationsPlayground } from './components/Playground';
+export {
+ documentCommentLocation,
+ getDocumentCommentLocation,
+} from './document-comment-location';
+export { getDocumentCommentNotification } from './document-comment-notification';
export {
createEffectOnEntityTypeNotification,
entityHasUnreadNotifications,
executeMarkNotificationsDone,
executeMarkNotificationsUndone,
+ isDocumentCommentNotification,
markNotificationForEntityIdAsRead,
markNotificationsForEntityAsDone,
markNotificationsForEntityAsRead,
diff --git a/apps/web/src/features/notifications/notification-helpers.ts b/apps/web/src/features/notifications/notification-helpers.ts
index 9431561648..575b639c60 100644
--- a/apps/web/src/features/notifications/notification-helpers.ts
+++ b/apps/web/src/features/notifications/notification-helpers.ts
@@ -16,12 +16,9 @@ import {
} from '@queries/notification/user-notifications';
import { type Accessor, createEffect, createMemo, onCleanup } from 'solid-js';
import { isMatching, P } from 'ts-pattern';
+import { DOCUMENT_COMMENT_EVENT_TYPES } from './document-comment-notification';
import type { NotificationSource } from './notification-source';
-import {
- CHANNEL_EVENT_TYPES,
- DOCUMENT_COMMENT_EVENT_TYPES,
- setDoneOverride,
-} from './notification-source';
+import { CHANNEL_EVENT_TYPES, setDoneOverride } from './notification-source';
import { compositeEntity, type UnifiedNotification } from './types';
export const isChannelNotification = isMatching({
diff --git a/apps/web/src/features/notifications/notification-navigation.ts b/apps/web/src/features/notifications/notification-navigation.ts
index bf1c6adeac..fc65e6d647 100644
--- a/apps/web/src/features/notifications/notification-navigation.ts
+++ b/apps/web/src/features/notifications/notification-navigation.ts
@@ -4,18 +4,12 @@ import {
getChannelParams,
navigateToChannelMessage,
} from '@block-channel/utils/link';
-import { URL_PARAMS as MD_URL_PARAMS } from '@block-md/constants';
-import { URL_PARAMS as PDF_URL_PARAMS } from '@block-pdf/constants';
import type {
SplitHandle,
SplitManager,
} from '@components/app/split-layout/layoutManager';
import type { BlockAlias, BlockName } from '@core/block';
-import {
- type ItemLike,
- itemToBlockName,
- resolveBlockAlias,
-} from '@core/constant/allBlocks';
+import { resolveBlockAlias } from '@core/constant/allBlocks';
import {
enableCalendarUi,
enableReminders,
@@ -28,6 +22,10 @@ import { getNotificationById } from '@queries/notification/user-notifications';
import { getReminderById } from '@queries/reminders/reminders';
import { errAsync, ResultAsync } from 'neverthrow';
import { match, P } from 'ts-pattern';
+import {
+ getDocumentCommentLocation,
+ type NotificationEntityOverride,
+} from './document-comment-location';
import { GITHUB_EVENT_TYPES } from './github-event-types';
import { isChannelNotification } from './notification-helpers';
import { DefaultNotificationBlockNameResolver } from './notification-resolvers';
@@ -141,36 +139,6 @@ async function openChannelNotification(
});
}
-// Minimal entity shape — the live entity from the UI is authoritative when
-// available (notification metadata is a snapshot at notification time and may
-// lack `subType` for older events).
-type NotificationEntityOverride = {
- fileType?: string | null;
- subType?: { type: string } | null;
-};
-
-// Resolve the block type for a document notification, honoring `subType` so
-// that e.g. a markdown doc with `subType: { type: 'task' }` routes to the
-// 'task' block alias instead of raw 'md'. Prefers the live entity's fields
-// over the notification-metadata snapshot when provided.
-function safeDocumentContentToBlockName(
- content: NotificationEntityOverride,
- entity?: NotificationEntityOverride
-) {
- return itemToBlockName({
- type: 'document',
- fileType: entity?.fileType ?? content.fileType ?? undefined,
- subType: entity?.subType ?? content.subType ?? undefined,
- } as ItemLike);
-}
-
-function resolveBlockCommentParamName(type: BlockName | BlockAlias) {
- const resolved = resolveBlockAlias(type);
- if (resolved === 'md' || resolved === 'spreadsheet')
- return MD_URL_PARAMS.commentId;
- if (resolved === 'pdf') return PDF_URL_PARAMS.annotationId;
-}
-
type NotSupportedError = {
tag: 'NotSupportedError';
notificationType: NotificationType;
@@ -301,63 +269,24 @@ function getSupportedHandler(
openExternalUrl(url);
};
})
- .with('mentioned_in_document_comment', () => {
- const meta = notification.notification_metadata;
- if (meta.tag !== 'mentioned_in_document_comment') return null;
-
- const blockName = safeDocumentContentToBlockName(meta.content, entity);
- const commentParamName = resolveBlockCommentParamName(blockName);
- const params = commentParamName
- ? {
- [commentParamName]: meta.content.commentId.toString(),
- }
- : undefined;
-
- return async (lm: SplitManager, newSplit: boolean = false) =>
- openSplitIfNotOpen(lm, blockName, notification.entity_id, {
- newSplit,
- params,
- sourceHandle,
- });
- })
- .with('replied_to_document_comment_thread', () => {
- const meta = notification.notification_metadata;
- if (meta.tag !== 'replied_to_document_comment_thread') return null;
-
- const blockName = safeDocumentContentToBlockName(meta.content, entity);
- const commentParamName = resolveBlockCommentParamName(blockName);
- const params = commentParamName
- ? {
- [commentParamName]: meta.content.commentId.toString(),
- }
- : undefined;
-
- return async (lm: SplitManager, newSplit: boolean = false) =>
- openSplitIfNotOpen(lm, blockName, notification.entity_id, {
- newSplit,
- params,
- sourceHandle,
- });
- })
- .with('commented_on_document', () => {
- const meta = notification.notification_metadata;
- if (meta.tag !== 'commented_on_document') return null;
-
- const blockName = safeDocumentContentToBlockName(meta.content, entity);
- const commentParamName = resolveBlockCommentParamName(blockName);
- const params = commentParamName
- ? {
- [commentParamName]: meta.content.commentId.toString(),
- }
- : undefined;
+ .with(
+ P.union(
+ 'mentioned_in_document_comment',
+ 'replied_to_document_comment_thread',
+ 'commented_on_document'
+ ),
+ () => {
+ const location = getDocumentCommentLocation(notification, entity);
+ if (!location) return null;
- return async (lm: SplitManager, newSplit: boolean = false) =>
- openSplitIfNotOpen(lm, blockName, notification.entity_id, {
- newSplit,
- params,
- sourceHandle,
- });
- })
+ return async (lm: SplitManager, newSplit: boolean = false) =>
+ openSplitIfNotOpen(lm, location.blockName, notification.entity_id, {
+ newSplit,
+ params: location.params,
+ sourceHandle,
+ });
+ }
+ )
.with('reminder', () => {
// The notification points at the reminder itself, so there is nothing to
// open until the reminder is fetched and its referenced entity read. A
diff --git a/apps/web/src/features/notifications/notification-source.ts b/apps/web/src/features/notifications/notification-source.ts
index 8b598f68e5..1c7e4735bf 100644
--- a/apps/web/src/features/notifications/notification-source.ts
+++ b/apps/web/src/features/notifications/notification-source.ts
@@ -52,12 +52,6 @@ export const CHANNEL_EVENT_TYPES = [
'document_mention',
] as const;
-export const DOCUMENT_COMMENT_EVENT_TYPES = [
- 'mentioned_in_document_comment',
- 'replied_to_document_comment_thread',
- 'commented_on_document',
-] as const;
-
type NotificationsByEntity = Record<CompositeEntity, UnifiedNotification[]>;
type UnsubscribeFn = () => void;