"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "8110a872d5b8fb88cd28c694486781f2dcb9a130"
Commit 8c011974 authored by Danny Liu's avatar Danny Liu
Browse files

refac: reassign grandchildren of deleted message as children of parent message

parent 22503873
......@@ -224,15 +224,35 @@
};
const messageDeleteHandler = async (messageId) => {
const messageParentId = history.messages[messageId]?.parentId;
if (messageParentId !== null) {
history.messages[messageParentId].childrenIds = []
}
const messageToDelete = history.messages[messageId];
const messageParentId = messageToDelete.parentId;
const messageChildrenIds = messageToDelete.childrenIds ?? [];
messageChildrenIds.forEach((childId) => {
const child = history.messages[childId];
if (child && child.childrenIds) {
if (child.childrenIds.length == 0) { // if last prompt/response pair
history.messages[messageParentId].childrenIds = []
history.currentId = messageParentId;
}
else {
child.childrenIds.forEach((grandChildId) => {
if (history.messages[grandChildId]) {
history.messages[grandChildId].parentId = messageParentId;
history.messages[messageParentId].childrenIds.push(grandChildId);
}
});
}
}
history.currentId = messageParentId;
// remove response
history.messages[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
.filter((id) => id !== childId);
});
await tick();
// remove prompt
history.messages[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
.filter((id) => id !== messageId);
await updateChatById(localStorage.token, chatId, {
messages: messages,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment