From 78e5a639228ba846e38ae722590aec1310275c79 Mon Sep 17 00:00:00 2001 From: Eugenij Date: Sun, 1 Nov 2020 14:25:02 +0000 Subject: [PATCH] Apply 1 suggestion(s) to 1 file(s) --- src/services/chat_service/chat_service.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/services/chat_service/chat_service.js b/src/services/chat_service/chat_service.js index 815af82e..b0905dc1 100644 --- a/src/services/chat_service/chat_service.js +++ b/src/services/chat_service/chat_service.js @@ -78,6 +78,12 @@ const add = (storage, { messages: newMessages, updateMaxId = true }) => { if (message.fakeId) { const fakeMessage = storage.idIndex[message.fakeId] if (fakeMessage) { + // In case the same id exists (chat update before POST response) + // make sure to remove the older duplicate message. + if (storage.idIndex[message.id]) { + delete storage.idIndex[message.id] + storage.messages = storage.messages.filter(msg => msg.id !== message.id) + } Object.assign(fakeMessage, message, { error: false }) delete fakeMessage['fakeId'] storage.idIndex[fakeMessage.id] = fakeMessage