From a52ee4dc77ced243b46ec9986b633ec5c9eeec6f Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 30 Sep 2025 22:14:07 +0800 Subject: [PATCH] fix(ai): edit message should updated message Signed-off-by: Innei --- .../components/layouts/WelcomeScreen.tsx | 2 +- .../components/message/AIChatMessage.tsx | 2 +- .../message/UserRichTextMessage.tsx | 24 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx index 2e5cb79d9..ac294782e 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx @@ -54,7 +54,7 @@ export const WelcomeScreen = ({ onSend, centerInputOnEmpty }: WelcomeScreenProps const month = now.getMonth() + 1 const year = now.getFullYear() - return `${AI_CHAT_SPECIAL_ID_PREFIX}${year}-${month}-${day}` + return `${AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY}${year}-${month}-${day}` }, []) const status = useChatStatus() diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIChatMessage.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIChatMessage.tsx index d0131c3c0..e428e52db 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIChatMessage.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIChatMessage.tsx @@ -110,7 +110,7 @@ export const AIChatMessage: React.FC = React.memo(
{/* Normal message display */}
-
+
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserRichTextMessage.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserRichTextMessage.tsx index 348b00cf8..630666b99 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserRichTextMessage.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/UserRichTextMessage.tsx @@ -3,11 +3,13 @@ import { defaultLexicalTheme } from "@follow/components/ui/lexical-rich-editor/t import { cn } from "@follow/utils" import type { InitialConfigType } from "@lexical/react/LexicalComposer" import { LexicalComposer } from "@lexical/react/LexicalComposer" +import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext" import { ContentEditable } from "@lexical/react/LexicalContentEditable" import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary" import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin" import type { SerializedEditorState } from "lexical" import * as React from "react" +import isEqual from "react-fast-compare" import { FileAttachmentNode } from "../../editor" import { MentionNode } from "../../editor/plugins/mention/MentionNode" @@ -26,6 +28,7 @@ interface UserRichTextMessageProps { export const UserRichTextMessage: React.FC = React.memo( ({ data, className }) => { + const editorState = typeof data.state === "object" ? JSON.stringify(data.state) : data.state let initialConfig: InitialConfigType = null! if (!initialConfig) { initialConfig = { @@ -33,12 +36,12 @@ export const UserRichTextMessage: React.FC = React.mem theme: defaultLexicalTheme, onError, editable: false, - editorState: typeof data.state === "object" ? JSON.stringify(data.state) : data.state, + editorState, nodes: [...LexicalRichEditorNodes, MentionNode, FileAttachmentNode], } } return ( -
+
= React.mem ErrorBoundary={LexicalErrorBoundary} placeholder={null} /> +
) }, ) + +const ListenableContentChangedPlugin = ({ state }: { state: string }) => { + const [editor] = useLexicalComposerContext() + React.useEffect(() => { + const editorState = editor.getEditorState() + editorState.read(() => { + const text = editorState.toJSON() + + if (isEqual(text, state)) { + return + } + editor.setEditorState(editor.parseEditorState(state)) + }) + }, [editor, state]) + return null +}