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(soup): mark as read context menu action (#5643)

dev-rbdb6ed3f4a3a6
diff --git a/apps/web/src/features/next-soup/actions/index.ts b/apps/web/src/features/next-soup/actions/index.ts
index 262b45704d..26e1a3785e 100644
--- a/apps/web/src/features/next-soup/actions/index.ts
+++ b/apps/web/src/features/next-soup/actions/index.ts
@@ -10,6 +10,7 @@ export { makeFavoriteAction } from './make-favorite-action';
export { makeHideCompanyAction } from './make-hide-company-action';
export { makeMarkDoneAction } from './make-mark-done-action';
export { makeMarkNotDoneAction } from './make-mark-not-done-action';
+export { makeMarkNotificationsReadAction } from './make-mark-notifications-read-action';
export { makeMarkSenderSignalAction } from './make-mark-sender-important-action';
export { makeMarkSenderNoiseAction } from './make-mark-sender-noise-action';
export {
diff --git a/apps/web/src/features/next-soup/actions/make-mark-notifications-read-action.ts b/apps/web/src/features/next-soup/actions/make-mark-notifications-read-action.ts
new file mode 100644
index 0000000000..7c3b8c16a7
--- /dev/null
+++ b/apps/web/src/features/next-soup/actions/make-mark-notifications-read-action.ts
@@ -0,0 +1,88 @@
+import { toast } from '@core/component/Toast/Toast';
+import type { EntityData } from '@entity';
+import { isWithNotification } from '@entity/types/notification';
+import {
+ notificationIsRead,
+ toNotificationEntity,
+} from '@entity/utils/notification';
+import type { NotificationSource, UnifiedNotification } from '@notifications';
+import { compositeEntity } from '@notifications/types';
+import type { SoupState } from '../create-soup-state';
+
+type MakeMarkNotificationsReadOptions = {
+ notificationSource: () => NotificationSource;
+};
+
+/**
+ * Marks the unread notifications attached to Soup entities as read.
+ *
+ * GraphQL Soup rows carry their own notification edge, which can contain
+ * notifications that the global notification query has not paged in yet.
+ * Prefer that edge and use the global source only for rows without one.
+ */
+export const makeMarkNotificationsReadAction = (
+ options: MakeMarkNotificationsReadOptions
+) => {
+ const notificationsForEntity = (
+ entity: EntityData
+ ): UnifiedNotification[] => {
+ const attachedNotifications = isWithNotification(entity)
+ ? entity.notifications?.()
+ : undefined;
+
+ return (
+ attachedNotifications ??
+ options.notificationSource().notificationsByEntity()[
+ compositeEntity(toNotificationEntity(entity))
+ ] ??
+ []
+ );
+ };
+
+ const unreadNotificationsForEntity = (entity: EntityData) =>
+ notificationsForEntity(entity).filter(
+ (notification) => !notificationIsRead(notification)
+ );
+
+ const canExecute = (entity: EntityData): boolean =>
+ unreadNotificationsForEntity(entity).length > 0;
+
+ const execute = async (entities: EntityData[]) => {
+ const notificationsById = new Map<string, UnifiedNotification>();
+ let targetCount = 0;
+
+ for (const entity of entities) {
+ const notifications = unreadNotificationsForEntity(entity);
+ if (notifications.length === 0) continue;
+
+ targetCount += 1;
+ for (const notification of notifications) {
+ notificationsById.set(notification.id, notification);
+ }
+ }
+
+ const notifications = [...notificationsById.values()];
+ if (notifications.length === 0) return;
+
+ try {
+ await options.notificationSource().bulkMarkAsRead(notifications);
+ } catch {
+ toast.failure('Failed to mark as read');
+ return;
+ }
+
+ toast.success(
+ targetCount > 1
+ ? `Marked ${targetCount} items as read`
+ : 'Marked as read',
+ { duration: 3_000, stack: true, hideOnMobile: true }
+ );
+ };
+
+ /** Rows remain in place; this only updates their notification read state. */
+ const executeWithSoup = async (entities: EntityData[], _soup: SoupState) => {
+ await execute(entities);
+ };
+
+ return { canExecute, execute, executeWithSoup };
+};
diff --git a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
index 84450ed5f9..40b254a33e 100644
--- a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
+++ b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts
@@ -24,6 +24,7 @@ import {
makeHideCompanyAction,
makeMarkDoneAction,
makeMarkNotDoneAction,
+ makeMarkNotificationsReadAction,
makeMarkReadAction,
makeMarkSenderNoiseAction,
makeMarkSenderSignalAction,
@@ -110,6 +111,9 @@ export function createSoupEntityActions(): {
const markRead = makeMarkReadAction();
const markUnread = makeMarkUnreadAction();
+ const markNotificationsRead = makeMarkNotificationsReadAction({
+ notificationSource: () => notificationSource,
+ });
const deleteAction = makeDeleteAction({
userId: () => userId(),
@@ -178,9 +182,9 @@ export function createSoupEntityActions(): {
}
}
- // Read-state toggle for email selections: a fully-read selection gets
- // Mark Unread; anything with an unread thread gets Mark Read (which
- // skips the already-read ones).
+ // Email selections keep their thread read-state toggle. Other entities
+ // can mark their attached notifications read; that action skips entities
+ // and notifications that are already read.
if (canExecuteAll(markUnread.canExecute)) {
topItems.push({
id: 'mark-unread',
@@ -198,6 +202,15 @@ export function createSoupEntityActions(): {
hotkeyToken: TOKENS.entity.action.markRead,
onClick: handle(markRead.executeWithSoup),
});
+ } else if (
+ entities.every((entity) => entity.type !== 'email') &&
+ entities.some(markNotificationsRead.canExecute)
+ ) {
+ topItems.push({
+ id: 'mark-notifications-read',
+ label: 'Mark Read',
+ onClick: handle(markNotificationsRead.executeWithSoup),
+ });
}
/**