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[channels]: mark messages seen on mount (#1904)

Peter Chinman0f529a234f93
diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsx
index 2e4727496b..6875a752ce 100644
--- a/js/app/packages/channel/Thread/ChannelThread.tsx
+++ b/js/app/packages/channel/Thread/ChannelThread.tsx
@@ -1,6 +1,7 @@
import { useThreadRepliesQuery } from '@queries/channel/thread-replies';
import { Show, Suspense, type Accessor } from 'solid-js';
import { ChannelMessage } from '../Message';
+import { MarkMessaageNotifications } from '@notifications/components/MarkMessageNotifications';
import { useUserId } from '@core/context/user';
import { tryMacroId, useDisplayName } from '@core/user';
import { Thread } from './Thread';
@@ -71,11 +72,16 @@ export function ChannelThread(props: ThreadProps) {
onDismissNewMessages={props.threadActions?.onDismissNewMessages}
>
<div class="flex flex-col w-full">
- <ChannelMessage
- message={props.data()}
- actions={props.getMessageActions?.(props.data())}
- listMeta={props.listMeta}
- />
+ <MarkMessaageNotifications
+ messageId={props.data().id}
+ channelId={props.channelId()}
+ >
+ <ChannelMessage
+ message={props.data()}
+ actions={props.getMessageActions?.(props.data())}
+ listMeta={props.listMeta}
+ />
+ </MarkMessaageNotifications>
<Show when={hasReplies() || props.isReplying()}>
<div class="relative w-full">
<Thread.RailDecorations isReplying={props.isReplying} />
@@ -88,6 +94,7 @@ export function ChannelThread(props: ThreadProps) {
threadId={props.data().id}
replies={previewReplies()}
getMessageActions={props.getMessageActions}
+ channelId={props.channelId()}
/>
}
>
@@ -96,6 +103,7 @@ export function ChannelThread(props: ThreadProps) {
threadId={props.data().id}
replies={fetchedReplies()}
getMessageActions={props.getMessageActions}
+ channelId={props.channelId()}
/>
</Suspense>
</Show>
diff --git a/js/app/packages/channel/Thread/ThreadReplyList.tsx b/js/app/packages/channel/Thread/ThreadReplyList.tsx
index 4f270524be..28b14d92f4 100644
--- a/js/app/packages/channel/Thread/ThreadReplyList.tsx
+++ b/js/app/packages/channel/Thread/ThreadReplyList.tsx
@@ -5,12 +5,14 @@ import {
type MessageData,
} from '../Message';
import type { ApiThreadReply } from '@service-comms/client';
+import { MarkMessaageNotifications } from '@notifications/components/MarkMessageNotifications';
import { buildThreadReplyListMeta } from './reply-list-meta';
export function ThreadReplyList(props: {
threadId: string;
replies: Array<ApiThreadReply>;
getMessageActions?: (message: MessageData) => MessageActions | undefined;
+ channelId: string;
}) {
const listMetaByReplyId = createMemo(() =>
buildThreadReplyListMeta(props.replies)
@@ -25,11 +27,16 @@ export function ThreadReplyList(props: {
});
return (
- <ChannelMessage
- message={reply}
- actions={props.getMessageActions?.(replyMessage())}
- listMeta={listMetaByReplyId()[reply.id]}
- />
+ <MarkMessaageNotifications
+ messageId={reply.id}
+ channelId={props.channelId}
+ >
+ <ChannelMessage
+ message={reply}
+ actions={props.getMessageActions?.(replyMessage())}
+ listMeta={listMetaByReplyId()[reply.id]}
+ />
+ </MarkMessaageNotifications>
);
}}
</For>
diff --git a/js/app/packages/notifications/components/MarkMessageNotifications.tsx b/js/app/packages/notifications/components/MarkMessageNotifications.tsx
new file mode 100644
index 0000000000..5e5cd8f007
--- /dev/null
+++ b/js/app/packages/notifications/components/MarkMessageNotifications.tsx
@@ -0,0 +1,32 @@
+import { onMount } from 'solid-js';
+import type { JSXElement } from 'solid-js';
+import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
+
+export function MarkMessaageNotifications(props: {
+ messageId: string;
+ channelId: string;
+ children: JSXElement;
+}) {
+ const notificationSource = useGlobalNotificationSource();
+
+ onMount(() => {
+ const toMark = notificationSource.notifications().filter((n) => {
+ if (n.viewed_at || n.done) return false;
+ if (n.entity_id !== props.channelId) return false;
+ const meta = n.notification_metadata;
+ if (
+ meta.tag === 'channel_mention' ||
+ meta.tag === 'channel_message_send' ||
+ meta.tag === 'channel_message_reply'
+ ) {
+ return meta.content.messageId === props.messageId;
+ }
+ return false;
+ });
+ if (toMark.length > 0) {
+ notificationSource.bulkMarkAsRead(toMark);
+ }
+ });
+
+ return <>{props.children}</>;
+}