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(channels): quote reply to thread message (#3589)
Seamus5940c988da01
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 06ebe6230d..f94fe003ed 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -64,6 +64,7 @@ import {import { ChannelInputContainer } from '../Input/ChannelInputContainer';import { hasSendableInputContent } from '../Input/utils/sendable-content';import { ChannelThread } from '../Thread';+import { buildQuoteReplyValue } from '../Thread/utils/message-actions';import { ChannelDropZone } from './ChannelDropZone';import { createChannelDragState } from './create-channel-drag-state';import { createChannelFindBar } from './create-channel-find-bar';@@ -255,6 +256,40 @@ export function Channel(props: ChannelProps) {},});+ const openReplyInput = (message: {+ id: string;+ thread_id?: string | null;+ }) => {+ const threadId = message.thread_id ?? message.id;+ const state = threadManager.getOrCreateThreadState(threadId);+ state.setIsReplying(true);+ return state;+ };++ const openQuoteReplyInput = (message: {+ id: string;+ content: string;+ thread_id?: string | null;+ }) => {+ const threadId = message.thread_id ?? message.id;+ const state = threadManager.getOrCreateThreadState(threadId);+ const beforeSnapshot = state.replyInputState();+ const nextSnapshot: InputSnapshot = {+ value: buildQuoteReplyValue({+ quotedContent: message.content,+ existingValue: beforeSnapshot?.value,+ }),+ mentions: beforeSnapshot?.mentions ?? [],+ attachments: beforeSnapshot?.attachments ?? [],+ };++ state.setReplyInputState(nextSnapshot);+ state.setIsReplying(true);+ requestAnimationFrame(() => {+ state.replyInputHandle?.()?.restoreSnapshot(nextSnapshot);+ });+ };+const getMessageActions = createChannelMessageActions({channelId: () => props.channelId,userId,@@ -262,8 +297,11 @@ export function Channel(props: ChannelProps) {addReaction: addReactionMutation.mutate,removeReaction: removeReactionMutation.mutate,onReply: (ctx) => {- const state = threadManager.getOrCreateThreadState(ctx.message.id);- state.setIsReplying(true);+ if (ctx.message.thread_id) {+ openQuoteReplyInput(ctx.message);+ return;+ }+ openReplyInput(ctx.message);},onEdit: ({ message }) => {messageEditor.start(message);@@ -468,6 +506,7 @@ export function Channel(props: ChannelProps) {replyInputState={state.replyInputState}setReplyInputState={state.setReplyInputState}setReplyInputEl={state.setReplyInputEl}+ setReplyInputHandle={state.setReplyInputHandle}listMeta={listMetaByMessageId()[item.id]}messageEditor={messageEditor}threadActions={{diff --git a/js/app/packages/channel/Channel/tests/create-channel-message-actions.test.ts b/js/app/packages/channel/Channel/tests/create-channel-message-actions.test.tsindex ddd967cf63..2245764c6d 100644--- a/js/app/packages/channel/Channel/tests/create-channel-message-actions.test.ts+++ b/js/app/packages/channel/Channel/tests/create-channel-message-actions.test.ts@@ -98,4 +98,18 @@ describe('createChannelMessageActions', () => {currentReactions: [],});});++ it('exposes reply action for thread replies', () => {+ const onReply = vi.fn();+ const harness = buildHarness({ userId: 'user-1', onReply });+ const reply = buildMessage({+ id: 'reply-1',+ thread_id: 'parent-1',+ });+ const actions = harness.getMessageActions(reply);++ actions.onReply?.({ message: reply });++ expect(onReply).toHaveBeenCalledWith({ message: reply });+ });});diff --git a/js/app/packages/channel/Channel/thread-manager.ts b/js/app/packages/channel/Channel/thread-manager.tsindex 726906325e..9462a020d9 100644--- a/js/app/packages/channel/Channel/thread-manager.ts+++ b/js/app/packages/channel/Channel/thread-manager.ts@@ -1,4 +1,4 @@-import type { InputSnapshot } from '@channel/Input';+import type { InputHandle, InputSnapshot } from '@channel/Input';import { batch, createSignal, type Setter } from 'solid-js';import { createStore } from 'solid-js/store';import type { ThreadState } from '../Thread';@@ -16,6 +16,9 @@ export function createThreadManager() {const [replyInputEl, setReplyInputEl] = createSignal<HTMLElement | undefined>();+ const [replyInputHandle, setReplyInputHandle] = createSignal<+ InputHandle | undefined+ >();/** If you set replying from false -> true this means it must be expanded **/const setIsReplying: Setter<boolean> = (val) => {@@ -41,6 +44,8 @@ export function createThreadManager() {setReplyInputState,replyInputEl,setReplyInputEl,+ replyInputHandle,+ setReplyInputHandle,};setThreadStore(threadId, state);diff --git a/js/app/packages/channel/Input/ChannelInput.tsx b/js/app/packages/channel/Input/ChannelInput.tsxindex ef371f39a5..1796f1df76 100644--- a/js/app/packages/channel/Input/ChannelInput.tsx+++ b/js/app/packages/channel/Input/ChannelInput.tsx@@ -141,6 +141,27 @@ export function ChannelInput(props: ChannelInputProps) {persistenceKey: props.persistenceKey,});+ let isEditorConnected = false;+ let pendingRestoreSnapshot:+ | Parameters<InputHandle['restoreSnapshot']>[0]+ | undefined;++ const applySnapshot = (+ snapshot: Parameters<InputHandle['restoreSnapshot']>[0]+ ) => {+ markdownEditor.controls.setMarkdown(snapshot.value);+ attachmentTracker.setAttachments(snapshot.attachments);+ mentionsTracker.setMentions(snapshot.mentions);+ markdownEditor.controls.focus();+ };++ const flushPendingRestore = () => {+ const snapshot = pendingRestoreSnapshot;+ pendingRestoreSnapshot = undefined;+ if (!snapshot) return;+ queueMicrotask(() => applySnapshot(snapshot));+ };+const markdownEditor = createConfiguredChannelMarkdownEditor({namespace: props.markdownNamespace ?? 'channel-input-markdown',enableMentions: true,@@ -188,10 +209,11 @@ export function ChannelInput(props: ChannelInputProps) {focus: () => markdownEditor.controls.focus(),attachFiles: (files) => inputState.commands.attachFiles(files),restoreSnapshot: (snapshot) => {- markdownEditor.controls.setMarkdown(snapshot.value);- attachmentTracker.setAttachments(snapshot.attachments);- mentionsTracker.setMentions(snapshot.mentions);- markdownEditor.controls.focus();+ if (!isEditorConnected) {+ pendingRestoreSnapshot = snapshot;+ return;+ }+ applySnapshot(snapshot);},});@@ -258,6 +280,10 @@ export function ChannelInput(props: ChannelInputProps) {autofocus={!isMobile() && (props.autofocus ?? true)}class="text-sm"refFn={attach}+ onConnect={() => {+ isEditorConnected = true;+ flushPendingRestore();+ }}/></Input.Editor></Input.EditorShell>diff --git a/js/app/packages/channel/StandaloneThread/EditableThread.tsx b/js/app/packages/channel/StandaloneThread/EditableThread.tsxindex 1c33668ad0..d912ea9862 100644--- a/js/app/packages/channel/StandaloneThread/EditableThread.tsx+++ b/js/app/packages/channel/StandaloneThread/EditableThread.tsx@@ -7,8 +7,9 @@ import {import type { ApiChannelMessage } from '@service-comms/client';import { createSignal, Show } from 'solid-js';import { createChannelMessageActions } from '../Channel/create-channel-message-actions';-import type { InputSnapshot } from '../Input';+import type { InputHandle, InputSnapshot } from '../Input';import { Thread } from '../Thread';+import { buildQuoteReplyValue } from '../Thread/utils/message-actions';import { useStandaloneThread } from './context';import { StandaloneThread } from './StandaloneThread';@@ -24,6 +25,9 @@ function EditableThreadInner() {const [replyInputState, setReplyInputState] = createSignal<InputSnapshot | undefined>();+ const [replyInputHandle, setReplyInputHandle] = createSignal<+ InputHandle | undefined+ >();const deleteMessageMutation = useDeleteMessageMutation();const addReactionMutation = useAddReactionMutation();const removeReactionMutation = useRemoveReactionMutation();@@ -34,7 +38,23 @@ function EditableThreadInner() {deleteMessage: deleteMessageMutation.mutate,addReaction: addReactionMutation.mutate,removeReaction: removeReactionMutation.mutate,- onReply: () => void ctx.setIsReplying(true),+ onReply: ({ message }) => {+ if (message.thread_id) {+ const current = replyInputState();+ const nextSnapshot: InputSnapshot = {+ value: buildQuoteReplyValue({+ quotedContent: message.content,+ existingValue: current?.value,+ }),+ mentions: current?.mentions ?? [],+ attachments: current?.attachments ?? [],+ };+ setReplyInputState(nextSnapshot);+ replyInputHandle()?.restoreSnapshot(nextSnapshot);+ }++ ctx.setIsReplying(true);+ },});const parentActions = () => {@@ -56,6 +76,7 @@ function EditableThreadInner() {replyInputState={replyInputState}setReplyInputState={setReplyInputState}setIsReplying={ctx.setIsReplying}+ setReplyInputHandle={setReplyInputHandle}/></Show></>diff --git a/js/app/packages/channel/StandaloneThread/Replies.tsx b/js/app/packages/channel/StandaloneThread/Replies.tsxindex 9147894d4b..bdd98eceea 100644--- a/js/app/packages/channel/StandaloneThread/Replies.tsx+++ b/js/app/packages/channel/StandaloneThread/Replies.tsx@@ -56,13 +56,16 @@ export function Replies(props: RepliesProps) {<Thread.RepliesContainer><For each={ctx.displayReplies()}>{(reply) => {+ const replyMessage = () =>+ ({ ...reply, thread_id: ctx.messageId() }) as MessageData;const meta = () => listMetaByReplyId()[reply.id];- const replyActions = () => props.getMessageActions?.(reply);+ const replyActions = () =>+ props.getMessageActions?.(replyMessage());return (<div class="relative"><ThreadRail /><Message.Root- message={reply}+ message={replyMessage()}actions={replyActions()}onClick={props.onClickMessagediff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsxindex 7a69958d3b..9945ca8452 100644--- a/js/app/packages/channel/Thread/ChannelThread.tsx+++ b/js/app/packages/channel/Thread/ChannelThread.tsx@@ -289,6 +289,7 @@ export function ChannelThread(props: ThreadProps) {setReplyInputState={props.setReplyInputState}setIsReplying={props.setIsReplying}setReplyInputEl={props.setReplyInputEl}+ setReplyInputHandle={props.setReplyInputHandle}/></div></Show>diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsxindex d63ed4807b..7e60eaa81e 100644--- a/js/app/packages/channel/Thread/ThreadReplyInput.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx@@ -22,10 +22,14 @@ type ThreadReplyInputProps = {setReplyInputState: Setter<InputSnapshot | undefined>;setIsReplying: Setter<boolean>;setReplyInputEl?: Setter<HTMLElement | undefined>;+ setReplyInputHandle?: Setter<InputHandle | undefined>;};export function ThreadReplyInput(props: ThreadReplyInputProps) {- onCleanup(() => props.setReplyInputEl?.(undefined));+ onCleanup(() => {+ props.setReplyInputEl?.(undefined);+ props.setReplyInputHandle?.(undefined);+ });const userId = useUserId();const sendMessageMutation = useSendMessageMutation();@@ -46,7 +50,16 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {tracker,});- const [replyInputHandle, setReplyInputHandle] = createSignal<InputHandle>();+ const [replyInputHandle, setLocalReplyInputHandle] =+ createSignal<InputHandle>();+ const setReplyInputHandle = (handle: InputHandle) => {+ setLocalReplyInputHandle(handle);+ props.setReplyInputHandle?.(handle);++ const snapshot = props.replyInputState();+ if (!snapshot) return;+ requestAnimationFrame(() => handle.restoreSnapshot(snapshot));+ };return (<divdiff --git a/js/app/packages/channel/Thread/tests/message-actions.test.ts b/js/app/packages/channel/Thread/tests/message-actions.test.tsindex 31545faa7e..fa37d727f2 100644--- a/js/app/packages/channel/Thread/tests/message-actions.test.ts+++ b/js/app/packages/channel/Thread/tests/message-actions.test.ts@@ -2,6 +2,7 @@ import { URL_PARAMS } from '@channel/Channel/link';import { describe, expect, it } from 'vitest';import {buildMessageLink,+ buildQuoteReplyValue,canEditOrDeleteMessage,canReplyToMessage,DEFAULT_REACTION_EMOJI,@@ -30,11 +31,11 @@ describe('message-actions helpers', () => {).toBe(false);});- it('allows reply only for non-thread non-deleted messages', () => {+ it('allows reply for non-deleted top-level messages and thread replies', () => {expect(canReplyToMessage({ thread_id: null, deleted_at: null })).toBe(true);expect(canReplyToMessage({ thread_id: 'parent-id', deleted_at: null })- ).toBe(false);+ ).toBe(true);expect(canReplyToMessage({thread_id: null,@@ -43,6 +44,32 @@ describe('message-actions helpers', () => {).toBe(false);});+ it('builds quote reply markdown before existing draft text', () => {+ expect(+ buildQuoteReplyValue({+ quotedContent: 'first line\nsecond line',+ existingValue: 'draft',+ })+ ).toBe('> first line\n> second line\n\ndraft');+ });++ it('does not insert a quote for empty quoted content', () => {+ expect(+ buildQuoteReplyValue({+ quotedContent: ' \n ',+ existingValue: 'draft',+ })+ ).toBe('draft');+ });++ it('flattens existing quote markers instead of nesting blockquotes', () => {+ expect(+ buildQuoteReplyValue({+ quotedContent: '> first line\n>> second line',+ })+ ).toBe('> first line\n> second line\n\n ');+ });+it('detects if user already reacted with the default emoji', () => {const message = {reactions: [diff --git a/js/app/packages/channel/Thread/types.ts b/js/app/packages/channel/Thread/types.tsindex 07f5d202ff..60469d7db2 100644--- a/js/app/packages/channel/Thread/types.ts+++ b/js/app/packages/channel/Thread/types.ts@@ -1,6 +1,6 @@import type { MessageEditor } from '@channel/Channel/create-message-editor';import type { NewMessageCheckable } from '@channel/Channel/util';-import type { InputSnapshot } from '@channel/Input';+import type { InputHandle, InputSnapshot } from '@channel/Input';import type { ApiChannelMessage } from '@service-comms/client';import type { Accessor, Setter } from 'solid-js';import type {@@ -22,6 +22,8 @@ export type ThreadState = {setReplyInputState: Setter<InputSnapshot | undefined>;replyInputEl?: Accessor<HTMLElement | undefined>;setReplyInputEl?: Setter<HTMLElement | undefined>;+ replyInputHandle?: Accessor<InputHandle | undefined>;+ setReplyInputHandle?: Setter<InputHandle | undefined>;};export type MessageEditState = {diff --git a/js/app/packages/channel/Thread/utils/message-actions.ts b/js/app/packages/channel/Thread/utils/message-actions.tsindex a189ecd33a..8731c8419c 100644--- a/js/app/packages/channel/Thread/utils/message-actions.ts+++ b/js/app/packages/channel/Thread/utils/message-actions.ts@@ -3,6 +3,7 @@ import { buildSimpleEntityUrl } from '@core/util/url';import type { MessageData } from '../../Message';export const DEFAULT_REACTION_EMOJI = '👍';+const EMPTY_REPLY_PARAGRAPH = ' ';export type ActionableMessage = Pick<MessageData,@@ -29,7 +30,31 @@ export function canEditOrDeleteMessage(export function canReplyToMessage(message: Pick<ActionableMessage, 'thread_id' | 'deleted_at'>): boolean {- return !message.thread_id && !message.deleted_at;+ return !message.deleted_at;+}++export function buildQuoteReplyValue(input: {+ quotedContent: string;+ existingValue?: string;+}): string {+ const normalizedQuotedContent = input.quotedContent+ .trim()+ .split('\n')+ .map((line) => line.replace(/^\s*>+\s?/, ''))+ .join('\n')+ .trim();+ const existingValue = input.existingValue?.trimStart() ?? '';++ if (!normalizedQuotedContent) return existingValue;++ const quote = normalizedQuotedContent+ .split('\n')+ .map((line) => `> ${line}`)+ .join('\n');++ return existingValue+ ? `${quote}\n\n${existingValue}`+ : `${quote}\n\n${EMPTY_REPLY_PARAGRAPH}`;}export function hasReactionFromUser(diff --git a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsxindex 2fa370ae2b..0fb47e11ce 100644--- a/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/builder/MarkdownShell.tsx@@ -84,6 +84,8 @@ export const MarkdownShell: Component<if (hasInitialContent) {builderConfig.handlers.onChange?.(markdownState());}++ props.onConnect?.();};// Track editable statediff --git a/js/app/packages/core/component/LexicalMarkdown/builder/types.ts b/js/app/packages/core/component/LexicalMarkdown/builder/types.tsindex 0d0a0a1ee1..e775ff6cf0 100644--- a/js/app/packages/core/component/LexicalMarkdown/builder/types.ts+++ b/js/app/packages/core/component/LexicalMarkdown/builder/types.ts@@ -112,6 +112,7 @@ export interface EditorComponentProps {class?: string;portalScope?: PortalScope;refFn?: (ref: HTMLDivElement) => void;+ onConnect?: () => void;}export interface EditorConfig {