From 1c8dceb304b1bcf69c7b43658222db53a9c0bf21 Mon Sep 17 00:00:00 2001 From: Sushmitha Sekar Date: Wed, 1 May 2024 23:26:56 +0200 Subject: [PATCH 1/4] Remove message prepending --- src/webchat/store/reducer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webchat/store/reducer.ts b/src/webchat/store/reducer.ts index a3f01102..bed5654e 100644 --- a/src/webchat/store/reducer.ts +++ b/src/webchat/store/reducer.ts @@ -36,7 +36,8 @@ export const reducer = (state = rootReducer(undefined, { type: '' }), action) => return rootReducer({ ...state, messages: [ - ...action.state.messages, + // TODO: Prepending messages causes duplicates in the message history. Find out why messages are prepended in the first place. + // ...action.state.messages, ...state.messages, ], rating: { From babef28e8e9b997b8d7dc25d5f8d664c31763966 Mon Sep 17 00:00:00 2001 From: Sushmitha Sekar Date: Mon, 6 May 2024 16:21:22 +0200 Subject: [PATCH 2/4] Fix logic to prepend messages --- src/webchat/store/reducer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webchat/store/reducer.ts b/src/webchat/store/reducer.ts index bed5654e..24004f79 100644 --- a/src/webchat/store/reducer.ts +++ b/src/webchat/store/reducer.ts @@ -33,11 +33,13 @@ export const reducer = (state = rootReducer(undefined, { type: '' }), action) => switch (action.type) { case 'RESET_STATE': { // We only restore messages and prepend them to the current message history + console.log(action.state.messages); + return rootReducer({ ...state, messages: [ - // TODO: Prepending messages causes duplicates in the message history. Find out why messages are prepended in the first place. - // ...action.state.messages, + // To avaoid duplicate messages in chat history during re-connection, we only restore messages if the current message history is empty + ...state.messages.length === 0 && action.state.messages, ...state.messages, ], rating: { From 4717b2ca5ca44684d7fca2797f291c125285b8c3 Mon Sep 17 00:00:00 2001 From: Sushmitha Sekar Date: Tue, 7 May 2024 09:24:37 +0200 Subject: [PATCH 3/4] Remove console log --- src/webchat/store/reducer.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/webchat/store/reducer.ts b/src/webchat/store/reducer.ts index 24004f79..bf96a277 100644 --- a/src/webchat/store/reducer.ts +++ b/src/webchat/store/reducer.ts @@ -33,8 +33,6 @@ export const reducer = (state = rootReducer(undefined, { type: '' }), action) => switch (action.type) { case 'RESET_STATE': { // We only restore messages and prepend them to the current message history - console.log(action.state.messages); - return rootReducer({ ...state, messages: [ From 120222c367d0c59e7520dd06a5605dda1618c1b5 Mon Sep 17 00:00:00 2001 From: Sushmitha Sekar Date: Tue, 7 May 2024 09:25:02 +0200 Subject: [PATCH 4/4] Fix typo --- src/webchat/store/reducer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webchat/store/reducer.ts b/src/webchat/store/reducer.ts index bf96a277..673bed9e 100644 --- a/src/webchat/store/reducer.ts +++ b/src/webchat/store/reducer.ts @@ -36,7 +36,7 @@ export const reducer = (state = rootReducer(undefined, { type: '' }), action) => return rootReducer({ ...state, messages: [ - // To avaoid duplicate messages in chat history during re-connection, we only restore messages if the current message history is empty + // To avoid duplicate messages in chat history during re-connection, we only restore messages if the current message history is empty ...state.messages.length === 0 && action.state.messages, ...state.messages, ],