Ver código fonte

fix: 查询消息的bug

xsx 7 meses atrás
pai
commit
dbaee8baf1

+ 17 - 16
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) {
-					return chat.messages[idx];
+				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) {
-					return chat.messages[idx];
-				}
-				// 如果id比要查询的消息小,说明没有这条消息
-				if (msgInfo.id && msgInfo.id > chat.messages[idx].id) {
-					break;
-				}
-				if (msgInfo.tmpId && msgInfo.tmpId > chat.messages[idx].tmpId) {
-					break;
+				if (msgInfo.tmpId && chat.messages[idx].tmpId) {
+					if (msgInfo.tmpId == chat.messages[idx].tmpId) {
+						return chat.messages[idx];
+					}
+					// 如果id比要查询的消息小,说明没有这条消息
+					if (msgInfo.tmpId > chat.messages[idx].tmpId) {
+						break;
+					}
 				}
 			}
 			return null;

+ 1 - 1
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;
 				}

+ 16 - 15
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) {
-					return chat.messages[idx];
+				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) {
-					return chat.messages[idx];
-				}
-				// 如果id比要查询的消息小,说明没有这条消息
-				if (msgInfo.id && msgInfo.id > chat.messages[idx].id) {
-					break;
-				}
-				if (msgInfo.tmpId && msgInfo.tmpId > chat.messages[idx].tmpId) {
-					break;
+				if (msgInfo.tmpId && chat.messages[idx].tmpId) {
+					if (msgInfo.tmpId == chat.messages[idx].tmpId) {
+						return chat.messages[idx];
+					}
+					// 如果id比要查询的消息小,说明没有这条消息
+					if (msgInfo.tmpId > chat.messages[idx].tmpId) {
+						break;
+					}
 				}
 			}
 		}

+ 0 - 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) {
 							// 如果正在拉取离线消息,先放进缓存区,等待消息拉取完成再处理,防止消息乱序