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(new-channels): collapsing consecutive messages (#1905)
teo8e060522b433
diff --git a/js/app/packages/block-channel/component/Block.tsx b/js/app/packages/block-channel/component/Block.tsxindex b64f297da9..44f3ce286a 100644--- a/js/app/packages/block-channel/component/Block.tsx+++ b/js/app/packages/block-channel/component/Block.tsx@@ -34,7 +34,7 @@ export default function BlockChannel(props: BlockChannelProps) {return (<NewChannelchannelId={channelId}- targetMessageId="019b47e2-d61d-7cef-a7a3-b192c0df2f7f"+ // targetMessageId="019b47e2-d61d-7cef-a7a3-b192c0df2f7f"/>);}diff --git a/js/app/packages/channel/Channel/message-grouping-meta.ts b/js/app/packages/channel/Channel/message-grouping-meta.tsnew file mode 100644index 0000000000..8f5747e8e4--- /dev/null+++ b/js/app/packages/channel/Channel/message-grouping-meta.ts@@ -0,0 +1,34 @@+import type { ApiChannelMessage } from '@service-comms/client';++export type GroupableMessage = Pick<+ ApiChannelMessage,+ 'id' | 'sender_id' | 'created_at' | 'attachments' | 'deleted_at'+> & {+ thread?: Pick<ApiChannelMessage['thread'], 'reply_count'>;+};++export const MESSAGE_GROUPING_WINDOW_MS = 5 * 60 * 1000;++function isDeleted(message: Pick<GroupableMessage, 'deleted_at'>): boolean {+ return message.deleted_at != null;+}++function hasThreadReplies(message: GroupableMessage): boolean {+ return (message.thread?.reply_count ?? 0) > 0;+}++export function shouldGroupWithPreviousMessage(+ current: GroupableMessage,+ previous: GroupableMessage | undefined+): boolean {+ if (!previous) return false;+ if (current.sender_id !== previous.sender_id) return false;+ if (isDeleted(current) || isDeleted(previous)) return false;+ if (hasThreadReplies(previous)) return false;++ const currentCreatedAt = new Date(current.created_at).getTime();+ const previousCreatedAt = new Date(previous.created_at).getTime();+ const timeGap = currentCreatedAt - previousCreatedAt;++ return timeGap >= 0 && timeGap <= MESSAGE_GROUPING_WINDOW_MS;+}diff --git a/js/app/packages/channel/Channel/message-list-meta.ts b/js/app/packages/channel/Channel/message-list-meta.tsindex 5197154b0a..2383c8cc9f 100644--- a/js/app/packages/channel/Channel/message-list-meta.ts+++ b/js/app/packages/channel/Channel/message-list-meta.ts@@ -1,5 +1,6 @@import type { ApiChannelMessage } from '@service-comms/client';import type { ChannelMessageListMeta } from '../Message/list-meta';+import { shouldGroupWithPreviousMessage } from './message-grouping-meta';export function buildChannelMessageListMeta(messages: ApiChannelMessage[],@@ -7,6 +8,7 @@ export function buildChannelMessageListMeta(): Record<string, ChannelMessageListMeta> {const metaByMessageId: Record<string, ChannelMessageListMeta> = {};let previousTopLevelCreatedAt: string | undefined;+ let previousMessage: ApiChannelMessage | undefined;let foundFirstNewMessage = false;for (const [index, message] of messages.entries()) {@@ -22,9 +24,14 @@ export function buildChannelMessageListMeta(isNewMessage,isFirstNewMessage,previousTopLevelCreatedAt,+ isGroupedWithPrevious: shouldGroupWithPreviousMessage(+ message,+ previousMessage+ ),};previousTopLevelCreatedAt = message.created_at;+ previousMessage = message;}return metaByMessageId;diff --git a/js/app/packages/channel/Channel/tests/message-grouping-meta.test.ts b/js/app/packages/channel/Channel/tests/message-grouping-meta.test.tsnew file mode 100644index 0000000000..44be204bd4--- /dev/null+++ b/js/app/packages/channel/Channel/tests/message-grouping-meta.test.ts@@ -0,0 +1,70 @@+import { describe, expect, it } from 'vitest';+import {+ MESSAGE_GROUPING_WINDOW_MS,+ shouldGroupWithPreviousMessage,+} from '../message-grouping-meta';+import type { ApiChannelMessage } from '@service-comms/client';++function createMessage(+ id: string,+ createdAt: string,+ senderId = 'user-1'+): ApiChannelMessage {+ return {+ id,+ channel_id: 'channel-1',+ content: '',+ created_at: createdAt,+ updated_at: createdAt,+ sender_id: senderId,+ attachments: [],+ reactions: [],+ thread: {+ preview: [],+ reply_count: 0,+ latest_reply_at: null,+ },+ };+}++describe('message grouping meta', () => {+ it('groups same-author messages within the five-minute window', () => {+ const previous = createMessage('m1', '2026-02-20T09:00:00.000Z');+ const current = createMessage('m2', '2026-02-20T09:05:00.000Z');++ expect(shouldGroupWithPreviousMessage(current, previous)).toBe(true);+ });++ it('does not group when author changes', () => {+ const previous = createMessage('m1', '2026-02-20T09:00:00.000Z');+ const current = createMessage('m2', '2026-02-20T09:01:00.000Z', 'user-2');++ expect(shouldGroupWithPreviousMessage(current, previous)).toBe(false);+ });++ it('does not group when the time gap exceeds five minutes', () => {+ const previous = createMessage('m1', '2026-02-20T09:00:00.000Z');+ const current = createMessage(+ 'm2',+ new Date(+ new Date(previous.created_at).getTime() + MESSAGE_GROUPING_WINDOW_MS + 1+ ).toISOString()+ );++ expect(shouldGroupWithPreviousMessage(current, previous)).toBe(false);+ });++ it('does not group when the previous message has thread replies', () => {+ const previous = {+ ...createMessage('m1', '2026-02-20T09:00:00.000Z'),+ thread: {+ preview: [],+ reply_count: 1,+ latest_reply_at: '2026-02-20T09:00:30.000Z',+ },+ };+ const current = createMessage('m2', '2026-02-20T09:01:00.000Z');++ expect(shouldGroupWithPreviousMessage(current, previous)).toBe(false);+ });+});diff --git a/js/app/packages/channel/Channel/tests/message-list-meta.test.ts b/js/app/packages/channel/Channel/tests/message-list-meta.test.tsindex de23586990..e0c51b626a 100644--- a/js/app/packages/channel/Channel/tests/message-list-meta.test.ts+++ b/js/app/packages/channel/Channel/tests/message-list-meta.test.ts@@ -39,6 +39,7 @@ describe('buildChannelMessageListMeta', () => {isNewMessage: false,isFirstNewMessage: false,previousTopLevelCreatedAt: undefined,+ isGroupedWithPrevious: false,});expect(meta.m2.previousTopLevelCreatedAt).toBe('2026-02-20T09:00:00.000Z');expect(meta.m3.previousTopLevelCreatedAt).toBe('2026-02-20T10:00:00.000Z');@@ -62,4 +63,18 @@ describe('buildChannelMessageListMeta', () => {expect(meta.m3.isNewMessage).toBe(true);expect(meta.m3.isFirstNewMessage).toBe(false);});++ it('derives grouped state from the immediately previous top-level message', () => {+ const messages = [+ createMessage('m1', '2026-02-20T09:00:00.000Z'),+ createMessage('m2', '2026-02-20T09:05:00.000Z'),+ createMessage('m3', '2026-02-20T09:05:01.000Z'),+ ];++ const meta = buildChannelMessageListMeta(messages, () => false);++ expect(meta.m1.isGroupedWithPrevious).toBe(false);+ expect(meta.m2.isGroupedWithPrevious).toBe(true);+ expect(meta.m3.isGroupedWithPrevious).toBe(true);+ });});diff --git a/js/app/packages/channel/Message/ChannelMessage.tsx b/js/app/packages/channel/Message/ChannelMessage.tsxindex 73f860696f..4084537acc 100644--- a/js/app/packages/channel/Message/ChannelMessage.tsx+++ b/js/app/packages/channel/Message/ChannelMessage.tsx@@ -1,30 +1,72 @@import type { MessageActions, MessageData } from './types';import { Message } from './Message';+import type { ChannelMessageListMeta } from './list-meta';+import { Show } from 'solid-js';type ChannelMessageProps = {message: MessageData;actions?: MessageActions;+ listMeta?: ChannelMessageListMeta;};-export function ChannelMessage(props: ChannelMessageProps) {+function MessageFooter() {return (- <Message.Root message={props.message} actions={props.actions}>- <Message.Layout>- <div class="flex items-start gap-2">- <Message.SenderIcon />- <div class="flex flex-col flex-1 min-w-0">- <div class="flex items-center gap-2">- <Message.SenderName />+ <>+ <Message.Attachments />+ <Message.Reactions />+ </>+ );+}++function NormalLayout() {+ return (+ <Message.Layout>+ <div class="flex items-start gap-2">+ <Message.SenderIcon />+ <div class="flex flex-col flex-1 min-w-0">+ <div class="flex items-center gap-2">+ <Message.SenderName />+ <Message.EditedIndicator />+ <Message.Timestamp class="ml-auto" />+ </div>+ <Message.Content />+ <MessageFooter />+ </div>+ </div>+ <Message.ActionMenu />+ </Message.Layout>+ );+}++function GroupedLayout() {+ return (+ <Message.Layout class="py-1">+ <div class="flex items-start gap-2">+ <Message.SenderIcon hidden />+ <div class="flex flex-col flex-1 min-w-0">+ <div class="flex items-center gap-3 min-w-0">+ <Message.Content class="flex-1 min-w-0" />+ <div class="flex items-center gap-2 shrink-0"><Message.EditedIndicator />- <Message.Timestamp class="ml-auto" />+ <Message.Timestamp compact /></div>- <Message.Content />- <Message.Attachments />- <Message.Reactions /></div>+ <MessageFooter /></div>- <Message.ActionMenu />- </Message.Layout>+ </div>+ <Message.ActionMenu />+ </Message.Layout>+ );+}++export function ChannelMessage(props: ChannelMessageProps) {+ const isGrouped = () => props.listMeta?.isGroupedWithPrevious === true;++ return (+ <Message.Root message={props.message} actions={props.actions}>+ <Show when={isGrouped()} fallback={<NormalLayout />}>+ <GroupedLayout />+ </Show></Message.Root>);}diff --git a/js/app/packages/channel/Message/SenderIcon.tsx b/js/app/packages/channel/Message/SenderIcon.tsxindex 009070d639..971c6e5f45 100644--- a/js/app/packages/channel/Message/SenderIcon.tsx+++ b/js/app/packages/channel/Message/SenderIcon.tsx@@ -4,14 +4,20 @@ import { useMessage } from './context';type SenderIconProps = {class?: string;+ hidden?: boolean;};export function SenderIcon(props: SenderIconProps) {const message = useMessage();return (- <div class={cn('flex-shrink-0 size-[var(--user-icon-width)]', props.class)}>- <UserIcon id={message().sender_id} size="fill" />+ <div+ class={cn('flex-shrink-0 size-[var(--user-icon-width)]', props.class, {+ invisible: props.hidden,+ })}+ aria-hidden={props.hidden ? 'true' : undefined}+ >+ {!props.hidden && <UserIcon id={message().sender_id} size="fill" />}</div>);}diff --git a/js/app/packages/channel/Message/SenderName.tsx b/js/app/packages/channel/Message/SenderName.tsxindex e7db6956bf..205ce8ce85 100644--- a/js/app/packages/channel/Message/SenderName.tsx+++ b/js/app/packages/channel/Message/SenderName.tsx@@ -1,10 +1,12 @@import { cn } from '@ui/utils/classname';import { tryMacroId } from '@core/user';import { useDisplayName } from '@core/user';+import { Show } from 'solid-js';import { useMessage } from './context';type SenderNameProps = {class?: string;+ hidden?: boolean;};export function SenderName(props: SenderNameProps) {@@ -13,8 +15,10 @@ export function SenderName(props: SenderNameProps) {const [displayName] = useDisplayName(macroId());return (- <span class={cn('text-sm font-semibold truncate', props.class)}>- {displayName()}- </span>+ <Show when={!props.hidden}>+ <span class={cn('text-sm font-semibold truncate', props.class)}>+ {displayName()}+ </span>+ </Show>);}diff --git a/js/app/packages/channel/Message/Timestamp.tsx b/js/app/packages/channel/Message/Timestamp.tsxindex 6803f0760d..84f9531720 100644--- a/js/app/packages/channel/Message/Timestamp.tsx+++ b/js/app/packages/channel/Message/Timestamp.tsx@@ -4,13 +4,20 @@ import { useMessage } from './context';type TimestampProps = {class?: string;+ compact?: boolean;};export function Timestamp(props: TimestampProps) {const message = useMessage();return (- <span class={cn('text-xs text-secondary-fg', props.class)}>+ <span+ class={cn(+ 'text-xs text-secondary-fg',+ props.compact && 'leading-none',+ props.class+ )}+ >{formatDate(message().created_at)}</span>);diff --git a/js/app/packages/channel/Message/list-meta.ts b/js/app/packages/channel/Message/list-meta.tsindex 4b4a10e39b..897d8d3a87 100644--- a/js/app/packages/channel/Message/list-meta.ts+++ b/js/app/packages/channel/Message/list-meta.ts@@ -3,4 +3,5 @@ export type ChannelMessageListMeta = {isNewMessage: boolean;isFirstNewMessage: boolean;previousTopLevelCreatedAt?: string;+ isGroupedWithPrevious?: boolean;};diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsxindex 61f346c196..2e4727496b 100644--- a/js/app/packages/channel/Thread/ChannelThread.tsx+++ b/js/app/packages/channel/Thread/ChannelThread.tsx@@ -74,6 +74,7 @@ export function ChannelThread(props: ThreadProps) {<ChannelMessagemessage={props.data()}actions={props.getMessageActions?.(props.data())}+ listMeta={props.listMeta}/><Show when={hasReplies() || props.isReplying()}><div class="relative w-full">diff --git a/js/app/packages/channel/Thread/ThreadReplyList.tsx b/js/app/packages/channel/Thread/ThreadReplyList.tsxindex 97fad7a559..4f270524be 100644--- a/js/app/packages/channel/Thread/ThreadReplyList.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyList.tsx@@ -1,16 +1,21 @@-import { For } from 'solid-js';+import { For, createMemo } from 'solid-js';import {ChannelMessage,type MessageActions,type MessageData,} from '../Message';import type { ApiThreadReply } from '@service-comms/client';+import { buildThreadReplyListMeta } from './reply-list-meta';export function ThreadReplyList(props: {threadId: string;replies: Array<ApiThreadReply>;getMessageActions?: (message: MessageData) => MessageActions | undefined;}) {+ const listMetaByReplyId = createMemo(() =>+ buildThreadReplyListMeta(props.replies)+ );+return (<For each={props.replies}>{(reply) => {@@ -23,6 +28,7 @@ export function ThreadReplyList(props: {<ChannelMessagemessage={reply}actions={props.getMessageActions?.(replyMessage())}+ listMeta={listMetaByReplyId()[reply.id]}/>);}}diff --git a/js/app/packages/channel/Thread/reply-list-meta.ts b/js/app/packages/channel/Thread/reply-list-meta.tsnew file mode 100644index 0000000000..bda1f81b94--- /dev/null+++ b/js/app/packages/channel/Thread/reply-list-meta.ts@@ -0,0 +1,23 @@+import type { ApiThreadReply } from '@service-comms/client';+import type { ChannelMessageListMeta } from '../Message';+import { shouldGroupWithPreviousMessage } from '../Channel/message-grouping-meta';++export function buildThreadReplyListMeta(+ replies: ApiThreadReply[]+): Record<string, ChannelMessageListMeta> {+ return replies.reduce<Record<string, ChannelMessageListMeta>>(+ (metaById, reply, index, items) => {+ metaById[reply.id] = {+ index,+ isNewMessage: false,+ isFirstNewMessage: false,+ isGroupedWithPrevious: shouldGroupWithPreviousMessage(+ reply,+ items[index - 1]+ ),+ };+ return metaById;+ },+ {}+ );+}diff --git a/js/app/packages/channel/Thread/tests/reply-list-meta.test.ts b/js/app/packages/channel/Thread/tests/reply-list-meta.test.tsnew file mode 100644index 0000000000..2bdde42c81--- /dev/null+++ b/js/app/packages/channel/Thread/tests/reply-list-meta.test.ts@@ -0,0 +1,40 @@+import { describe, expect, it } from 'vitest';+import type { ApiThreadReply } from '@service-comms/client';+import { buildThreadReplyListMeta } from '../reply-list-meta';++function createReply(+ id: string,+ createdAt: string,+ senderId = 'user-1'+): ApiThreadReply {+ return {+ id,+ content: '',+ created_at: createdAt,+ updated_at: createdAt,+ sender_id: senderId,+ attachments: [],+ reactions: [],+ };+}++describe('buildThreadReplyListMeta', () => {+ it('builds reply list indices and grouping metadata in order', () => {+ const replies = [+ createReply('r1', '2026-02-20T09:00:00.000Z'),+ createReply('r2', '2026-02-20T09:01:00.000Z'),+ createReply('r3', '2026-02-20T09:02:00.000Z', 'user-2'),+ ];++ const meta = buildThreadReplyListMeta(replies);++ expect(meta.r1).toEqual({+ index: 0,+ isNewMessage: false,+ isFirstNewMessage: false,+ isGroupedWithPrevious: false,+ });+ expect(meta.r2.isGroupedWithPrevious).toBe(true);+ expect(meta.r3.isGroupedWithPrevious).toBe(false);+ });+});