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): add failed to send message failover (#2693)
teo3360a5ac1b39
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 3d6d7e428a..45afbea109 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -37,8 +37,10 @@ import { ChannelThread } from '../Thread';import {ChannelInput,createInputAttachmentTracker,+ type InputHandle,type InputSnapshot,} from '../Input';+import { hasSendableInputContent } from '../Input/utils/sendable-content';import { ChannelInputContainer } from '../Input/ChannelInputContainer';import { createChannelMessageActions } from './create-channel-message-actions';import { useSplitLayout } from '@app/component/split-layout/layout';@@ -126,6 +128,8 @@ export function Channel(props: ChannelProps) {const [channelInputSnapshot, setChannelInputSnapshot] =createSignal<InputSnapshot>();+ const [channelInputHandle, setChannelInputHandle] =+ createSignal<InputHandle>();const messagesQuery = useChannelMessagesQuery(() => props.channelId,@@ -291,15 +295,26 @@ export function Channel(props: ChannelProps) {const senderId = userId();if (!senderId) return;- sendMessageMutation.mutate({- channelID: props.channelId,- senderId,- optimisticId: crypto.randomUUID(),- message: buildPostMessageRequest({- snapshot,- participantIds: participants.ids(),- }),- });+ sendMessageMutation.mutate(+ {+ channelID: props.channelId,+ senderId,+ optimisticId: crypto.randomUUID(),+ message: buildPostMessageRequest({+ snapshot,+ participantIds: participants.ids(),+ }),+ },+ {+ onError: () => {+ const handle = channelInputHandle();+ if (!handle) return;+ const current = channelInputSnapshot();+ if (current && hasSendableInputContent(current)) return;+ handle.restoreSnapshot(snapshot);+ },+ }+ );};const isChannelReady = () => {@@ -424,6 +439,7 @@ export function Channel(props: ChannelProps) {})}onReady={(handle) => {dragState.setAttachFilesToChannel(handle.attachFiles);+ setChannelInputHandle(handle);}}onChange={(snapshot) =>void setChannelInputSnapshot(snapshot)diff --git a/js/app/packages/channel/Input/ChannelInput.tsx b/js/app/packages/channel/Input/ChannelInput.tsxindex 282912f054..6ef835fdce 100644--- a/js/app/packages/channel/Input/ChannelInput.tsx+++ b/js/app/packages/channel/Input/ChannelInput.tsx@@ -155,6 +155,12 @@ export function ChannelInput(props: ChannelInputProps) {clear: () => markdownEditor.controls.clear(),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();+ },});return (diff --git a/js/app/packages/channel/Input/mentions-tracker.ts b/js/app/packages/channel/Input/mentions-tracker.tsindex 0a17cffd54..b145ceffcb 100644--- a/js/app/packages/channel/Input/mentions-tracker.ts+++ b/js/app/packages/channel/Input/mentions-tracker.ts@@ -6,6 +6,7 @@ export type MentionsTracker = {onMentionCreate: MentionFn;onMentionRemove: MentionFn;mentions: Accessor<ItemMention[]>;+ setMentions: (mentions: ItemMention[]) => void;};export function createMentionsTracker(): MentionsTracker {@@ -29,5 +30,6 @@ export function createMentionsTracker(): MentionsTracker {onMentionCreate,onMentionRemove,mentions,+ setMentions: (next) => setMentions(next),};}diff --git a/js/app/packages/channel/Input/types.ts b/js/app/packages/channel/Input/types.tsindex 3643507d7d..cc695f90a8 100644--- a/js/app/packages/channel/Input/types.ts+++ b/js/app/packages/channel/Input/types.ts@@ -71,6 +71,7 @@ export type InputHandle = {clear: () => void;focus: () => void;attachFiles: (files: File[]) => Promise<void>;+ restoreSnapshot: (snapshot: InputSnapshot) => void;};export type InputAttachmentTracker = Tracker;diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsxindex 8017b21d69..8a8fc8c7f0 100644--- a/js/app/packages/channel/Thread/ThreadReplyInput.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx@@ -1,9 +1,10 @@import { useUserId } from '@core/context/user';import { useSendMessageMutation } from '@queries/channel/message';import { usePostTypingUpdateMutation } from '@queries/channel/typing';-import { onCleanup, type Accessor, type Setter } from 'solid-js';+import { createSignal, onCleanup, type Accessor, type Setter } from 'solid-js';import { ChannelInput, createInputAttachmentTracker } from '../Input';-import type { InputSnapshot } from '../Input';+import type { InputHandle, InputSnapshot } from '../Input';+import { hasSendableInputContent } from '../Input/utils/sendable-content';import { buildPostMessageRequest } from '../Input/message-payload';import { createEntityDropZone } from '../Channel/create-entity-drop-zone';import { replyInputOffsetX } from './utils/thread-rail-geometry';@@ -45,6 +46,8 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {tracker,});+ const [replyInputHandle, setReplyInputHandle] = createSignal<InputHandle>();+return (<divclass="relative pt-2"@@ -75,6 +78,7 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {threadId: props.messageId,})}markdownNamespace={`thread-reply-input-${props.messageId}-markdown`}+ onReady={setReplyInputHandle}onChange={(snapshot) => void props.setReplyInputState(snapshot)}onStartTyping={() =>typingMutation.mutate({@@ -98,19 +102,31 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {const senderId = userId();if (!senderId) return;- sendMessageMutation.mutate({- channelID: props.channelId,- senderId,- optimisticId: crypto.randomUUID(),- message: buildPostMessageRequest({- snapshot,- threadId: props.messageId,- participantIds: participants.ids(),- }),- });-- props.setReplyInputState(undefined);- props.setIsReplying(false);+ sendMessageMutation.mutate(+ {+ channelID: props.channelId,+ senderId,+ optimisticId: crypto.randomUUID(),+ message: buildPostMessageRequest({+ snapshot,+ threadId: props.messageId,+ participantIds: participants.ids(),+ }),+ },+ {+ onSuccess: () => {+ props.setReplyInputState(undefined);+ props.setIsReplying(false);+ },+ onError: () => {+ const handle = replyInputHandle();+ if (!handle) return;+ const current = props.replyInputState();+ if (current && hasSendableInputContent(current)) return;+ handle.restoreSnapshot(snapshot);+ },+ }+ );}}/></div>