feat: The cloud synchronization feature is enhanced to support the synchronization of deleted conversations and deleted messages

This commit is contained in:
李超
2024-08-03 20:53:36 +08:00
parent 5065091b74
commit 22c79595fb
4 changed files with 96 additions and 8 deletions

View File

@@ -60,6 +60,7 @@ import {
getMessageTextContent,
getMessageImages,
isVisionModel,
removeOutdatedEntries,
} from "../utils";
import { uploadImage as uploadImageRemote } from "@/app/utils/chat";
@@ -923,10 +924,20 @@ function _Chat() {
};
const deleteMessage = (msgId?: string) => {
chatStore.updateCurrentSession(
(session) =>
(session.messages = session.messages.filter((m) => m.id !== msgId)),
);
chatStore.updateCurrentSession((session) => {
session.deletedMessageIds &&
removeOutdatedEntries(session.deletedMessageIds);
session.messages = session.messages.filter((m) => {
if (m.id !== msgId) {
return true;
}
if (!session.deletedMessageIds) {
session.deletedMessageIds = {} as Record<string, number>;
}
session.deletedMessageIds[m.id] = Date.now();
return false;
});
});
};
const onDelete = (msgId: string) => {