File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,17 @@ export type SetPrevStateAction = ReturnType<typeof setPrevState>;
52
52
53
53
export const reducer = ( state = rootReducer ( undefined , { type : "" } ) , action ) => {
54
54
switch ( action . type ) {
55
+ // This is actually "Restore persisted history"
55
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 . length === 0 ||
60
+ ( state . messages . length === 1 && state . messages [ 0 ] . source === "engagement" ) ;
61
+ const messages = isEmptyHistory ? action . state . messages : [ ] ;
56
62
return rootReducer (
57
63
{
58
64
...state ,
59
- messages : [
60
- // To avoid duplicate messages in chat history during re-connection, we only restore messages and prepend them if the current message history is empty
61
- ...( state . messages . length === 0 ? action . state . messages : [ ] ) ,
62
- ...state . messages ,
63
- ] ,
65
+ messages : [ ...messages , ...state . messages ] ,
64
66
rating : {
65
67
...state . rating ,
66
68
hasGivenRating : action . state . rating . hasGivenRating ,
You can’t perform that action at this time.
0 commit comments