Fix abort group generation

This commit is contained in:
Cohee 2023-12-11 20:03:31 +02:00
parent 0302686a96
commit d38a4dc6c1
1 changed files with 8 additions and 4 deletions

View File

@ -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);