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) {
|
||||||
|
const childMessage = history.messages[childId];
|
||||||
|
const grandChildrenIds = childMessage.childrenIds ?? [];
|
||||||
|
grandchildrenIds.push(...grandChildrenIds);
|
||||||
|
}
|
||||||
|
|
||||||
messageChildrenIds.forEach((childId) => {
|
history.messages[parentId].childrenIds.push(...grandchildrenIds);
|
||||||
const child = history.messages[childId];
|
history.messages[parentId].childrenIds = history.messages[parentId].childrenIds.filter(
|
||||||
if (child && child.childrenIds) {
|
(id) => id !== messageId
|
||||||
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
|
await updateChatById(localStorage.token, chatId, { messages, history });
|
||||||
history.messages[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
|
|
||||||
.filter((id) => id !== childId);
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove prompt
|
|
||||||
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