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): mark soup channel target notifications read (#5871)

Sean Aye623f89f0a93e
diff --git a/apps/web/src/features/next-soup/soup-view/soup-view.tsx b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
index b97fa7a8d6..d78dce6e2e 100644
--- a/apps/web/src/features/next-soup/soup-view/soup-view.tsx
+++ b/apps/web/src/features/next-soup/soup-view/soup-view.tsx
@@ -49,6 +49,7 @@ import { TaskListEntity } from '@app/features/next-soup/soup-view/views/tasks/Ta
import { ResponsiveTaskListHeader } from '@app/features/next-soup/soup-view/views/tasks/TaskListHeader';
import { TaskGroupHeader } from '@app/features/next-soup/soup-view/views/tasks/task-group-header';
import {
+ markChannelTargetSeenOnOpen,
markReminderSeenOnOpen,
openEntityInNewTab,
openEntityInSplitFromUnifiedList,
@@ -964,6 +965,7 @@ const SoupViewListContent = (props: SoupViewListProps) => {
// Join button (or, in preview, the Viewer's Join prompt) is the only
// affordance.
if (!isNonMemberChannelEntity(entity)) {
+ markChannelTargetSeenOnOpen(entity, notificationSource);
openEntityInNewTab({ entity, location });
}
return;
@@ -990,6 +992,9 @@ const SoupViewListContent = (props: SoupViewListProps) => {
// Single click: focus the row AND open it in the Preview Pair's Viewer.
// The openWithSplit redirect keeps the Viewer unfocused so keyboard
// navigation stays in this list.
+ if (!isNonMemberChannelEntity(entity)) {
+ markChannelTargetSeenOnOpen(entity, notificationSource);
+ }
if (args.rowIndex !== undefined) soup.focus.setIndex(args.rowIndex);
else soup.focus.set(entity.id);
@@ -1004,6 +1009,10 @@ const SoupViewListContent = (props: SoupViewListProps) => {
const finishTouchHighlight = persistSoupNavigationTouchHighlight(event);
+ if (!isNonMemberChannelEntity(entity)) {
+ markChannelTargetSeenOnOpen(entity, notificationSource);
+ }
+
try {
await openEntityInSplitFromUnifiedList(entity, {
openInNewSplit: event.shiftKey,
diff --git a/apps/web/src/features/next-soup/utils.test.ts b/apps/web/src/features/next-soup/utils.test.ts
index 1385866129..6b28df517f 100644
--- a/apps/web/src/features/next-soup/utils.test.ts
+++ b/apps/web/src/features/next-soup/utils.test.ts
@@ -79,6 +79,7 @@ import {
executeMarkEntitiesDone,
getChannelEntityTarget,
getRowClickFallbackLocation,
+ markChannelTargetSeenOnOpen,
openEntityInSplitFromUnifiedList,
preventDuplicatePreviewEntityOpen,
resolveMarkEntitiesDoneVariables,
@@ -393,6 +394,59 @@ describe('getChannelEntityTarget', () => {
});
});
+ it('marks an attached agent notification read even when the global source does not contain it', () => {
+ const notification = sendNotification('agent-notification', 'agent-msg');
+ notification.notification_metadata = {
+ tag: 'channel_message_send',
+ content: {
+ messageId: 'agent-msg',
+ sender: null,
+ senderDisplayName: 'Macro Agent',
+ },
+ } as UnifiedNotification['notification_metadata'];
+ const bulkMarkAsRead = vi.fn(async () => {});
+ const notificationSource = {
+ notificationsByEntity: () => ({}),
+ bulkMarkAsRead,
+ } as unknown as NotificationSource;
+
+ markChannelTargetSeenOnOpen(
+ channelRow({ notifications: [notification] }),
+ notificationSource
+ );
+
+ expect(bulkMarkAsRead).toHaveBeenCalledOnce();
+ expect(bulkMarkAsRead).toHaveBeenCalledWith([notification]);
+ });
+
+ it('reports failures to mark an attached channel notification read', async () => {
+ const error = new Error('mark failed');
+ const consoleError = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => {});
+ const notification = sendNotification('notification', 'message');
+ const notificationSource = {
+ bulkMarkAsRead: vi.fn(async () => {
+ throw error;
+ }),
+ } as unknown as NotificationSource;
+
+ try {
+ markChannelTargetSeenOnOpen(
+ channelRow({ notifications: [notification] }),
+ notificationSource
+ );
+ await Promise.resolve();
+
+ expect(consoleError).toHaveBeenCalledWith(
+ 'Failed to mark message notifications as read',
+ error
+ );
+ } finally {
+ consoleError.mockRestore();
+ }
+ });
+
it('opens a channel row at latest when it has no notifications', () => {
expect(getChannelEntityTarget(channelRow())).toEqual({ kind: 'latest' });
});
diff --git a/apps/web/src/features/next-soup/utils.ts b/apps/web/src/features/next-soup/utils.ts
index 335fdeaa37..0dba05d125 100644
--- a/apps/web/src/features/next-soup/utils.ts
+++ b/apps/web/src/features/next-soup/utils.ts
@@ -732,6 +732,36 @@ export const openEntityInSplitFromUnifiedList = async (
}
};
+/**
+ * Mark the attached notification that caused a channel row to target a message.
+ *
+ * The row's Soup edge is authoritative here. The channel block's message marker
+ * discovers notifications through the separately paginated global source, so
+ * an older notification can drive navigation without being present there.
+ */
+export function markChannelTargetSeenOnOpen(
+ entity: EntityData,
+ notificationSource: NotificationSource
+) {
+ const target = getChannelEntityTarget(entity);
+ if (target?.kind !== 'message' || !isWithNotification(entity)) return;
+
+ const notifications = scopeChannelNotificationsForEntity(
+ entity,
+ entity.notifications?.() ?? []
+ ).filter((notification) => {
+ if (notificationIsRead(notification)) return false;
+ return (
+ getChannelNotificationParams(notification).messageId === target.messageId
+ );
+ });
+ if (notifications.length === 0) return;
+
+ void notificationSource.bulkMarkAsRead(notifications).catch((error) => {
+ console.error('Failed to mark message notifications as read', error);
+ });
+}
+
/**
* Mark a reminder's notification read when the user opens it.
*