|
@@ -57,13 +57,15 @@
|
|
|
|
|
|
const chatId = payload[0]?.chat?._id
|
|
|
|
|
|
- // console.log(chatId, state[chatId]?.messages, payload)
|
|
|
-
|
|
|
const msgState = state[chatId]?.messages || []
|
|
|
|
|
|
- for (const newMsg of payload || []) {
|
|
|
- if (!msgState.find(oldMsg => oldMsg._id === newMsg._id)) {
|
|
|
- msgState.push(newMsg)
|
|
|
+ for (const newMsg of payload || []) {
|
|
|
+ const currIndex = msgState.findIndex(oldMsg => oldMsg._id === newMsg._id)
|
|
|
+
|
|
|
+ if (currIndex === -1) {
|
|
|
+ msgState.push(newMsg)
|
|
|
+ } else {
|
|
|
+ msgState[currIndex] = newMsg
|
|
|
}
|
|
|
}
|
|
|
|