|
|
@@ -1028,47 +1028,36 @@ export default {
|
|
|
|
|
|
// event.data 包含已读的消息列表
|
|
|
if (event.data && Array.isArray(event.data)) {
|
|
|
- for (const item of event.data) {
|
|
|
- console.log(' - 处理会话:', item.conversationID, '当前会话:', this.conversationID);
|
|
|
+ let updatedCount = 0;
|
|
|
+
|
|
|
+ // 🔥 直接使用事件数据中的消息对象(它们已经带有 isPeerRead: true)
|
|
|
+ event.data.forEach(readMessage => {
|
|
|
+ console.log(' - 处理消息:', readMessage.ID, '会话:', readMessage.conversationID);
|
|
|
|
|
|
// 只处理当前会话的消息
|
|
|
- if (item.conversationID === this.conversationID) {
|
|
|
- console.log('✅ 对方已阅读当前会话的消息');
|
|
|
+ if (readMessage.conversationID === this.conversationID) {
|
|
|
+ // 在本地消息列表中查找对应的消息
|
|
|
+ const localMsgIndex = this.messages.findIndex(msg => msg.messageId === readMessage.ID);
|
|
|
|
|
|
- // 🔥 关键修复:使用 peerReadTime 精确判断哪些消息被读了
|
|
|
- try {
|
|
|
- const conversationRes = await timManager.tim.getConversationProfile(this.conversationID);
|
|
|
+ if (localMsgIndex > -1) {
|
|
|
+ const localMsg = this.messages[localMsgIndex];
|
|
|
|
|
|
- if (conversationRes && conversationRes.data && conversationRes.data.conversation) {
|
|
|
- const peerReadTime = conversationRes.data.conversation.peerReadTime;
|
|
|
- console.log(' - 对方最后阅读时间:', peerReadTime, new Date(peerReadTime * 1000).toLocaleString());
|
|
|
-
|
|
|
- if (peerReadTime && peerReadTime > 0) {
|
|
|
- let updatedCount = 0;
|
|
|
-
|
|
|
- // 只更新发送时间 <= peerReadTime 的消息
|
|
|
- this.messages.forEach((msg, index) => {
|
|
|
- if (msg.fromUserId === this.userId && !msg.isPeerRead && msg.sendStatus !== 4) {
|
|
|
- const msgTime = Math.floor(msg.sendTime.getTime() / 1000);
|
|
|
-
|
|
|
- // 只有消息发送时间 <= 对方阅读时间,才标记为已读
|
|
|
- if (msgTime <= peerReadTime) {
|
|
|
- this.$set(this.messages[index], 'isPeerRead', true);
|
|
|
- updatedCount++;
|
|
|
- console.log(` - 消息 ${msg.messageId} 已标记为已读 (发送时间: ${new Date(msgTime * 1000).toLocaleString()})`);
|
|
|
- } else {
|
|
|
- console.log(` - 消息 ${msg.messageId} 保持未读 (发送时间: ${new Date(msgTime * 1000).toLocaleString()} > 阅读时间)`);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- console.log(`✅ 共更新 ${updatedCount} 条消息为已读状态`);
|
|
|
- }
|
|
|
+ // 只更新自己发送的未读消息
|
|
|
+ if (localMsg.fromUserId === this.userId && !localMsg.isPeerRead) {
|
|
|
+ this.$set(this.messages[localMsgIndex], 'isPeerRead', true);
|
|
|
+ updatedCount++;
|
|
|
+ console.log(` - ✅ 消息 ${readMessage.ID} 已标记为已读`);
|
|
|
}
|
|
|
- } catch (error) {
|
|
|
- console.error('❌ 获取会话 peerReadTime 失败:', error);
|
|
|
+ } else {
|
|
|
+ console.log(` - ⚠️ 本地未找到消息 ${readMessage.ID}`);
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
+
|
|
|
+ if (updatedCount > 0) {
|
|
|
+ console.log(`✅ 共更新 ${updatedCount} 条消息为已读状态`);
|
|
|
+ } else {
|
|
|
+ console.log('⚠️ 没有消息需要更新');
|
|
|
}
|
|
|
}
|
|
|
};
|