Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(web): show the task for Home activity newer than its comment notification (#7301)

gbirman24efb8cf9693
diff --git a/apps/web/src/features/entity/types/notification.ts b/apps/web/src/features/entity/types/notification.ts
index 9bc8dcc90d..15fe9f3bca 100644
--- a/apps/web/src/features/entity/types/notification.ts
+++ b/apps/web/src/features/entity/types/notification.ts
@@ -1,3 +1,4 @@
+import type { DateValue } from '@core/util/date';
import type { ApiUserNotification } from '@service-notification/generated/schemas/apiUserNotification';
import type { Accessor } from 'solid-js';
@@ -5,6 +6,9 @@ export type Notification = Omit<ApiUserNotification, 'owner_id'>;
export type WithNotification<T> = T & {
notifications?: Accessor<Notification[]>;
+ /** Earliest event this row can represent. Older notifications still count
+ * toward unread state and bulk actions, but cannot supply its label/target. */
+ notificationDisplayCutoff?: DateValue | null;
};
/**
diff --git a/apps/web/src/features/home/components/home-press.test.tsx b/apps/web/src/features/home/components/home-press.test.tsx
index 022d44ac62..14f899e2cd 100644
--- a/apps/web/src/features/home/components/home-press.test.tsx
+++ b/apps/web/src/features/home/components/home-press.test.tsx
@@ -22,7 +22,6 @@ vi.mock('@entity', () => ({
Entity: { Title: () => 'Recent chat', Timestamp: () => 'now' },
MaybeEntityRow: (props: { children: JSX.Element }) => props.children,
}));
-vi.mock('@entity/utils/filter', () => ({ unreadFilterFn: () => false }));
vi.mock('@components/app/GlobalAppState', () => ({
useGlobalNotificationSource: () => ({ mutedEntities: () => [] }),
}));
@@ -177,7 +176,10 @@ describe('Home document comment row', () => {
},
});
- const renderRow = (state: 'unseen' | 'seen' | 'done') =>
+ const renderRow = (
+ state: 'unseen' | 'seen' | 'done',
+ notificationDisplayCutoff?: string
+ ) =>
render(() => (
<HomeListEntity
entity={
@@ -187,6 +189,7 @@ describe('Home document comment row', () => {
name: 'Plan',
ownerId: 'test-user',
fileType: 'md',
+ notificationDisplayCutoff,
notifications: () => [commentNotification(state)],
} as never
}
@@ -207,6 +210,24 @@ describe('Home document comment row', () => {
expect(renderRow('done').textContent).not.toContain('mentioned you');
});
+ it.each(['unseen', 'seen'] as const)(
+ 'shows the task instead of an older %s comment after newer activity',
+ (state) => {
+ const row = renderRow(state, '2026-10-01T17:02:49Z');
+ expect(row.textContent).toContain('Recent chat');
+ expect(row.textContent).not.toContain('Peter mentioned');
+ expect(row.querySelector('[aria-label="Unread"]') !== null).toBe(
+ state === 'unseen'
+ );
+ }
+ );
+
+ it('announces a comment that supplied the row timestamp', () => {
+ expect(renderRow('seen', '2026-09-23T00:00:00Z').textContent).toContain(
+ 'Peter mentioned you on Recent chat'
+ );
+ });
+
it('names the agent that replied instead of someone', () => {
const row = render(() => (
<HomeListEntity
diff --git a/apps/web/src/features/home/queries/use-home-query.test.ts b/apps/web/src/features/home/queries/use-home-query.test.ts
index 6374f71dfe..69f133a737 100644
--- a/apps/web/src/features/home/queries/use-home-query.test.ts
+++ b/apps/web/src/features/home/queries/use-home-query.test.ts
@@ -1,4 +1,7 @@
import type { EmailEntity, EntityData } from '@entity/types/entity';
+import { unreadFilterFn } from '@entity/utils/filter';
+import { getDocumentCommentNotification } from '@notifications/document-comment-notification';
+import type { UnifiedNotification } from '@notifications/types';
import type { SoupAstItemsQuery } from '@queries/soup/items';
import { useSoupAstItemsQuery } from '@queries/soup/items';
import { soupPageTimestamp } from '@queries/soup/page-timestamp';
@@ -150,6 +153,69 @@ describe('Home data source', () => {
vi.useRealTimers();
});
+ it('keeps old notifications unread but presents newer own activity as the task', () => {
+ const comment: UnifiedNotification = {
+ id: 'comment-notification',
+ entity_id: 'task',
+ entity_type: 'document',
+ sender_id: 'peter',
+ state: 'unseen',
+ created_at: '2026-09-01T16:37:00Z',
+ updated_at: '2026-09-01T16:37:00Z',
+ viewed_at: null,
+ sent: true,
+ notification_event_type: 'replied_to_document_comment_thread',
+ notification_metadata: {
+ tag: 'replied_to_document_comment_thread',
+ content: {
+ documentName: 'emails not sending',
+ owner: 'alice',
+ fileType: 'md',
+ commentId: 'comment',
+ threadId: 'thread',
+ text: 'Making progress',
+ },
+ },
+ };
+ const task = {
+ type: 'document' as const,
+ id: 'task',
+ name: 'emails not sending',
+ ownerId: 'alice',
+ fileType: 'md',
+ updatedAt: comment.created_at,
+ notifiedAt: comment.created_at,
+ notifications: () => [comment],
+ };
+ const notifications = makeQuery([task], false);
+ const activity = makeQuery(
+ [{ ...task, touchedAt: '2026-09-10T13:02:00Z' }],
+ false
+ );
+ const { source } = mount(notifications, activity);
+ const [row] = rows(source);
+ expect(row.sortTs).toBe('2026-09-10T13:02:00Z');
+ expect(getDocumentCommentNotification(row)).toBeUndefined();
+ expect(row.notifications?.()).toEqual([comment]);
+ expect(unreadFilterFn(row)).toBe(true);
+
+ const fresh = {
+ ...comment,
+ id: 'fresh',
+ created_at: '2026-09-10T14:00:00Z',
+ };
+ notifications.setEntities([
+ {
+ ...task,
+ notifiedAt: fresh.created_at,
+ notifications: () => [fresh, comment],
+ },
+ ]);
+ const [refreshed] = rows(source);
+ expect(refreshed.sortTs).toBe(fresh.created_at);
+ expect(getDocumentCommentNotification(refreshed)).toEqual(fresh);
+ });
+
it('excludes Noise and unclassified emails from recent activity, even when important or drafted', () => {
const activity = makeQuery(
[
diff --git a/apps/web/src/features/home/queries/use-home-query.ts b/apps/web/src/features/home/queries/use-home-query.ts
index 4d0d1f31ba..195207ebb0 100644
--- a/apps/web/src/features/home/queries/use-home-query.ts
+++ b/apps/web/src/features/home/queries/use-home-query.ts
@@ -255,7 +255,10 @@ export function useHomeDataSource(state: HomeDataSourceInput): HomeDataSource {
matchesCapabilities(entity, viewContext().capabilities)
),
viewContext()
- ).map(attachNotifications)
+ ).map((entity) => ({
+ ...attachNotifications(entity),
+ notificationDisplayCutoff: entity.sortTs,
+ }))
: transformEntities(entities);
const { entityPool } = useSearchContext();
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index 2326fd2de1..2915d0ed0e 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -1705,6 +1705,63 @@ const documentRow = (notifications: UnifiedNotification[]) =>
}) as unknown as EntityData;
describe('getDocumentCommentTarget', () => {
+ it('opens the entity without replaying an older comment after own activity', async () => {
+ const notification = commentNotification('old', 'comment-old', {
+ created_at: '2026-09-24T20:39:45Z',
+ });
+ const entity = {
+ ...documentRow([notification]),
+ notificationDisplayCutoff: '2026-10-01T17:02:49Z',
+ };
+ expect(getDocumentCommentTarget(entity)).toBeUndefined();
+ expect(previewBlockTarget(entity as never).params).toBeUndefined();
+ expect(homePreviewNavigation(entity as never).search.drive).toBeUndefined();
+
+ const openWithSplit = vi.fn(() => ({ status: 'unavailable' }));
+ setGlobalSplitManager({
+ activeSplit: vi.fn(),
+ getOrchestrator: vi.fn(() => ({})),
+ getSplitByContent: vi.fn(),
+ openWithSplit,
+ } as unknown as SplitManager);
+ await openEntityInSplitFromUnifiedList(entity, {});
+ expect(openWithSplit).toHaveBeenCalledWith(
+ {
+ type: 'component',
+ id: 'documents',
+ entryMetadata: {
+ route: {
+ matches: [
+ { id: 'drive', params: {} },
+ {
+ id: 'drive-document',
+ params: { documentId: 'doc-1', documentType: 'md' },
+ },
+ ],
+ },
+ },
+ },
+ expect.objectContaining({ activate: true, search: undefined })
+ );
+ expect(notification.state).toBe('unseen');
+ });
+
+ it('does not borrow an older comment target for a newer unsupported event', () => {
+ const entity = documentRow([
+ commentNotification('old', 'comment-old', {
+ created_at: '2026-09-24T20:39:45Z',
+ }),
+ commentNotification('assigned', '', {
+ created_at: '2026-10-01T17:02:49Z',
+ notification_metadata: {
+ tag: 'task_assigned',
+ content: { taskId: 'doc-1', assignedBy: 'alice', taskName: 'Plan' },
+ },
+ }),
+ ]);
+ expect(getDocumentCommentTarget(entity)).toBeUndefined();
+ });
+
it('targets the newest comment notification that is not done, read or not', () => {
expect(
getDocumentCommentTarget(
diff --git a/apps/web/src/features/notifications/document-comment-notification.ts b/apps/web/src/features/notifications/document-comment-notification.ts
index d0e3b10b6c..b5f50c5a78 100644
--- a/apps/web/src/features/notifications/document-comment-notification.ts
+++ b/apps/web/src/features/notifications/document-comment-notification.ts
@@ -1,4 +1,5 @@
import { compareDateDesc } from '@core/util/date';
+import type { WithNotification } from '@entity/types/notification';
import type { UnifiedNotification } from './types';
export const DOCUMENT_COMMENT_EVENT_TYPES = [
@@ -11,19 +12,31 @@ const isDocumentCommentTag = (tag: string) =>
(DOCUMENT_COMMENT_EVENT_TYPES as readonly string[]).includes(tag);
/**
- * The comment notification a document row stands for: its newest one that is
- * not done. Like a channel thread row, the row keeps pointing at that comment
- * after it is read; marking it done is what returns the row to the document.
+ * A document row can announce its newest outstanding event when it is a
+ * comment. Home supplies a cutoff so newer own activity cannot borrow an old
+ * comment's label or click target. Reading a comment does not dismiss it.
*/
-export function getDocumentCommentNotification(entity: {
- type: string;
- notifications?: () => UnifiedNotification[];
-}): UnifiedNotification | undefined {
+export function getDocumentCommentNotification(
+ entity: WithNotification<{
+ type: string;
+ }>
+): UnifiedNotification | undefined {
if (entity.type !== 'document') return undefined;
- return (entity.notifications?.() ?? [])
- .filter(
- (n) =>
- n.state !== 'done' && isDocumentCommentTag(n.notification_metadata.tag)
- )
+ const notification = (entity.notifications?.() ?? [])
+ .filter((n) => n.state !== 'done')
.sort((a, b) => compareDateDesc(a.created_at, b.created_at))[0];
+ if (
+ !notification ||
+ !isDocumentCommentTag(notification.notification_metadata.tag)
+ ) {
+ return undefined;
+ }
+ if (
+ entity.notificationDisplayCutoff != null &&
+ compareDateDesc(notification.created_at, entity.notificationDisplayCutoff) >
+ 0
+ ) {
+ return undefined;
+ }
+ return notification;
}
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 6b189b0b1b..9d4399ea58 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -127,6 +127,13 @@ targets, spreadsheets, unknown items, and other unsupported block types retain
the legacy inline preview so their navigation still works. The URL shape stays
`/app/home/<block-type>/<uuid>` in either rendering mode.
+Desktop Home names a document comment event only when it is the latest
+outstanding notification and is at least as recent as the activity that placed
+the row there. Newer own activity, or an event without a supported comment
+description, shows the document/task title and opens the entity without a
+comment target. Older notifications retain their unread state and remain
+available to notification actions.
+
On touch devices, documents (including tasks) open in legacy blocks rather than
inline Drive details. Canonical `/app/drive/.../<document-type>/<uuid>` links also
fall back to legacy document routes. This uses touch detection, not the native-app