Skip to content

Commit

Permalink
Merge pull request #415 from Cognigy/bug/65227-duplicate-input-and-ou…
Browse files Browse the repository at this point in the history
…tput-after-reconnecting-v3

Avoid duplicate message in history on re-connect in (v3)
  • Loading branch information
kwinto authored May 7, 2024
2 parents 00e5646 + 159b949 commit 1bc63ea
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/webchat/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export type SetPrevStateAction = ReturnType<typeof setPrevState>;
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
return rootReducer(
{
...state,
messages: [...action.state.messages, ...state.messages],
messages: [
// To avoid duplicate messages in chat history during re-connection, we only restore messages and prepend them if the current message history is empty
...state.messages.length === 0 ? action.state.messages : [],
...state.messages
],
rating: {
...state.rating,
hasGivenRating: action.state.rating.hasGivenRating,
Expand Down

0 comments on commit 1bc63ea

Please sign in to comment.