@@ -3,20 +3,22 @@ import styles from '../styles/ChatGPT.module.scss';
33import { useEffect } from 'react' ;
44import { ipcRenderer } from 'electron' ;
55
6+ const chatuiClient = createClient ( ) ;
67
78export default function Chat ( props : {
89 date : string ;
910 roomName : string ;
1011} ) {
11- const chatuiClient = createClient ( ) ;
12- chatuiClient . chatboxStore . on ( 'submit' , ( message ) => {
12+
13+ const sendMessage = ( message : string ) => {
1314 ipcRenderer . send ( 'send-chat-content' , {
1415 roomName : props . roomName . replace ( '.txt' , '' ) ,
1516 content : message ,
1617 } ) ;
17- } ) ;
18-
18+ } ;
1919 useEffect ( ( ) => {
20+
21+ chatuiClient . chatboxStore . on ( 'submit' , sendMessage ) ;
2022 chatuiClient . messageStore . clear ( ) ;
2123 ipcRenderer . send ( 'get-chat-content' , {
2224 date : props . date ,
@@ -32,6 +34,9 @@ export default function Chat(props: {
3234 console . log ( 'chat-replay' , args ) ;
3335 if ( args . date == props . date && args . roomName == props . roomName ) {
3436 args . chats . forEach ( ( chat ) => {
37+ if ( chatuiClient . messageStore . messages . find ( ( m ) => m . id == chat . name + chat . content + chat . time ) ) {
38+ return ;
39+ }
3540 chatuiClient . messageStore . addMessageDirect ( {
3641 id : chat . name + chat . content + chat . time ,
3742 role : 'assistant' ,
@@ -43,15 +48,17 @@ export default function Chat(props: {
4348 typing : false ,
4449 timestamp : ( new Date ( chat . time ) ) . getTime ( ) ,
4550 } ) ;
51+ chatuiClient . messageStore . emit ( 'change' ) ;
4652 } ) ;
47- chatuiClient . messageStore . emit ( 'change' ) ;
53+
4854 } else {
4955 }
5056
5157 } ) ;
5258 return ( ) => {
5359 timer && clearInterval ( timer ) ;
5460 ipcRenderer . removeAllListeners ( 'chat-content-replay' ) ;
61+ chatuiClient . chatboxStore . removeListener ( 'submit' , sendMessage ) ;
5562 } ;
5663 } , [ ] ) ;
5764 return < ChatProvider client = { chatuiClient ! } >
0 commit comments