完善websocket的ack消息确认

This commit is contained in:
2026-09-29 11:14:47 +08:00
parent d84048d60a
commit 88cf0abc96
+14 -7
View File
@@ -333,6 +333,7 @@ export default {
// 获取最近消息列表 // 获取最近消息列表
getRecentMessageList() { getRecentMessageList() {
if(!this.currentUser) return;
getRecentMessages() getRecentMessages()
.then((response) => { .then((response) => {
this.recentChats = response.data.recentChats || []; this.recentChats = response.data.recentChats || [];
@@ -535,6 +536,12 @@ export default {
const message = data.message; const message = data.message;
const senderName = message.senderName; const senderName = message.senderName;
// 给发消息的人返回 ACK
sendWebSocketMessage({
type: "ack",
messageId: message.messageId
});
const currentContactName = const currentContactName =
this.currentContact && this.currentContact.contactName; this.currentContact && this.currentContact.contactName;
@@ -546,16 +553,16 @@ export default {
time: message.createdAt, time: message.createdAt,
}); });
} else { } else {
// 不是当前联系人,不加入 contactMessages,只更新最近聊天列表、未读数量 // 不是当前联系人,不加入 contactMessages
// 如果是当前联系人列表中的成员,更新最近聊天列表、未读数量
const contactIndex = this.contactList.findIndex(
(item) => item.contactName === senderName
);
if(contactIndex === -1) return;
this.updateRecentChat("receive", senderName, message); this.updateRecentChat("receive", senderName, message);
} }
// 返回 ACK
sendWebSocketMessage({
type: "ack",
messageId: message.messageId,
senderName: this.currentUser.username
});
this.$nextTick(() => { this.$nextTick(() => {
this.scrollToBottom(); this.scrollToBottom();
}); });