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()) + })