Fix auto-load not triggering from hotswaps

This commit is contained in:
Cohee 2023-08-19 22:22:24 +03:00
parent 5d1e27c820
commit bab368e3d2
3 changed files with 14 additions and 10 deletions

View File

@ -33,12 +33,12 @@ import {
} from "./power-user.js";
import { LoadLocal, SaveLocal, CheckLocal, LoadLocalBool } from "./f-localStorage.js";
import { selected_group, is_group_generating, getGroupAvatar, groups } from "./group-chats.js";
import { selected_group, is_group_generating, getGroupAvatar, groups, openGroupById } from "./group-chats.js";
import {
SECRET_KEYS,
secret_state,
} from "./secrets.js";
import { sortByCssOrder, debounce, delay } from "./utils.js";
import { debounce, delay } from "./utils.js";
import { chat_completion_sources, oai_settings } from "./openai.js";
var NavToggle = document.getElementById("nav-toggle");
@ -354,10 +354,8 @@ async function RA_autoloadchat() {
selectCharacterById(String(active_character_id));
}
let groupToAutoLoad = document.querySelector(`.group_select[grid="${active_group}"]`);
if (groupToAutoLoad != null) {
$(groupToAutoLoad).click();
if (active_group != null) {
openGroupById(String(active_group));
}
// if the character list hadn't been loaded yet, try again.
@ -395,17 +393,18 @@ export async function favsToHotswap() {
slot.attr('grid', isGroup ? grid : '');
slot.attr('chid', isCharacter ? chid : '');
slot.data('id', isGroup ? grid : chid);
slot.attr('title', '');
if (isGroup) {
const group = groups.find(x => x.id === grid);
const avatar = getGroupAvatar(group);
$(slot).find('img').replaceWith(avatar);
$(slot).attr('title', group.name);
}
if (isCharacter) {
const avatarUrl = getThumbnailUrl('avatar', entity.item.avatar);
$(slot).find('img').attr('src', avatarUrl);
$(slot).attr('title', entity.item.avatar);
}
$(slot).css('cursor', 'pointer');
@ -933,14 +932,16 @@ $("document").ready(function () {
// when a char is selected from the list, save their name as the auto-load character for next page load
$(document).on("click", ".character_select", function () {
setActiveCharacter($(this).find('.avatar').attr('title'));
const characterId = $(this).find('.avatar').attr('title') || $(this).attr('title');
setActiveCharacter(characterId);
setActiveGroup(null);
saveSettingsDebounced();
});
$(document).on("click", ".group_select", function () {
const groupId = $(this).data('id') || $(this).attr('grid');
setActiveCharacter(null);
setActiveGroup($(this).data('id'));
setActiveGroup(groupId);
saveSettingsDebounced();
});

View File

@ -308,6 +308,9 @@ async function getGroups() {
// Convert groups to new format
for (const group of groups) {
if (typeof group.id === 'number') {
group.id = String(group.id);
}
if (group.disabled_members == undefined) {
group.disabled_members = [];
}

View File

@ -2659,7 +2659,7 @@ app.post('/creategroup', jsonParser, (request, response) => {
return response.sendStatus(400);
}
const id = Date.now();
const id = String(Date.now());
const groupMetadata = {
id: id,
name: request.body.name ?? 'New Group',