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
fix(channel): notifications not being marked as read (#1101)
dev-rbcdc48bad42cd
diff --git a/js/app/packages/block-channel/component/Channel.tsx b/js/app/packages/block-channel/component/Channel.tsxindex f0a6ae4118..2dbd905c24 100644--- a/js/app/packages/block-channel/component/Channel.tsx+++ b/js/app/packages/block-channel/component/Channel.tsx@@ -33,7 +33,12 @@ import { blockHandleSignal } from '@core/signal/load';import { createTabFocusEffect } from '@core/signal/tabFocus';import type { InputAttachment } from '@core/store/cacheChannelInput';import { handleFileFolderDrop } from '@core/util/upload';-import { ChannelDebouncedNotificationReadMarker } from '@notifications';+import {+ ChannelDebouncedNotificationReadMarker,+ makeDebouncedChannelNotificationReadMarker,+ createEffectOnEntityTypeNotification,+ useEntityHasUnreadNotifications,+} from '@notifications';import { useChannelQuery } from '@queries/channel/channel';import type { Message } from '@service-comms/generated/models';import { connectionGatewayClient } from '@service-connection/client';@@ -57,6 +62,7 @@ import { type FocusableElement, tabbable } from 'tabbable';import { ChannelInput } from './ChannelInput';import { MessageList, type TargetMessageInfo } from './MessageList/MessageList';import { Top } from './Top';+import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';false && fileFolderDrop;@@ -317,6 +323,50 @@ export function Channel(props: {}));+ const debouncedMarkAsRead = makeDebouncedChannelNotificationReadMarker({+ notificationSource: notificationSource,+ channelId,+ debounceTime: 500,+ });++ // Listen for any incoming notifications and while the panel is active,+ // mark them as read+ createEffectOnEntityTypeNotification(+ notificationSource,+ 'channel',+ (notification) => {+ if (+ !splitContext.isPanelActive() ||+ notification.entity_id !== channelId+ ) {+ return;+ }++ debouncedMarkAsRead();+ }+ );++ const hasNotifications = useEntityHasUnreadNotifications(notificationSource, {+ type: 'channel',+ id: channelId,+ });++ const splitContext = useSplitPanelOrThrow();++ // Track panel active state. When the panel is focused and it was not previously+ // mark notifications as read if there are any+ createEffect(+ on(splitContext.isPanelActive, (isPanelActive, wasPanelActive) => {+ if (wasPanelActive !== false) return;++ if (!isPanelActive || !hasNotifications()) {+ return;+ }++ debouncedMarkAsRead();+ })+ );+return (<divclass={`relative flex flex-col w-full h-full bg-panel bracket-never`}diff --git a/js/app/packages/notifications/components/DebouncedNotificationReadMarker.tsx b/js/app/packages/notifications/components/DebouncedNotificationReadMarker.tsxindex 8879107918..ab53e8b0bb 100644--- a/js/app/packages/notifications/components/DebouncedNotificationReadMarker.tsx+++ b/js/app/packages/notifications/components/DebouncedNotificationReadMarker.tsx@@ -2,32 +2,36 @@ import type { Entity } from '@core/types';import { queryClient } from '@queries/client';import { emailKeys } from '@queries/email/keys';import { useMarkThreadAsSeenMutation } from '@queries/email/thread';-import { onCleanup, onMount } from 'solid-js';+import { onMount } from 'solid-js';import {markNotificationForEntityIdAsRead,markNotificationsForEntityAsRead,} from '../notification-helpers';import type { NotificationSource } from '../notification-source';+import { debounce } from '@solid-primitives/scheduled';const DEFAULT_DEBOUNCE_TIME = 2_000;-function DebouncedMarker(props: {+type DebouncedMarkerProps = {debouncedFn: () => void;debounceTime?: number;-}) {+};++export const makeDebouncedMarker = (+ props: DebouncedMarkerProps+): VoidFunction => {const debounceTime = props.debounceTime ?? DEFAULT_DEBOUNCE_TIME;- let timeout: ReturnType<typeof setTimeout> | undefined;- onMount(() => {- timeout = setTimeout(() => {- props.debouncedFn();- }, debounceTime);- });+ const trigger = debounce(props.debouncedFn, debounceTime);- onCleanup(() => {- if (timeout) {- clearTimeout(timeout);- }+ return trigger;+};++function DebouncedMarker(props: DebouncedMarkerProps) {+ const triggerDebounce = makeDebouncedMarker(props);++ onMount(() => {+ triggerDebounce();});return '';@@ -90,11 +94,29 @@ export function DocumentDebouncedNotificationReadMarker(props: {);}-export function ChannelDebouncedNotificationReadMarker(props: {+type ChannelDebouncedNotificationReadMarkerProps = {notificationSource: NotificationSource;debounceTime?: number;channelId: string;-}) {+};++export const makeDebouncedChannelNotificationReadMarker = (+ props: ChannelDebouncedNotificationReadMarkerProps+) => {+ return makeDebouncedMarker({+ debounceTime: props.debounceTime,+ debouncedFn() {+ markNotificationsForEntityAsRead(props.notificationSource, {+ type: 'channel',+ id: props.channelId,+ });+ },+ });+};++export function ChannelDebouncedNotificationReadMarker(+ props: ChannelDebouncedNotificationReadMarkerProps+) {return (<DebouncedNotificationReadMarkernotificationSource={props.notificationSource}diff --git a/js/app/packages/notifications/index.ts b/js/app/packages/notifications/index.tsindex 5e84924949..67b8a11927 100644--- a/js/app/packages/notifications/index.ts+++ b/js/app/packages/notifications/index.ts@@ -4,6 +4,7 @@ export {DebouncedNotificationReadMarker,DocumentDebouncedNotificationReadMarker,EmailDebouncedReadMarker,+ makeDebouncedChannelNotificationReadMarker,} from './components/DebouncedNotificationReadMarker';export type {CreateAppNotificationInterface,