@@ -26,26 +26,33 @@ export const useChatStore = defineStore('chat-store', {
26
26
actions : {
27
27
async syncHistory ( ) {
28
28
const rooms = ( await fetchGetChatRooms ( ) ) . data
29
- // if (rooms.length <= 0)
30
- // return
31
-
32
- let uuid = null
29
+ let uuid = this . active
33
30
this . history = [ ]
34
31
this . chat = [ ]
35
- await rooms . forEach ( async ( r : Chat . History ) => {
32
+ for ( const r of rooms ) {
36
33
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
+ }
41
40
if ( uuid == null ) {
42
41
uuid = Date . now ( )
43
42
this . addHistory ( { title : 'New Chat' , uuid : Date . now ( ) , isEdit : false } )
44
43
}
45
-
46
44
this . active = uuid
47
45
this . reloadRoute ( uuid )
48
46
} ,
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
+
49
56
setUsingContext ( context : boolean ) {
50
57
this . usingContext = context
51
58
this . recordState ( )
@@ -64,7 +71,8 @@ export const useChatStore = defineStore('chat-store', {
64
71
if ( index !== - 1 ) {
65
72
this . history [ index ] = { ...this . history [ index ] , ...edit }
66
73
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 )
68
76
}
69
77
} ,
70
78
0 commit comments