mirror of
https://github.com/open-webui/open-webui
synced 2024-11-06 08:56:39 +00:00
refac: reassign grandchildren of deleted message as children of parent message
This commit is contained in:
parent
2250387382
commit
8c01197483
@ -224,15 +224,35 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const messageDeleteHandler = async (messageId) => {
|
const messageDeleteHandler = async (messageId) => {
|
||||||
const messageParentId = history.messages[messageId]?.parentId;
|
const messageToDelete = history.messages[messageId];
|
||||||
|
const messageParentId = messageToDelete.parentId;
|
||||||
|
const messageChildrenIds = messageToDelete.childrenIds ?? [];
|
||||||
|
|
||||||
if (messageParentId !== null) {
|
messageChildrenIds.forEach((childId) => {
|
||||||
history.messages[messageParentId].childrenIds = []
|
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, {
|
await updateChatById(localStorage.token, chatId, {
|
||||||
messages: messages,
|
messages: messages,
|
||||||
|
Loading…
Reference in New Issue
Block a user