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(notifications): mute entities from context and command menus (#6063)
teo696c47881b79
diff --git a/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx b/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsxindex 71a8b2a6fb..0fd163a105 100644--- a/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx+++ b/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx@@ -6,6 +6,7 @@ import {makeCreateReminderAction,makeFavoriteAction,makeMarkDoneAction,+ makeMuteAction,markReminderTargetDone,} from '@app/features/next-soup/actions';import { useFeatureFlag } from '@app/lib/analytics/posthog';@@ -29,6 +30,7 @@ import { buildEntityData, type EntityData } from '@entity';import DotsThree from '@icon/dots-three-large.svg';import ArrowRight from '@phosphor/arrow-right.svg';import BellSimple from '@phosphor/bell-simple.svg';+import BellSlash from '@phosphor/bell-slash.svg';import CaretDown from '@phosphor/caret-down.svg';import CaretRight from '@phosphor/caret-right.svg';import Check from '@phosphor/check.svg';@@ -38,7 +40,7 @@ import Rename from '@phosphor/pencil-line.svg';import Star from '@phosphor/star.svg';import Tag from '@phosphor/tag.svg';import Trash from '@phosphor/trash-simple.svg';-import { blockNameToItemType, type ItemType } from '@service-storage/client';+import { blockNameToItemType, type ItemType } from '@service-storage/itemType';import { cn, Dropdown, Hotkey } from '@ui';import {type Component,@@ -372,6 +374,9 @@ export function SplitFileMenu(props: {const favoriteAction = makeFavoriteAction();const userId = useUserId();const notificationSource = useGlobalNotificationSource();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const markDone = makeMarkDoneAction({userId: () => userId(),notificationSource: () => notificationSource,@@ -421,6 +426,21 @@ export function SplitFileMenu(props: {};};+ const muteOp = (): SplitFileMenuAction | undefined => {+ const entity = menuEntity();+ if (!entity || !muteAction.canExecute(entity)) return undefined;+ const muted = muteAction.isMuted(entity);+ return {+ label: muted ? 'Unmute notifications' : 'Mute notifications',+ icon: muted ? BellSimple : BellSlash,+ action: () => {+ void muteAction.execute([entity]);+ },+ hotkeyToken: blockHotkeyToken(TOKENS.entity.action.mute),+ group: 'macro' as const,+ };+ };+// Read reactively as well as through the action's imperative gate: `ops` below// is a memo, so without a reactive dependency the item would stay missing for// the life of this menu if PostHog answered after it was first computed. The@@ -622,6 +642,7 @@ export function SplitFileMenu(props: {.filter((op) => !!op);return [favoriteOp(),+ muteOp(),reminderOp(),addTagOp(),copyLinkOp(),diff --git a/apps/web/src/components/app/split-layout/context.ts b/apps/web/src/components/app/split-layout/context.tsindex 8c26e8e3a1..aac8b6a612 100644--- a/apps/web/src/components/app/split-layout/context.ts+++ b/apps/web/src/components/app/split-layout/context.ts@@ -40,7 +40,7 @@ export type SplitFileMenuActionGroups = {sender: SplitFileMenuAction[];/** Share, Copy Link, Copy ID, and friends. */sharing: SplitFileMenuAction[];- /** Macro platform features: Favorite, Remind me, Add tag. */+ /** Macro platform features: Favorite, Mute, Remind me, Add tag. */macro: SplitFileMenuAction[];/** Non-destructive operations on the file itself: Duplicate, Rename, Move, Download. */file: SplitFileMenuAction[];diff --git a/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx b/apps/web/src/features/channel/sidebar/channels-recent-widget.tsxindex 7337a2748e..ae8948be56 100644--- a/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx+++ b/apps/web/src/features/channel/sidebar/channels-recent-widget.tsx@@ -1,3 +1,4 @@+import { makeMuteAction } from '@app/features/next-soup/actions';import {compileToAst,defineQueryFilters,@@ -198,6 +199,9 @@ function ChannelRow(props: {onFloatingOpenChange?: (open: boolean) => void;}) {const notificationSource = useGlobalNotificationSource();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const openChannel = useOpenChannel();const entity = () => props.channel.entity;@@ -302,6 +306,19 @@ function ChannelRow(props: {<MenuItem text="Mark as read" onClick={markAllAsRead} /></MenuGroup></Show>+ <Show when={muteAction.canExecute(entity())}>+ <MenuSeparator />+ <MenuGroup>+ <MenuItem+ text={+ muteAction.isMuted(entity())+ ? 'Unmute notifications'+ : 'Mute notifications'+ }+ onClick={() => void muteAction.execute([entity()])}+ />+ </MenuGroup>+ </Show></ContextMenuContent></ContextMenu.Portal></ContextMenu>diff --git a/apps/web/src/features/entity/utils/notification.ts b/apps/web/src/features/entity/utils/notification.tsindex c72c1e8691..8428ab26b9 100644--- a/apps/web/src/features/entity/utils/notification.ts+++ b/apps/web/src/features/entity/utils/notification.ts@@ -2,6 +2,8 @@ import { ENABLE_DOCUMENT_MENTION_NOTIFICATIONS } from '@core/constant/featureFlaimport type { Entity, NotificationType } from '@core/types';import type { NotificationStack } from '@notifications/notification-stacking';import type { UnifiedNotification } from '@notifications/types';+import type { ItemEntity } from '@queries/preview';+import type { UserUnsubscribe } from '@service-notification/generated/schemas/userUnsubscribe';import { match, P } from 'ts-pattern';import type { EntityData } from '../types/entity';import type { Notification } from '../types/notification';@@ -57,6 +59,125 @@ export function toNotificationEntity(entity: EntityData): Entity {return entity;}+/**+ * Item types the notification service can mute. Keep aligned with+ * `MUTED_ENTITY_TYPE_LABELS` and the events that actually fan out.+ */+const MUTEABLE_ITEM_TYPES = new Set([+ 'calendar_event',+ 'call',+ 'channel',+ 'chat',+ 'document',+ 'email_thread',+ 'foreign_entity',+ 'project',+ 'reminder',+]);++/**+ * Canonical unsubscribe `item_type`. Frontend rows use `email` / `foreign`;+ * notifications and the mute API store `email_thread` / `foreign_entity`.+ */+export function normalizeMuteItemType(type: string): string {+ return match(type)+ .with('email', () => 'email_thread')+ .with('foreign', () => 'foreign_entity')+ .otherwise((value) => value);+}++/**+ * The unsubscribe row that mutes notifications for this entity.+ *+ * Uses {@link toNotificationEntity} so the stored item matches the+ * notification's primary entity — outbound delivery filters unsubscribes by+ * that entity's `item_id`. Channel threads therefore mute the parent+ * channel, which is also how their notifications are attached.+ */+export function muteItemForEntity(+ entity: EntityData+): UserUnsubscribe | undefined {+ return muteItemForRef(toNotificationEntity(entity));+}++/** Same mapping for a bare id/type (favorites, already-canonical refs). */+export function muteItemForRef(entity: {+ id: string;+ type: string;+}): UserUnsubscribe | undefined {+ const item_type = normalizeMuteItemType(entity.type);+ if (!MUTEABLE_ITEM_TYPES.has(item_type)) return undefined;+ return { item_id: entity.id, item_type };+}++/**+ * Preview fetch key for a muted item. Only types the preview pipeline+ * actually serves — reminder and GitHub have no batch preview fetcher.+ */+export function muteItemPreviewEntity(+ item: UserUnsubscribe+): ItemEntity | undefined {+ return match<string, ItemEntity | undefined>(+ normalizeMuteItemType(item.item_type)+ )+ .with('email_thread', () => ({ id: item.item_id, type: 'email' }))+ .with(+ 'channel',+ 'calendar_event',+ 'document',+ 'chat',+ 'project',+ 'call',+ (type) => ({ id: item.item_id, type })+ )+ .otherwise(() => undefined);+}++export type MuteItemFallbackIconType =+ | 'calendar'+ | 'call'+ | 'channel'+ | 'chat'+ | 'default'+ | 'email'+ | 'githubPullRequest'+ | 'md'+ | 'project'+ | 'reminder';++/** Icon used before a preview loads, or when the type has no preview. */+export function muteItemFallbackIconType(+ itemType: string+): MuteItemFallbackIconType {+ return match(normalizeMuteItemType(itemType))+ .with('channel', 'chat', 'call', 'project', 'reminder', (type) => type)+ .with('document', () => 'md' as const)+ .with('email_thread', () => 'email' as const)+ .with('calendar_event', () => 'calendar' as const)+ .with('foreign_entity', () => 'githubPullRequest' as const)+ .otherwise(() => 'default' as const);+}++export function isMutedItem(+ muted: readonly UserUnsubscribe[],+ item: UserUnsubscribe+): boolean {+ const type = normalizeMuteItemType(item.item_type);+ return muted.some(+ (entry) =>+ entry.item_id === item.item_id &&+ normalizeMuteItemType(entry.item_type) === type+ );+}++export function entityIsMuted(+ muted: readonly UserUnsubscribe[],+ entity: EntityData+): boolean {+ const item = muteItemForEntity(entity);+ return item !== undefined && isMutedItem(muted, item);+}+/*** Filters out invalid notification types that shouldn't be displayed*/diff --git a/apps/web/src/features/favorites/sidebar/favorites-section.tsx b/apps/web/src/features/favorites/sidebar/favorites-section.tsxindex 8b551d2a7a..3b9f8c2f50 100644--- a/apps/web/src/features/favorites/sidebar/favorites-section.tsx+++ b/apps/web/src/features/favorites/sidebar/favorites-section.tsx@@ -1,4 +1,5 @@import { FavoriteIcon } from '@app/features/favorites/FavoriteIcon';+import { makeMuteAction } from '@app/features/next-soup/actions';import { globalSplitManager } from '@app/signal/splitLayout';import {favoriteIconType,@@ -23,6 +24,7 @@ import {import type { EntityIconSelector } from '@core/component/EntityIcon';import { ENABLE_GRAPHQL_SOUP } from '@core/constant/featureFlags';import { isTouchDevice } from '@core/mobile/isTouchDevice';+import type { EntityData } from '@entity';import { ContextMenu } from '@kobalte/core/context-menu';import { Tooltip as KobalteTooltip } from '@kobalte/core/tooltip';import { isChannelNotification } from '@notifications/notification-helpers';@@ -337,7 +339,17 @@ const FavoriteRow = (props: {}) => {const layout = useSplitLayout();const notificationSource = useGlobalNotificationSource();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const removeMutation = useRemoveFavoriteMutation();+ // Favorites already store the canonical notification type (`email_thread`),+ // which the mute mapping accepts as-is.+ const favoriteAsEntity = () =>+ ({+ type: props.favorite.entityType,+ id: props.favorite.entityId,+ }) as EntityData;const [dndState] = useDragDropContext() ?? [];const displayName = useFavoriteDisplayName(props.favorite);@@ -507,6 +519,19 @@ const FavoriteRow = (props: {<MenuItem text="Mark all as done" onClick={markAllAsDone} /></MenuGroup></Show>+ <Show when={muteAction.canExecute(favoriteAsEntity())}>+ <MenuSeparator />+ <MenuGroup>+ <MenuItem+ text={+ muteAction.isMuted(favoriteAsEntity())+ ? 'Unmute notifications'+ : 'Mute notifications'+ }+ onClick={() => void muteAction.execute([favoriteAsEntity()])}+ />+ </MenuGroup>+ </Show><MenuSeparator /><MenuGroup><MenuItemdiff --git a/apps/web/src/features/next-soup/actions/index.ts b/apps/web/src/features/next-soup/actions/index.tsindex c4c31dc74e..0d09134b17 100644--- a/apps/web/src/features/next-soup/actions/index.ts+++ b/apps/web/src/features/next-soup/actions/index.ts@@ -31,6 +31,7 @@ export {makeMarkUnreadAction,} from './make-mark-unread-action';export { makeMoveToProjectAction } from './make-move-to-project-action';+export { makeMuteAction } from './make-mute-action';export { makeRemoveFromProjectAction } from './make-remove-from-project-action';export { makeRenameAction } from './make-rename-action';export { makeSetCompanyPropertyAction } from './make-set-company-property-action';diff --git a/apps/web/src/features/next-soup/actions/make-mute-action.ts b/apps/web/src/features/next-soup/actions/make-mute-action.tsnew file mode 100644index 0000000000..9b54079e58--- /dev/null+++ b/apps/web/src/features/next-soup/actions/make-mute-action.ts@@ -0,0 +1,90 @@+import { toast } from '@core/component/Toast/Toast';+import type { EntityData } from '@entity';+import { entityIsMuted, muteItemForEntity } from '@entity/utils/notification';+import type { NotificationSource } from '@notifications';+import {+ useMuteItemMutation,+ useUnmuteItemMutation,+} from '@queries/notification/unsubscribes';+import type { UserUnsubscribe } from '@service-notification/generated/schemas/userUnsubscribe';+import type { EntityActionListState } from './entity-action-context';++type MakeMuteActionOptions = {+ notificationSource: () => NotificationSource;+};++/**+ * Toggle notification mute for an entity.+ *+ * `execute` mutes every entity that is not yet muted; when all of them+ * already are, it unmutes them instead. Channel threads mute the parent+ * channel — that is the notification's primary entity.+ */+export const makeMuteAction = (options: MakeMuteActionOptions) => {+ const muteMutation = useMuteItemMutation();+ const unmuteMutation = useUnmuteItemMutation();++ const canExecute = (entity: EntityData): boolean =>+ muteItemForEntity(entity) !== undefined;++ const isMuted = (entity: EntityData): boolean =>+ entityIsMuted(options.notificationSource().mutedEntities(), entity);++ const execute = async (entities: EntityData[]) => {+ // Ignore re-triggers while a toggle is still settling so a rapid+ // double-press can't fire a mute and its own unmute against each other.+ if (muteMutation.isPending || unmuteMutation.isPending) return;++ const muteable = entities.filter(canExecute);+ const shouldUnmute = muteable.length > 0 && muteable.every(isMuted);+ // On mute, skip entities already muted so counts reflect real work.+ const targets = shouldUnmute+ ? muteable+ : muteable.filter((entity) => !isMuted(entity));++ // Several rows (threads in one channel) can share a mute target.+ const items = new Map<string, UserUnsubscribe>();+ for (const entity of targets) {+ const item = muteItemForEntity(entity);+ if (item) items.set(`${item.item_type}:${item.item_id}`, item);+ }+ if (items.size === 0) return;++ const mutation = shouldUnmute ? unmuteMutation : muteMutation;+ const results = await Promise.allSettled(+ [...items.values()].map((item) => mutation.mutateAsync(item))+ );++ // Each mutation rolls its own optimistic change back on failure, so report+ // what actually happened rather than an all-or-nothing result.+ const verb = shouldUnmute ? 'Unmuted' : 'Muted';+ const failed = results.filter((r) => r.status === 'rejected').length;+ const succeeded = results.length - failed;+ if (failed === 0) {+ toast.success(+ succeeded > 1+ ? `${verb} notifications for ${succeeded} items`+ : `${verb} notifications`+ );+ } else if (succeeded === 0) {+ toast.failure(+ shouldUnmute+ ? 'Failed to unmute notifications'+ : 'Failed to mute notifications'+ );+ } else {+ toast.failure(+ `${verb} ${succeeded} of ${results.length} items; ${failed} failed`+ );+ }+ };++ const executeWithSoup = async (+ entities: EntityData[],+ _soup: EntityActionListState+ ) => {+ await execute(entities);+ };++ return { canExecute, isMuted, execute, executeWithSoup };+};diff --git a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts b/apps/web/src/features/next-soup/actions/use-block-entity-commands.tsindex 9b73c06223..7b97860aa8 100644--- a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts+++ b/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts@@ -29,6 +29,7 @@ import {makeFavoriteAction,makeMarkDoneAction,makeMoveToProjectAction,+ makeMuteAction,makeRenameAction,markReminderTargetDone,} from './index';@@ -70,6 +71,9 @@ export const useBlockEntityCommands = (const copyBranchNameAction = makeCopyBranchNameAction();const copyEntityIdAction = makeCopyEntityIdAction();const favoriteAction = makeFavoriteAction();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const addTagAction = makeAddTagAction();const allProperties = useAllProperties();@@ -293,6 +297,31 @@ export const useBlockEntityCommands = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);+ // Mute notifications (command menu only, no keybinding)+ registerHotkey({+ hotkeyToken: TOKENS.entity.action.mute,+ scopeId,+ description: () => {+ const entity = getEntity();+ return entity && muteAction.isMuted(entity)+ ? 'Unmute notifications'+ : 'Mute notifications';+ },+ keyDownHandler: () => {+ const entity = getEntity();+ if (!entity) return false;+ if (!muteAction.canExecute(entity)) return false;+ void muteAction.execute([entity]);+ return true;+ },+ condition: () => {+ const entity = getEntity();+ return entity !== undefined && muteAction.canExecute(entity);+ },+ displayPriority: 10,+ tags: [HotkeyTags.SelectionModification],+ }).withGroup(group);+registerHotkey({scopeId,description: 'Duplicate item',diff --git a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.tsindex 31a213bf4d..a4df7ac08b 100644--- a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts+++ b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts@@ -31,6 +31,7 @@ import {makeMarkReadAction,makeMarkUnreadAction,makeMoveToProjectAction,+ makeMuteAction,makeRenameAction,makeSetCompanyPropertyAction,makeShareAction,@@ -101,6 +102,9 @@ export const useEntityActionHotkeys = (const shareAction = makeShareAction();const favoriteAction = makeFavoriteAction();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const setCompanyPropertyAction = makeSetCompanyPropertyAction();const addTagAction = makeAddTagAction();@@ -370,6 +374,34 @@ export const useEntityActionHotkeys = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);+ // Mute notifications (command menu only, no keybinding)+ registerHotkey({+ hotkeyToken: TOKENS.entity.action.mute,+ scopeId,+ description: () => {+ const entities = getEntitiesForAction();+ const allMuted =+ entities.length > 0 &&+ entities.every((entity) => muteAction.isMuted(entity));+ return allMuted ? 'Unmute notifications' : 'Mute notifications';+ },+ keyDownHandler: () => {+ const entities = getEntitiesForAction();+ if (entities.length === 0) return false;+ if (!entities.every(muteAction.canExecute)) return false;++ void muteAction.executeWithSoup(entities, list);+ return true;+ },+ condition: () => {+ if (condition && !condition()) return false;+ const entities = getEntitiesForAction();+ return entities.length > 0 && entities.every(muteAction.canExecute);+ },+ displayPriority: 10,+ tags: [HotkeyTags.SelectionModification],+ }).withGroup(group);+// Copy - 'cmd+d'registerHotkey({hotkey: ['cmd+d'],diff --git a/apps/web/src/features/notifications/notification-event-catalog.ts b/apps/web/src/features/notifications/notification-event-catalog.tsindex 423cbcb02c..0757221583 100644--- a/apps/web/src/features/notifications/notification-event-catalog.ts+++ b/apps/web/src/features/notifications/notification-event-catalog.ts@@ -161,6 +161,7 @@ export const BLOCKABLE_NOTIFICATION_EVENT_TYPES: readonly string[] =export const MUTED_ENTITY_TYPE_LABELS: Record<string, string> = {calendar_event: 'Calendar event',+ call: 'Call',channel: 'Channel',channel_message: 'Thread',chat: 'Chat',@@ -169,6 +170,7 @@ export const MUTED_ENTITY_TYPE_LABELS: Record<string, string> = {email_thread: 'Email',foreign: 'GitHub',foreign_entity: 'GitHub',+ project: 'Folder',reminder: 'Reminder',team: 'Team',};diff --git a/apps/web/src/features/notifications/notification-helpers.ts b/apps/web/src/features/notifications/notification-helpers.tsindex 25eb14b365..0dd5bf6355 100644--- a/apps/web/src/features/notifications/notification-helpers.ts+++ b/apps/web/src/features/notifications/notification-helpers.ts@@ -1,5 +1,6 @@import { ENABLE_GRAPHQL_SOUP } from '@core/constant/featureFlags';import type { Entity, EntityType } from '@core/types';+import { isMutedItem } from '@entity/utils/notification';import { queryClient } from '@queries/client';import {toNotificationEntityRef,@@ -222,9 +223,9 @@ export function useNotificationsMutedForEntity(entity: Entity): Accessor<boolean> {return createMemo(() =>- notificationSource.mutedEntities().includes({- item_type: entity.type,+ isMutedItem(notificationSource.mutedEntities(), {item_id: entity.id,+ item_type: entity.type,}));}diff --git a/apps/web/src/features/notifications/notification-source.ts b/apps/web/src/features/notifications/notification-source.tsindex 6933cd5b2b..e1f848b855 100644--- a/apps/web/src/features/notifications/notification-source.ts+++ b/apps/web/src/features/notifications/notification-source.ts@@ -3,6 +3,7 @@ import {ENABLE_GRAPHQL_SOUP,} from '@core/constant/featureFlags';import type { Entity } from '@core/types';+import { muteItemForRef } from '@entity/utils/notification';import { createSocketEffect } from '@macro-inc/collaboration/websocket';import {useMuteItemMutation,@@ -409,18 +410,17 @@ export function createNotificationSource(await bulkMarkAsRead([notification]);};+ // Canonicalize the type where we know how to; otherwise pass it through so+ // legacy callers keep working unchanged.+ const toMuteItem = (entity: Entity): UserUnsubscribe =>+ muteItemForRef(entity) ?? { item_id: entity.id, item_type: entity.type };+const muteEntity = async (entity: Entity) => {- await muteItem.mutateAsync({- item_id: entity.id,- item_type: entity.type,- });+ await muteItem.mutateAsync(toMuteItem(entity));};const unmuteEntity = async (entity: Entity) => {- await unmuteItem.mutateAsync({- item_id: entity.id,- item_type: entity.type,- });+ await unmuteItem.mutateAsync(toMuteItem(entity));};const subscribe = (subscribeFn: SubscribeFn) => {diff --git a/apps/web/src/features/settings/MutedItemRow.tsx b/apps/web/src/features/settings/MutedItemRow.tsxnew file mode 100644index 0000000000..2c1a1969c6--- /dev/null+++ b/apps/web/src/features/settings/MutedItemRow.tsx@@ -0,0 +1,141 @@+import {+ EntityIcon,+ type EntityIconSelector,+ getPreviewItemIconType,+} from '@core/component/EntityIcon';+import { UserIcon } from '@core/component/UserIcon';+import { useChannelsContext } from '@core/context/channels';+import { useUserId } from '@core/context/user';+import {+ muteItemFallbackIconType,+ muteItemPreviewEntity,+ normalizeMuteItemType,+} from '@entity/utils/notification';+import { mutedEntityTypeLabel } from '@notifications/notification-event-catalog';+import {+ type ItemEntity,+ isAccessiblePreviewItem,+ useItemPreview,+} from '@queries/preview';+import type { UserUnsubscribe } from '@service-notification/generated/schemas/userUnsubscribe';+import { ChannelType } from '@service-storage/generated/schemas/channelType';+import { createMemo, Show } from 'solid-js';++/**+ * One muted entity in Settings: icon + name, never the raw id.+ */+export function MutedItemRow(props: {+ item: UserUnsubscribe;+ onUnmute: () => void;+}) {+ const entity = createMemo(() => muteItemPreviewEntity(props.item));+ return (+ <Show+ when={entity()}+ fallback={+ <MutedItemLayout+ item={props.item}+ name={mutedEntityTypeLabel(props.item.item_type)}+ iconType={muteItemFallbackIconType(props.item.item_type)}+ onUnmute={props.onUnmute}+ />+ }+ >+ {(previewEntity) => (+ <MutedItemPreviewRow+ item={props.item}+ entity={previewEntity()}+ onUnmute={props.onUnmute}+ />+ )}+ </Show>+ );+}++function MutedItemPreviewRow(props: {+ item: UserUnsubscribe;+ entity: ItemEntity;+ onUnmute: () => void;+}) {+ const [preview] = useItemPreview(() => props.entity);+ const name = () => {+ const item = preview();+ if (isAccessiblePreviewItem(item) && item.name.trim()) return item.name;+ return mutedEntityTypeLabel(props.item.item_type);+ };+ const iconType = (): EntityIconSelector => {+ const item = preview();+ if (isAccessiblePreviewItem(item)) {+ const fromPreview = getPreviewItemIconType(item);+ if (fromPreview !== 'default') return fromPreview;+ }+ return muteItemFallbackIconType(props.item.item_type);+ };++ return (+ <MutedItemLayout+ item={props.item}+ name={name()}+ iconType={iconType()}+ onUnmute={props.onUnmute}+ />+ );+}++function MutedItemLayout(props: {+ item: UserUnsubscribe;+ name: string;+ iconType: EntityIconSelector;+ onUnmute: () => void;+}) {+ const dmRecipientId = useMutedChannelDmRecipientId(() => props.item);++ return (+ <div class="flex items-center gap-3 px-6 py-3.5 min-h-[60px]">+ <div class="size-5 shrink-0 flex items-center justify-center">+ <Show+ when={dmRecipientId()}+ fallback={+ <EntityIcon targetType={props.iconType} size="sm" class="size-4" />+ }+ >+ {(recipientId) => (+ <UserIcon+ id={recipientId()}+ size="sm"+ suppressClick+ showTooltip={false}+ />+ )}+ </Show>+ </div>+ <div class="min-w-0 flex-1 truncate text-sm text-ink">{props.name}</div>+ <button+ type="button"+ class="shrink-0 text-sm text-ink-muted hover:text-ink"+ onClick={props.onUnmute}+ >+ Unmute+ </button>+ </div>+ );+}++function useMutedChannelDmRecipientId(+ item: () => UserUnsubscribe+): () => string | undefined {+ const isChannel = () => normalizeMuteItemType(item().item_type) === 'channel';+ const ctx = useChannelsContext();+ const userId = useUserId();+ return createMemo(() => {+ if (!isChannel()) return undefined;+ const channel = ctx.channelsById()[item().item_id];+ if (channel?.channel_type !== ChannelType.direct_message) {+ return undefined;+ }+ const recipient =+ channel.participants.find((p) => p.user_id !== userId()) ??+ channel.participants[0];+ return recipient?.user_id;+ });+}diff --git a/apps/web/src/features/settings/Notifications.tsx b/apps/web/src/features/settings/Notifications.tsxindex 7759285206..81463d7656 100644--- a/apps/web/src/features/settings/Notifications.tsx+++ b/apps/web/src/features/settings/Notifications.tsx@@ -3,7 +3,6 @@ import { toast } from '@core/component/Toast/Toast';import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';import {EMAIL_DIGEST_NOTIFICATION_TYPE,- mutedEntityTypeLabel,NOTIFICATION_EVENT_GROUPS,} from '@notifications/notification-event-catalog';import { useNotificationSettings } from '@notifications/notification-settings';@@ -18,6 +17,7 @@ import {} from '@queries/notification/unsubscribes';import { ToggleSwitch } from '@ui';import { For, Show } from 'solid-js';+import { MutedItemRow } from './MutedItemRow';import {SettingsCard,SettingsPage,@@ -163,18 +163,10 @@ export function Notifications() {><For each={mutedEntities()}>{(item) => (- <SettingsRow- label={mutedEntityTypeLabel(item.item_type)}- description={item.item_id}- >- <button- type="button"- class="text-sm text-ink-muted hover:text-ink"- onClick={() => unmuteEntity(item)}- >- Unmute- </button>- </SettingsRow>+ <MutedItemRow+ item={item}+ onUnmute={() => void unmuteEntity(item)}+ />)}</For></Show>diff --git a/apps/web/src/features/soup/createSoupEntityActions.ts b/apps/web/src/features/soup/createSoupEntityActions.tsindex 5c22afb4c4..373ec0e7b0 100644--- a/apps/web/src/features/soup/createSoupEntityActions.ts+++ b/apps/web/src/features/soup/createSoupEntityActions.ts@@ -19,6 +19,7 @@ import {makeMarkSenderSignalAction,makeMarkUnreadAction,makeMoveToProjectAction,+ makeMuteAction,makeRemoveFromProjectAction,makeRenameAction,makeSetCompanyPropertyAction,@@ -116,6 +117,9 @@ export function createSoupEntityActions(): {const copyAction = makeCopyAction();const favoriteAction = makeFavoriteAction();+ const muteAction = makeMuteAction({+ notificationSource: () => notificationSource,+ });const moveToProjectAction = makeMoveToProjectAction();const removeFromProjectAction = makeRemoveFromProjectAction();const copyLinkAction = makeCopyLinkAction();@@ -337,6 +341,15 @@ export function createSoupEntityActions(): {});}+ if (canExecuteAll(muteAction.canExecute)) {+ const allMuted = entities.every((entity) => muteAction.isMuted(entity));+ middleItems.push({+ id: 'mute',+ label: allMuted ? 'Unmute notifications' : 'Mute notifications',+ onClick: handle(muteAction.executeWithSoup),+ });+ }+// Single-entity only: a reminder points at one thing.if (entities.length === 1 && createReminderAction.canExecute(entities[0])) {middleItems.push({diff --git a/apps/web/src/lib/core/hotkey/tokens.ts b/apps/web/src/lib/core/hotkey/tokens.tsindex fecf21ba19..c9402241e0 100644--- a/apps/web/src/lib/core/hotkey/tokens.ts+++ b/apps/web/src/lib/core/hotkey/tokens.ts@@ -60,6 +60,7 @@ export const TOKENS = {copyBranchName: 'entity.action.copyBranchName',copyEntityId: 'entity.action.copyEntityId',favorite: 'entity.action.favorite',+ mute: 'entity.action.mute',createReminder: 'entity.action.createReminder',properties: 'entity.action.properties',tags: 'entity.action.tags',diff --git a/apps/web/src/lib/queries/notification/unsubscribes.ts b/apps/web/src/lib/queries/notification/unsubscribes.tsindex 78f0450a23..bcf0cd65d2 100644--- a/apps/web/src/lib/queries/notification/unsubscribes.ts+++ b/apps/web/src/lib/queries/notification/unsubscribes.ts@@ -5,6 +5,18 @@ import { useMutation, useQuery } from '@tanstack/solid-query';import { queryClient } from '../client';import { notificationKeys } from './keys';+function sameMuteItem(left: UserUnsubscribe, right: UserUnsubscribe): boolean {+ const normalize = (type: string) => {+ if (type === 'email') return 'email_thread';+ if (type === 'foreign') return 'foreign_entity';+ return type;+ };+ return (+ left.item_id === right.item_id &&+ normalize(left.item_type) === normalize(right.item_type)+ );+}+async function fetchUnsubscribes() {const response = await notificationServiceClient.getUnsubscribes();if (response.isErr()) {@@ -35,26 +47,83 @@ function invalidateUnsubscribes() {});}+const MUTE_ITEM_MUTATION_KEY = ['notification', 'mute-item'] as const;+const UNMUTE_ITEM_MUTATION_KEY = ['notification', 'unmute-item'] as const;++/**+ * Edit the cached list in place. Per-item edits (rather than snapshot+ * restores) keep parallel bulk mutes from clobbering each other's rollbacks.+ * With no cache yet there is nothing to show optimistically; the refetch on+ * settle picks the change up.+ */+function updateUnsubscribes(+ update: (prev: UserUnsubscribe[]) => UserUnsubscribe[]+) {+ queryClient.setQueryData<UserUnsubscribe[]>(+ notificationKeys.unsubscribes.queryKey,+ (prev) => (prev === undefined ? undefined : update(prev))+ );+}++function addUnsubscribe(item: UserUnsubscribe) {+ updateUnsubscribes((prev) =>+ prev.some((entry) => sameMuteItem(entry, item)) ? prev : [...prev, item]+ );+}++function removeUnsubscribe(item: UserUnsubscribe) {+ updateUnsubscribes((prev) =>+ prev.filter((entry) => !sameMuteItem(entry, item))+ );+}++/** Refetch once the last in-flight mute/unmute settles, not after each one. */+function invalidateUnsubscribesWhenIdle() {+ const pending =+ queryClient.isMutating({ mutationKey: MUTE_ITEM_MUTATION_KEY }) ++ queryClient.isMutating({ mutationKey: UNMUTE_ITEM_MUTATION_KEY });+ if (pending > 1) return;+ return invalidateUnsubscribes();+}++function cancelUnsubscribesFetch() {+ return queryClient.cancelQueries({+ queryKey: notificationKeys.unsubscribes.queryKey,+ });+}+export function useMuteItemMutation() {return useMutation(() => ({+ mutationKey: MUTE_ITEM_MUTATION_KEY,mutationFn: async (item: UserUnsubscribe) => {await throwOnErr(() => notificationServiceClient.unsubscribeItem(item));},+ onMutate: async (item) => {+ await cancelUnsubscribesFetch();+ addUnsubscribe(item);+ },+ onError: (_error, item) => removeUnsubscribe(item),onSettled: () => {- void invalidateUnsubscribes();+ void invalidateUnsubscribesWhenIdle();},}));}export function useUnmuteItemMutation() {return useMutation(() => ({+ mutationKey: UNMUTE_ITEM_MUTATION_KEY,mutationFn: async (item: UserUnsubscribe) => {await throwOnErr(() =>notificationServiceClient.removeUnsubscribeItem(item));},+ onMutate: async (item) => {+ await cancelUnsubscribesFetch();+ removeUnsubscribe(item);+ },+ onError: (_error, item) => addUnsubscribe(item),onSettled: () => {- void invalidateUnsubscribes();+ void invalidateUnsubscribesWhenIdle();},}));}