Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
a9d74b66
Commit
a9d74b66
authored
Mar 06, 2024
by
Timothy J. Baek
Browse files
refac
parent
03907f9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
34 deletions
+16
-34
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+16
-34
No files found.
src/lib/components/chat/Messages.svelte
View file @
a9d74b66
...
@@ -224,42 +224,24 @@
...
@@ -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
messageChildrenIds.forEach((childId) => {
for (const childId of childrenIds) {
const child = history.messages[childId];
const childMessage = history.messages[childId];
if (child && child.childrenIds) {
const grandChildrenIds = childMessage.childrenIds ?? [];
if (child.childrenIds.length === 0 && !hasSibling) { // if last prompt/response pair
grandchildrenIds.push(...grandChildrenIds);
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[messageParentId].childrenIds = history.messages[messageParentId].childrenIds
.filter((id) => id !== childId);
});
// remove prompt
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 !== messageId);
(id) => id !== messageId
);
await updateChatById(localStorage.token, chatId, {
await updateChatById(localStorage.token, chatId, { messages, history });
messages: messages,
history: history
});
};
};
</script>
</script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment