Browse Source
!55 发送方,发送图片和文件时,图片总是出现在聊天记录的头部,原因应该是 msgInfo.id =0 导致的
Merge pull request !55 from tb/feature/fix-bug
master
blue
2 years ago
committed by
Gitee
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with
12 additions and
6 deletions
-
im-ui/src/store/chatStore.js
|
|
|
@ -176,13 +176,19 @@ export default { |
|
|
|
} |
|
|
|
// 根据id顺序插入,防止消息乱序
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
if(msgInfo.id>0){ |
|
|
|
//防止 图片、文件 在发送方 显示 在顶端 因为还没存库,id=0
|
|
|
|
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"); |
|
|
|
}, |
|
|
|
|