forked from open-webui/open-webui
refac
This commit is contained in:
parent
03907f9a8a
commit
a9d74b669e
1 changed files with 15 additions and 33 deletions
|
@ -224,42 +224,24 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageDeleteHandler = async (messageId) => {
|
const messageDeleteHandler = async (messageId) => {
|
||||||
const messageToDelete = history.messages[messageId];
|
const message = history.messages[messageId];
|
||||||
const messageParentId = messageToDelete.parentId;
|
const parentId = message.parentId;
|
||||||
const messageChildrenIds = messageToDelete.childrenIds ?? [];
|
const childrenIds = message.childrenIds ?? [];
|
||||||
|
const grandchildrenIds = [];
|
||||||
|
|
||||||
const hasSibling = messageChildrenIds.some(childId => history.messages[childId]?.childrenIds?.length > 0);
|
// Iterate through childrenIds to find grandchildrenIds
|
||||||
|
for (const childId of childrenIds) {
|
||||||
messageChildrenIds.forEach((childId) => {
|
const childMessage = history.messages[childId];
|
||||||
const child = history.messages[childId];
|
const grandChildrenIds = childMessage.childrenIds ?? [];
|
||||||
if (child && child.childrenIds) {
|
grandchildrenIds.push(...grandChildrenIds);
|
||||||
if (child.childrenIds.length === 0 && !hasSibling) { // 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove response
|
history.messages[parentId].childrenIds.push(...grandchildrenIds);
|
||||||
history.messages[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
|
history.messages[parentId].childrenIds = history.messages[parentId].childrenIds.filter(
|
||||||
.filter((id) => id !== childId);
|
(id) => id !== messageId
|
||||||
});
|
);
|
||||||
|
|
||||||
// remove prompt
|
await updateChatById(localStorage.token, chatId, { messages, history });
|
||||||
history.messages[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
|
|
||||||
.filter((id) => id !== messageId);
|
|
||||||
|
|
||||||
await updateChatById(localStorage.token, chatId, {
|
|
||||||
messages: messages,
|
|
||||||
history: history
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue