Apply 1 suggestion(s) to 1 file(s)

This commit is contained in:
Eugenij 2020-11-01 14:25:02 +00:00 committed by eugenijm
parent e798e9a417
commit 78e5a63922
1 changed files with 6 additions and 0 deletions

View File

@ -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