Fix: In order to distinguish the keys of a pair of messages, add a prefix to the id when rendering the message. #4409 (#4451)

### What problem does this PR solve?

Fix: In order to distinguish the keys of a pair of messages, add a
prefix to the id when rendering the message. #4409

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2025-01-13 10:51:59 +08:00
committed by GitHub
parent 95261f17f6
commit 2c7ba90cb4
6 changed files with 23 additions and 26 deletions

View File

@ -7,7 +7,7 @@ import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { IClientConversation, IMessage } from '@/pages/chat/interface';
import api from '@/utils/api';
import { getAuthorization } from '@/utils/authorization-util';
import { buildMessageUuid, getMessagePureId } from '@/utils/chat';
import { buildMessageUuid } from '@/utils/chat';
import { PaginationProps, message } from 'antd';
import { FormInstance } from 'antd/lib';
import axios from 'axios';
@ -309,7 +309,9 @@ export const useSelectDerivedMessages = () => {
...pre,
{
...message,
id: buildMessageUuid(message),
id: buildMessageUuid(message), // The message id is generated on the front end,
// and the message id returned by the back end is the same as the question id,
// so that the pair of messages can be deleted together when deleting the message
},
{
role: MessageType.Assistant,
@ -353,10 +355,7 @@ export const useSelectDerivedMessages = () => {
const removeMessageById = useCallback(
(messageId: string) => {
setDerivedMessages((pre) => {
const nextMessages =
pre?.filter(
(x) => getMessagePureId(x.id) !== getMessagePureId(messageId),
) ?? [];
const nextMessages = pre?.filter((x) => x.id !== messageId) ?? [];
return nextMessages;
});
},