perf: 优化消息更新太快导致不更新数据的情况

This commit is contained in:
kuaifan 2023-12-14 16:30:07 +08:00
parent 603db9de7f
commit 9ca9de0d7e

View File

@ -3261,27 +3261,22 @@ export default {
break;
case 'update':
case 'readed':
// 更新、已读回执
if (state.dialogMsgs.find(({id}) => id == data.id)) {
dispatch("saveDialogMsg", data)
// 更新待办
if (typeof data.todo !== "undefined") {
dispatch("getDialogTodo", dialog_id)
const updateMsg = (data, count) => {
if (state.dialogMsgs.find(({id}) => id == data.id)) {
dispatch("saveDialogMsg", data)
// 更新待办
if (typeof data.todo !== "undefined") {
dispatch("getDialogTodo", dialog_id)
}
return;
}
if (count <= 5) {
setTimeout(_ => {
updateMsg(data, ++count)
}, 500);
}
} else if (mode === 'readed') {
// 消息不存在,重试已读标记
let readedNum = 0
const readedTimer = setInterval(_ => {
if (readedNum > 6) {
clearInterval(readedTimer)
}
if (state.dialogMsgs.find(({id}) => id == data.id)) {
clearInterval(readedTimer)
dispatch("saveDialogMsg", data)
}
readedNum++
}, 500)
}
updateMsg(data, 0);
break;
case 'groupAdd':
case 'groupJoin':