feat: Delete message by id #2088 (#2155)

### What problem does this PR solve?

feat: Delete message by id #2088

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-08-29 14:32:04 +08:00
committed by GitHub
parent f87e7242cd
commit f8a479bf88
7 changed files with 84 additions and 9 deletions

View File

@ -314,6 +314,10 @@ export const useDeleteMessage = () => {
conversationId,
});
if (data.retcode === 0) {
message.success(i18n.t(`message.deleted`));
}
return data.retcode;
},
});

View File

@ -5,8 +5,10 @@ import { ResponseType } from '@/interfaces/database/base';
import { IAnswer } from '@/interfaces/database/chat';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { IClientConversation } from '@/pages/chat/interface';
import api from '@/utils/api';
import { getAuthorization } from '@/utils/authorization-util';
import { getMessagePureId } from '@/utils/chat';
import { PaginationProps } from 'antd';
import { FormInstance } from 'antd/lib';
import axios from 'axios';
@ -306,6 +308,34 @@ export const useHandleMessageInputChange = () => {
};
};
export interface IRemoveMessageById {
removeMessageById(messageId: string): void;
}
export const useRemoveMessageById = (
setCurrentConversation: (
callback: (state: IClientConversation) => IClientConversation,
) => void,
) => {
const removeMessageById = useCallback(
(messageId: string) => {
setCurrentConversation((pre) => {
const nextMessages =
pre.message?.filter(
(x) => getMessagePureId(x.id) !== getMessagePureId(messageId),
) ?? [];
return {
...pre,
message: nextMessages,
};
});
},
[setCurrentConversation],
);
return { removeMessageById };
};
// #endregion
/**