@@ -26,26 +26,33 @@ export const useChatStore = defineStore('chat-store', {
2626 actions : {
2727 async syncHistory ( ) {
2828 const rooms = ( await fetchGetChatRooms ( ) ) . data
29- // if (rooms.length <= 0)
30- // return
31-
32- let uuid = null
29+ let uuid = this . active
3330 this . history = [ ]
3431 this . chat = [ ]
35- await rooms . forEach ( async ( r : Chat . History ) => {
32+ for ( const r of rooms ) {
3633 this . history . unshift ( r )
37- uuid = r . uuid
38- const chatData = ( await fetchGetChatHistory ( r . uuid ) ) . data
39- this . chat . unshift ( { uuid : r . uuid , data : chatData } )
40- } )
34+ if ( uuid == null )
35+ uuid = r . uuid
36+ this . chat . unshift ( { uuid : r . uuid , data : [ ] } )
37+ if ( uuid === r . uuid )
38+ await this . syncChat ( r )
39+ }
4140 if ( uuid == null ) {
4241 uuid = Date . now ( )
4342 this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
4443 }
45-
4644 this . active = uuid
4745 this . reloadRoute ( uuid )
4846 } ,
47+
48+ async syncChat ( h : Chat . History ) {
49+ const chatIndex = this . chat . findIndex ( item => item . uuid === h . uuid )
50+ if ( chatIndex <= - 1 || this . chat [ chatIndex ] . data . length <= 0 ) {
51+ const chatData = ( await fetchGetChatHistory ( h . uuid ) ) . data
52+ this . chat . unshift ( { uuid : h . uuid , data : chatData } )
53+ }
54+ } ,
55+
4956 setUsingContext ( context : boolean ) {
5057 this . usingContext = context
5158 this . recordState ( )
@@ -64,7 +71,8 @@ export const useChatStore = defineStore('chat-store', {
6471 if ( index !== - 1 ) {
6572 this . history [ index ] = { ...this . history [ index ] , ...edit }
6673 this . recordState ( )
67- fetchRenameChatRoom ( this . history [ index ] . title , this . history [ index ] . uuid )
74+ if ( ! edit . isEdit )
75+ fetchRenameChatRoom ( this . history [ index ] . title , this . history [ index ] . uuid )
6876 }
6977 } ,
7078
0 commit comments