diff --git a/public/script.js b/public/script.js index 302427a00..050dc6767 100644 --- a/public/script.js +++ b/public/script.js @@ -143,6 +143,7 @@ const system_messages = { is_user: false, is_system: true, is_name: true, + is_group: true, mes: "Group chat created. Say 'Hi' to lovely people!", }, empty: { @@ -920,7 +921,7 @@ async function Generate(type, automatic_trigger) { return; } - if (selected_group && !is_group_generating) { + if (selected_group) { generateGroupWrapper(false); return; } @@ -1607,7 +1608,7 @@ async function Generate(type, automatic_trigger) { ); } // clean-up group message from excessive generations - if (type == "group_chat" && selected_group) { + if (selected_group) { getMessage = cleanGroupMessage(getMessage); } let this_mes_is_name = true; @@ -1628,7 +1629,7 @@ async function Generate(type, automatic_trigger) { getMessage = $.trim(getMessage); chat[chat.length - 1]["mes"] = getMessage; - if (type === "group_chat") { + if (selected_group) { let avatarImg = default_avatar; if (characters[this_chid].avatar != "none") { avatarImg = `characters/${characters[this_chid].avatar}?${Date.now()}`; @@ -1641,7 +1642,7 @@ async function Generate(type, automatic_trigger) { $("#send_but").css("display", "inline"); $("#loading_mes").css("display", "none"); - if (type == "group_chat" && selected_group) { + if (selected_group) { saveGroupChat(selected_group); } else { saveChat(); @@ -1753,6 +1754,10 @@ function resultCheckStatusNovel() { async function saveChat() { chat.forEach(function (item, i) { + if (item["is_group"]) { + alert('Trying to save group chat with regular saveChat function. Aborting to prevent corruption.'); + throw new Error('Group chat saved from saveChat'); + } if (item["is_user"]) { var str = item["mes"].replace(name1 + ":", default_user_name + ":"); chat[i]["mes"] = str; diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 6466c1c3f..0bb69ea72 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -83,6 +83,7 @@ async function getGroupChat(id) { if (response.ok) { const data = await response.json(); if (Array.isArray(data) && data.length) { + data[0].is_group = true; for (let key of data) { chat.push(key); } @@ -238,6 +239,10 @@ async function generateGroupWrapper(by_auto_mode) { return; } + if (is_group_generating) { + return false; + } + const group = groups.find((x) => x.id === selected_group); if (!group || !Array.isArray(group.members) || !group.members.length) { @@ -308,6 +313,7 @@ async function generateGroupWrapper(by_auto_mode) { is_group_generating = false; setSendButtonState(false); setCharacterId(undefined); + setCharacterName(''); } } diff --git a/public/style.css b/public/style.css index 9f1a077b9..0d3b774b0 100644 --- a/public/style.css +++ b/public/style.css @@ -605,8 +605,7 @@ input[type=submit] {} } #rm_print_characters_block { - margin-top: 15px; - padding-bottom: 10vh; + margin: 15px 0; overflow-y: auto; }