Browse Source

fix: 查询消息的bug

master
xsx 8 months ago
parent
commit
dbaee8baf1
  1. 21
      im-uniapp/store/chatStore.js
  2. 2
      im-web/src/components/chat/ChatMessageItem.vue
  3. 19
      im-web/src/store/chatStore.js
  4. 1
      im-web/src/view/Home.vue

21
im-uniapp/store/chatStore.js

@ -165,7 +165,7 @@ export default defineStore('chatStore', {
let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo);
if (message) {
console.log("message:",message)
console.log("message:", message)
Object.assign(message, msgInfo);
chat.stored = false;
this.saveToStorage();
@ -498,24 +498,25 @@ export default defineStore('chatStore', {
return null;
}
for (let idx = chat.messages.length - 1; idx >= 0; idx--) {
if (!chat.messages[idx].id && !chat.messages[idx].tmpId) {
continue;
}
// 通过id判断
if (msgInfo.id && chat.messages[idx].id == msgInfo.id) {
if (msgInfo.id && chat.messages[idx].id) {
if (msgInfo.id == chat.messages[idx].id) {
return chat.messages[idx];
}
// 如果id比要查询的消息小,说明没有这条消息
if (msgInfo.id > chat.messages[idx].id) {
break;
}
}
// 正在发送中的消息可能没有id,只有tmpId
if (msgInfo.tmpId && chat.messages[idx].tmpId &&
chat.messages[idx].tmpId == msgInfo.tmpId) {
if (msgInfo.tmpId && chat.messages[idx].tmpId) {
if (msgInfo.tmpId == chat.messages[idx].tmpId) {
return chat.messages[idx];
}
// 如果id比要查询的消息小,说明没有这条消息
if (msgInfo.id && msgInfo.id > chat.messages[idx].id) {
if (msgInfo.tmpId > chat.messages[idx].tmpId) {
break;
}
if (msgInfo.tmpId && msgInfo.tmpId > chat.messages[idx].tmpId) {
break;
}
}
return null;

2
im-web/src/components/chat/ChatMessageItem.vue

@ -320,7 +320,7 @@ export default {
.message-image {
border-radius: 8px;
border: 3px solid var(--im-color-primary-light-8);
border: 2px solid var(--im-color-primary-light-9);
overflow: hidden;
cursor: pointer;
}

19
im-web/src/store/chatStore.js

@ -523,24 +523,25 @@ export default defineStore('chatStore', {
return null;
}
for (let idx = chat.messages.length - 1; idx >= 0; idx--) {
if (!chat.messages[idx].id && !chat.messages[idx].tmpId) {
continue;
}
// 通过id判断
if (msgInfo.id && chat.messages[idx].id == msgInfo.id) {
if (msgInfo.id && chat.messages[idx].id) {
if (msgInfo.id == chat.messages[idx].id) {
return chat.messages[idx];
}
// 如果id比要查询的消息小,说明没有这条消息
if (msgInfo.id > chat.messages[idx].id) {
break;
}
}
// 正在发送中的消息可能没有id,只有tmpId
if (msgInfo.tmpId && chat.messages[idx].tmpId &&
chat.messages[idx].tmpId == msgInfo.tmpId) {
if (msgInfo.tmpId && chat.messages[idx].tmpId) {
if (msgInfo.tmpId == chat.messages[idx].tmpId) {
return chat.messages[idx];
}
// 如果id比要查询的消息小,说明没有这条消息
if (msgInfo.id && msgInfo.id > chat.messages[idx].id) {
if (msgInfo.tmpId > chat.messages[idx].tmpId) {
break;
}
if (msgInfo.tmpId && msgInfo.tmpId > chat.messages[idx].tmpId) {
break;
}
}
}

1
im-web/src/view/Home.vue

@ -125,7 +125,6 @@ export default {
location.href = "/";
}
});
} else if (cmd == 3) {
if (!this.configStore.appInit || this.chatStore.loading) {
// 线

Loading…
Cancel
Save