diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index 91dc0a1..089b337 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -519,20 +519,15 @@ export default defineStore('chatStore', { } } } - // 正在发送中的消息可能没有id,只有tmpId - if (msgInfo.tmpId) { + // 正在发送中的临时消息可能没有id,只有tmpId + if (msgInfo.selfSend && msgInfo.tmpId) { for (let idx = chat.messages.length - 1; idx >= 0; idx--) { let m = chat.messages[idx]; - // 这里只查询临时消息,跳过正常消息 - if (m.id) { - continue; - } - // 这里只查询临时消息,跳过有id的正常消息 - if (m.id) { - contine; + if (!m.selfSend || !m.tmpId) { + continue; } - if (m.tmpId && msgInfo.tmpId == m.tmpId) { - return m; + if (msgInfo.tmpId == m.tmpId) { + return idx; } // 如果id比要查询的消息小,说明没有这条消息 if (m.tmpId && m.tmpId < msgInfo.tmpId) { diff --git a/im-web/src/store/chatStore.js b/im-web/src/store/chatStore.js index f4b6bc7..7b040d3 100644 --- a/im-web/src/store/chatStore.js +++ b/im-web/src/store/chatStore.js @@ -547,16 +547,15 @@ export default defineStore('chatStore', { } } } - // 正在发送中的消息可能没有id,只有tmpId - if (msgInfo.tmpId) { + // 正在发送中的临时消息可能没有id,只有tmpId + if (msgInfo.selfSend && msgInfo.tmpId) { for (let idx = chat.messages.length - 1; idx >= 0; idx--) { let m = chat.messages[idx]; - // 这里只查询临时消息,跳过正常消息 - if (m.id) { + if (!m.selfSend || !m.tmpId) { continue; } - if (m.tmpId && msgInfo.tmpId == m.tmpId) { - return m; + if (msgInfo.tmpId == m.tmpId) { + return idx; } // 如果id比要查询的消息小,说明没有这条消息 if (m.tmpId && m.tmpId < msgInfo.tmpId) {