diff --git a/src/lib/ChatScreens/Chat.svelte b/src/lib/ChatScreens/Chat.svelte index 72d8da0b..4f6f41b0 100644 --- a/src/lib/ChatScreens/Chat.svelte +++ b/src/lib/ChatScreens/Chat.svelte @@ -8,14 +8,15 @@ import { CurrentCharacter, CurrentChat, CurrentVariablePointer, HideIconStore, ReloadGUIPointer } from "../../ts/stores"; import { translateHTML } from "../../ts/translator/translator"; import { risuChatParser } from "src/ts/process/scripts"; - import { get } from "svelte/store"; + import { get, type Unsubscriber } from "svelte/store"; import { isEqual } from "lodash"; import { sayTTS } from "src/ts/process/tts"; import { getModelShortName } from "src/ts/model/names"; import { capitalize } from "src/ts/util"; - import { longpress } from "src/ts/gui/longtouch"; - import { ColorSchemeTypeStore } from "src/ts/gui/colorscheme"; - import { ConnectionOpenStore } from "src/ts/sync/multiuser"; + import { longpress } from "src/ts/gui/longtouch"; + import { ColorSchemeTypeStore } from "src/ts/gui/colorscheme"; + import { ConnectionOpenStore } from "src/ts/sync/multiuser"; + import { onDestroy, onMount } from "svelte"; export let message = '' export let name = '' export let largePortrait = false @@ -72,7 +73,7 @@ $CurrentChat.message = msg } - function displaya(message:string, chatPointer?:any){ + function displaya(message:string){ msgDisplay = risuChatParser(message, {chara: name, chatID: idx, rmVar: true, visualize: true}) } @@ -91,23 +92,22 @@ $: blankMessage = (message === '{{none}}' || message === '{{blank}}' || message === '') && idx === -1 const markParsing = async (data: string, charArg?: string | simpleCharacterArgument, mode?: "normal" | "back", chatID?: number, translateText?:boolean, tries?:number) => { try { - if((!isEqual(lastCharArg, charArg)) || (chatID !== lastChatId)){ - lastParsed = '' - lastCharArg = charArg - lastChatId = chatID - translateText = false - try { - translated = get(DataBase).autoTranslate - if(translated){ - translateText = true - } - } catch (error) {} - } + if((!isEqual(lastCharArg, charArg)) || (chatID !== lastChatId)){ + lastParsed = '' + lastCharArg = charArg + lastChatId = chatID + translateText = false + try { + translated = get(DataBase).autoTranslate + if(translated){ + translateText = true + } + } catch (error) {} + } if(translateText){ if(!$DataBase.legacyTranslation){ const marked = await ParseMarkdown(data, charArg, 'pretranslate', chatID) translating = true - console.log(marked) const translated = await postTranslationParse(await translateHTML(marked, false, charArg, chatID)) translating = false lastParsed = translated @@ -141,7 +141,22 @@ } } - $: displaya(message, $CurrentVariablePointer) + $: displaya(message) + + const unsubscribers:Unsubscriber[] = [] + + onMount(()=>{ + unsubscribers.push(CurrentVariablePointer.subscribe((v) => { + displaya(message) + })) + unsubscribers.push(ReloadGUIPointer.subscribe((v) => { + displaya(message) + })) + }) + + onDestroy(()=>{ + unsubscribers.forEach(u => u()) + })
diff --git a/src/ts/process/triggers.ts b/src/ts/process/triggers.ts index 19a68cf5..e959e758 100644 --- a/src/ts/process/triggers.ts +++ b/src/ts/process/triggers.ts @@ -3,7 +3,7 @@ import { DataBase, type Chat, type character } from "../storage/database"; import { tokenize } from "../tokenizer"; import { getModuleTriggers } from "./modules"; import { get } from "svelte/store"; -import { CurrentCharacter, CurrentChat, selectedCharID } from "../stores"; +import { CurrentCharacter, CurrentChat, ReloadGUIPointer, selectedCharID } from "../stores"; import { processMultiCommand } from "./command"; import { parseKeyValue } from "../util"; import { alertError, alertInput, alertNormal, alertSelect } from "../alert"; @@ -531,6 +531,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{ if(varChanged){ const currentChat = get(CurrentChat) currentChat.scriptstate = chat.scriptstate + ReloadGUIPointer.set(get(ReloadGUIPointer) + 1) } return {additonalSysPrompt, chat, tokens:caculatedTokens, stopSending, sendAIprompt}