From 88cf0abc96299aaf76d07d305f2dd02bf9f51999 Mon Sep 17 00:00:00 2001 From: Seven <1530011482@qq.com> Date: Tue, 29 Sep 2026 11:14:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84websocket=E7=9A=84ack?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/ChatPage.vue | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pages/index/ChatPage.vue b/src/pages/index/ChatPage.vue index 6ff8ec4..4096263 100644 --- a/src/pages/index/ChatPage.vue +++ b/src/pages/index/ChatPage.vue @@ -333,6 +333,7 @@ export default { // 获取最近消息列表 getRecentMessageList() { + if(!this.currentUser) return; getRecentMessages() .then((response) => { this.recentChats = response.data.recentChats || []; @@ -535,6 +536,12 @@ export default { const message = data.message; const senderName = message.senderName; + // 给发消息的人返回 ACK + sendWebSocketMessage({ + type: "ack", + messageId: message.messageId + }); + const currentContactName = this.currentContact && this.currentContact.contactName; @@ -546,16 +553,16 @@ export default { time: message.createdAt, }); } else { - // 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量 + // 不是当前联系人,不加入 contactMessages + // 如果是当前联系人列表中的成员,更新最近聊天列表、未读数量 + const contactIndex = this.contactList.findIndex( + (item) => item.contactName === senderName + ); + if(contactIndex === -1) return; + this.updateRecentChat("receive", senderName, message); } - // 返回 ACK - sendWebSocketMessage({ - type: "ack", - messageId: message.messageId, - senderName: this.currentUser.username - }); this.$nextTick(() => { this.scrollToBottom(); });