Fix not jumping twice to group chat when creating a new group chat with deleting the old one (#4602) * fix: do not jumo to chat twice on new group chat with delete * fix: prevent metadata reset when deleting non-active group chat * Bring back group chat splice call * Always delete past group metadata on chat delete --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

39fd16fe86230e551449f71d0bd9b5d28a4d4b67

Wolfsblvt <wolfsblvt@gmail.com>

Signed
2 files changed, +16 -4Showing whitespace changes
public/script.js+1 -1
@@ -9011,7 +9011,7 @@ export async function doNewChat({ deleteCurrentChat = false } = {}) {
90119011
90129012 if (selected_group) {
90139013 await createNewGroupChat(selected_group);
9014- if (deleteCurrentChat) await deleteGroupChat(selected_group, chat_file_for_del);
9014+ if (deleteCurrentChat) await deleteGroupChat(selected_group, chat_file_for_del, { jumpToNewChat: false }); // don't jump, new chat was already created and jumped to above
90159015 }
90169016 else {
90179017 //RossAscends: added character name to new chat filenames and replaced Date.now() with humanizedDateTime;
public/scripts/group-chats.js+15 -3
@@ -2018,7 +2018,14 @@ export async function deleteGroupChatByName(groupId, chatName) {
20182018 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatName);
20192019}
20202020
2021-export async function deleteGroupChat(groupId, chatId) {
2021+/**
2022+ * Deletes a group chat by name.
2023+ * @param {string} groupId The ID of the group containing the chat to delete.
2024+ * @param {string} chatId The id/name of the chat to delete.
2025+ * @param {object} [options={}] Options for the deletion.
2026+ * @param {boolean} [options.jumpToNewChat=true] Whether to jump to a new chat after deletion (existing one, or create a new one if none exists)
2027+ */
2028+export async function deleteGroupChat(groupId, chatId, { jumpToNewChat = true } = {}) {
20222029 const group = groups.find(x => x.id === groupId);
20232030
20242031 if (!group || !group.chats.includes(chatId)) {
@@ -2026,10 +2033,13 @@ export async function deleteGroupChat(groupId, chatId) {
20262033 }
20272034
20282035 group.chats.splice(group.chats.indexOf(chatId), 1);
2029- group.chat_metadata = {};
2030- group.chat_id = '';
20312036 delete group.past_metadata[chatId];
2037+
2038+ if (group.chat_id === chatId) {
2039+ group.chat_id = '';
2040+ group.chat_metadata = {};
20322041 updateChatMetadata(group.chat_metadata, true);
2042+ }
20332043
20342044 const response = await fetch('/api/chats/group/delete', {
20352045 method: 'POST',
@@ -2038,11 +2048,13 @@ export async function deleteGroupChat(groupId, chatId) {
20382048 });
20392049
20402050 if (response.ok) {
2051+ if (jumpToNewChat) {
20412052 if (group.chats.length) {
20422053 await openGroupChat(groupId, group.chats[group.chats.length - 1]);
20432054 } else {
20442055 await createNewGroupChat(groupId);
20452056 }
2057+ }
20462058
20472059 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatId);
20482060 }