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 cf1c8e8f2a
commit 648e60028d
4 changed files with 96 additions and 8 deletions

View File

@@ -62,6 +62,7 @@ import {
getMessageImages,
isVisionModel,
isDalle3,
removeOutdatedEntries,
} from "../utils";
import { uploadImage as uploadImageRemote } from "@/app/utils/chat";
@@ -959,10 +960,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) => {