From 67d7d50ee2b05f66de3ab6aea38ff5d7d56ce839 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sun, 29 Mar 2026 13:34:17 +0900 Subject: fix chat sync --- src/chat-view.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/chat-view.ts') diff --git a/src/chat-view.ts b/src/chat-view.ts index 72e7a32..dd27c63 100644 --- a/src/chat-view.ts +++ b/src/chat-view.ts @@ -7,7 +7,7 @@ import { ToolModal } from "./tool-modal"; import { TOOL_REGISTRY } from "./tools"; import type { OllamaToolDefinition } from "./tools"; import { collectVaultContext, formatVaultContext } from "./vault-context"; -import { loadChatHistory, saveChatHistory, clearChatHistory, toRuntimeMessages, toPersistableMessages } from "./chat-history"; +import { toRuntimeMessages, toPersistableMessages } from "./chat-history"; import type { PersistedMessage } from "./chat-history"; export const VIEW_TYPE_CHAT = "ai-pulse-chat"; @@ -116,8 +116,9 @@ export class ChatView extends ItemView { if (this.messageContainer !== null) { this.messageContainer.empty(); } - void clearChatHistory(this.plugin.app, this.plugin.manifest.id); + this.plugin.settings.chatHistory = []; this.plugin.updateChatSnapshot([]); + void this.plugin.saveSettings(); (document.activeElement as HTMLElement)?.blur(); }); @@ -161,7 +162,8 @@ export class ChatView extends ItemView { this.saveDebounceTimer = null; } // Save any pending history before closing - void saveChatHistory(this.plugin.app, this.plugin.manifest.id, this.messages); + this.plugin.settings.chatHistory = toPersistableMessages(this.messages); + void this.plugin.saveSettings(); this.contentEl.empty(); this.messages = []; this.bubbleContent.clear(); @@ -762,12 +764,12 @@ export class ChatView extends ItemView { } this.saveDebounceTimer = setTimeout(() => { this.saveDebounceTimer = null; - void saveChatHistory(this.plugin.app, this.plugin.manifest.id, this.messages); + const persistable = toPersistableMessages(this.messages); + this.plugin.settings.chatHistory = persistable; // Update the plugin's snapshot so the sync checker doesn't treat // our own save as an external change. - this.plugin.updateChatSnapshot( - toPersistableMessages(this.messages), - ); + this.plugin.updateChatSnapshot(persistable); + void this.plugin.saveSettings(); }, 500); } @@ -775,7 +777,7 @@ export class ChatView extends ItemView { * Restore chat history from the persisted file and render messages. */ private async restoreChatHistory(): Promise { - const persisted = await loadChatHistory(this.plugin.app, this.plugin.manifest.id); + const persisted = this.plugin.settings.chatHistory; if (persisted.length === 0) return; this.messages = toRuntimeMessages(persisted); @@ -828,7 +830,7 @@ export class ChatView extends ItemView { * Replaces the current messages and re-renders the UI. */ async reloadChatHistory(): Promise { - const persisted = await loadChatHistory(this.plugin.app, this.plugin.manifest.id); + const persisted = this.plugin.settings.chatHistory; // Skip reload if we're currently streaming — avoid disrupting the UI if (this.abortController !== null) return; -- cgit v1.2.3