From 25d1bf49922b59881d9267ac677c86e93b0c819a Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Tue, 9 Jul 2024 10:15:01 +0800 Subject: [PATCH] Refactor chat store and session sync logic (#494) --- web/src/store/modules/chat/index.ts | 10 ++++++---- web/src/views/chat/index.vue | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/src/store/modules/chat/index.ts b/web/src/store/modules/chat/index.ts index 6e275c29..ccb43501 100644 --- a/web/src/store/modules/chat/index.ts +++ b/web/src/store/modules/chat/index.ts @@ -9,7 +9,7 @@ import { deleteChatSession, updateChatSession as fetchUpdateChatByUuid, getChatSessionDefault, - getChatMessagesBySessionUUID as getChatSessionHistory, + getChatMessagesBySessionUUID, getChatSessionsByUser, getUserActiveChatSession, renameChatSession, @@ -82,9 +82,11 @@ export const useChatStore = defineStore('chat-store', { async syncChatMessages(need_uuid: string) { if (need_uuid) { - const messageData = await getChatSessionHistory(need_uuid) + const messageData = await getChatMessagesBySessionUUID(need_uuid) this.chat[need_uuid] = messageData - // this.reloadRoute(need_uuid) // !!! this cause cycle + await createOrUpdateUserActiveChatSession(need_uuid) + this.setActiveLocal(need_uuid) + //await this.reloadRoute(this.active) // !!! this cause cycle } }, @@ -93,7 +95,7 @@ export const useChatStore = defineStore('chat-store', { this.history.unshift(history) this.chat[history.uuid] = chatData this.active = history.uuid - this.reloadRoute(history.uuid) + this.reloadRoute(this.active) }, async updateChatSession(uuid: string, edit: Partial) { diff --git a/web/src/views/chat/index.vue b/web/src/views/chat/index.vue index 4d2f5433..eabe388d 100644 --- a/web/src/views/chat/index.vue +++ b/web/src/views/chat/index.vue @@ -41,6 +41,7 @@ const { scrollRef, scrollToBottom } = useScroll() // session uuid const { uuid: sessionUuid } = route.params as { uuid: string } chatStore.syncChatMessages(sessionUuid) + const dataSources = computed(() => chatStore.getChatSessionDataByUuid(sessionUuid)) const chatSession = computed(() => chatStore.getChatSessionByUuid(sessionUuid))