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
9012 if (selected_group) {9012 if (selected_group) {
9013 await createNewGroupChat(selected_group);9013 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
9015 }9015 }
9016 else {9016 else {
9017 //RossAscends: added character name to new chat filenames and replaced Date.now() with humanizedDateTime;9017 //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) {
2018 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatName);2018 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatName);
2019}2019}
20202020
2021export 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 */
2028export async function deleteGroupChat(groupId, chatId, { jumpToNewChat = true } = {}) {
2022 const group = groups.find(x => x.id === groupId);2029 const group = groups.find(x => x.id === groupId);
20232030
2024 if (!group || !group.chats.includes(chatId)) {2031 if (!group || !group.chats.includes(chatId)) {
@@ -2026,10 +2033,13 @@ export async function deleteGroupChat(groupId, chatId) {
2026 }2033 }
20272034
2028 group.chats.splice(group.chats.indexOf(chatId), 1);2035 group.chats.splice(group.chats.indexOf(chatId), 1);
2029 group.chat_metadata = {};
2030 group.chat_id = '';
2031 delete group.past_metadata[chatId];2036 delete group.past_metadata[chatId];
2037
2038 if (group.chat_id === chatId) {
2039 group.chat_id = '';
2040 group.chat_metadata = {};
2032 updateChatMetadata(group.chat_metadata, true);2041 updateChatMetadata(group.chat_metadata, true);
2042 }
20332043
2034 const response = await fetch('/api/chats/group/delete', {2044 const response = await fetch('/api/chats/group/delete', {
2035 method: 'POST',2045 method: 'POST',
@@ -2038,11 +2048,13 @@ export async function deleteGroupChat(groupId, chatId) {
2038 });2048 });
20392049
2040 if (response.ok) {2050 if (response.ok) {
2051 if (jumpToNewChat) {
2041 if (group.chats.length) {2052 if (group.chats.length) {
2042 await openGroupChat(groupId, group.chats[group.chats.length - 1]);2053 await openGroupChat(groupId, group.chats[group.chats.length - 1]);
2043 } else {2054 } else {
2044 await createNewGroupChat(groupId);2055 await createNewGroupChat(groupId);
2045 }2056 }
2057 }
20462058
2047 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatId);2059 await eventSource.emit(event_types.GROUP_CHAT_DELETED, chatId);
2048 }2060 }