diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index c76d53f3f..dad8b167f 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -609,6 +609,12 @@ function getGroupChatNames(groupId) { } async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { + function throwIfAborted() { + if (params.signal instanceof AbortSignal && params.signal.aborted) { + throw new Error('AbortSignal was fired. Group generation stopped'); + } + } + if (online_status === 'no_connection') { is_group_generating = false; setSendButtonState(false); @@ -635,6 +641,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { } try { + throwIfAborted(); hideSwipeButtons(); is_group_generating = true; setCharacterName(''); @@ -664,10 +671,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { } } - if (params.signal instanceof AbortSignal && params.signal.aborted) { - throw new Error('Already aborted signal passed. Group generation stopped'); - } - const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL); const enabledMembers = group.members.filter(x => !group.disabled_members.includes(x)); let activatedMembers = []; @@ -712,6 +715,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) { // now the real generation begins: cycle through every activated character for (const chId of activatedMembers) { + throwIfAborted(); deactivateSendButtons(); const generateType = type == 'swipe' || type == 'impersonate' || type == 'quiet' || type == 'continue' ? type : 'group_chat'; setCharacterId(chId);