Browse Source

fix:修复断线重连时可能会出现消息乱序的bug

master
xsx 2 years ago
parent
commit
f18a8e62eb
  1. 12
      im-ui/src/store/chatStore.js
  2. 12
      im-uniapp/store/chatStore.js

12
im-ui/src/store/chatStore.js

@ -174,8 +174,16 @@ export default {
}); });
chat.lastTimeTip = msgInfo.sendTime; chat.lastTimeTip = msgInfo.sendTime;
} }
// 新的消息 // 根据id顺序插入,防止消息乱序
chat.messages.push(msgInfo); let insertPos = chat.messages.length;
for (let idx in chat.messages) {
if (chat.messages[idx].id && msgInfo.id < chat.messages[idx].id) {
insertPos = idx;
console.log(`消息出现乱序,位置:${chat.messages.length},修正至:${insertPos}`);
break;
}
}
chat.messages.splice(insertPos, 0, msgInfo);
this.commit("saveToStorage"); this.commit("saveToStorage");
}, },
updateMessage(state, msgInfo) { updateMessage(state, msgInfo) {

12
im-uniapp/store/chatStore.js

@ -176,8 +176,16 @@ export default {
}); });
chat.lastTimeTip = msgInfo.sendTime; chat.lastTimeTip = msgInfo.sendTime;
} }
// 新的消息 // 根据id顺序插入,防止消息乱序
chat.messages.push(msgInfo); let insertPos = chat.messages.length;
for (let idx in chat.messages) {
if (chat.messages[idx].id && msgInfo.id < chat.messages[idx].id) {
insertPos = idx;
console.log(`消息出现乱序,位置:${chat.messages.length},修正至:${insertPos}`);
break;
}
}
chat.messages.splice(insertPos, 0, msgInfo);
this.commit("saveToStorage"); this.commit("saveToStorage");
}, },
updateMessage(state, msgInfo) { updateMessage(state, msgInfo) {

Loading…
Cancel
Save