@@ -16,7 +16,6 @@ import {
16
16
import { StoreState } from "./store" ;
17
17
import xAppOverlay from "./xapp-overlay/slice" ;
18
18
import queueUpdates from "./queue-updates/slice" ;
19
- import { IStreamingMessage } from "../../common/interfaces/message" ;
20
19
21
20
const rootReducer = ( state , action ) => {
22
21
const combinedReducer = combineReducers ( {
@@ -53,18 +52,19 @@ export type SetPrevStateAction = ReturnType<typeof setPrevState>;
53
52
54
53
export const reducer = ( state = rootReducer ( undefined , { type : "" } ) , action ) => {
55
54
switch ( action . type ) {
55
+ // This is actually "Restore persisted history"
56
56
case "RESET_STATE" : {
57
+ // To avoid duplicate messages in chat history during re-connection, we only restore messages and prepend them if the current message history is empty
58
+ const isEmptyHistory =
59
+ state . messages . messageHistory . length === 0 ||
60
+ ( state . messages . messageHistory . length === 1 &&
61
+ state . messages . messageHistory [ 0 ] . source === "engagement" ) ;
62
+ const messages = isEmptyHistory ? action . state . messages : [ ] ;
57
63
return rootReducer (
58
64
{
59
65
...state ,
60
66
messages : {
61
- messageHistory : [
62
- // To avoid duplicate messages in chat history during re-connection, we only restore messages and prepend them if the current message history is empty
63
- ...( state . messages . messageHistory . length === 0
64
- ? action . state . messages
65
- : [ ] ) ,
66
- ...state . messages . messageHistory ,
67
- ] ,
67
+ messageHistory : [ ...messages , ...state . messages . messageHistory ] ,
68
68
visibleOutputMessages : state . messages . visibleOutputMessages ,
69
69
} ,
70
70
rating : {
0 commit comments