Skip to content

Commit

Permalink
Avoid duplicate message in history on re-connect
Browse files Browse the repository at this point in the history
  • Loading branch information
sushmi21 committed May 7, 2024
1 parent 552759a commit 159b949
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 159b949

Please sign in to comment.