Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate messgaes in history after re-connecting (v2) #412

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/webchat/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +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: [
...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: {
Expand Down
Loading