fix(im): 修复点击未读会话后重新登录未读回潮
点击会话时,消息列表可能尚未加载完成,导致已读上报只能从空列表算出 messageId = 0,并跳过服务端已读接口。此时本地未读已清零,但服务端读位置未推进,重新登录后会按服务端状态恢复未读。 已读上报时改为取已加载消息最大编号和会话末条服务端消息编号的较大值,确保消息列表尚未加载时也能使用 lastMessageId 推进服务端读位置。pull/884/MERGE
parent
4879c4705f
commit
cb625d11bb
|
|
@ -222,7 +222,7 @@ export const useMessageSender = () => {
|
||||||
/**
|
/**
|
||||||
* 触发当前会话的已读上报(切会话 / 进入页面时调用)
|
* 触发当前会话的已读上报(切会话 / 进入页面时调用)
|
||||||
* 1. 本端立刻清未读数;服务端回包成功后再做持久化
|
* 1. 本端立刻清未读数;服务端回包成功后再做持久化
|
||||||
* 2. 已读位置取会话内最大真实消息 id(本地发送中消息跳过)
|
* 2. 已读位置取已加载消息和会话末条消息的最大服务端 id
|
||||||
*/
|
*/
|
||||||
const readActive = async () => {
|
const readActive = async () => {
|
||||||
const conversation = conversationStore.activeConversation
|
const conversation = conversationStore.activeConversation
|
||||||
|
|
@ -231,13 +231,14 @@ export const useMessageSender = () => {
|
||||||
}
|
}
|
||||||
// 本地标记已读:未读数清零(UI 立刻响应)
|
// 本地标记已读:未读数清零(UI 立刻响应)
|
||||||
conversationStore.markConversationRead(conversation.type, conversation.targetId)
|
conversationStore.markConversationRead(conversation.type, conversation.targetId)
|
||||||
const maxMessageId = messageStore
|
const loadedMaxMessageId = messageStore
|
||||||
.getMessages(getClientConversationId(conversation.type, conversation.targetId))
|
.getMessages(getClientConversationId(conversation.type, conversation.targetId))
|
||||||
.reduce<number>(
|
.reduce<number>(
|
||||||
(maxMessageId, message) =>
|
(maxMessageId, message) =>
|
||||||
message.id && message.id > maxMessageId ? message.id : maxMessageId,
|
message.id && message.id > maxMessageId ? message.id : maxMessageId,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
const maxMessageId = Math.max(loadedMaxMessageId, conversation.lastMessageId || 0)
|
||||||
if (!maxMessageId) {
|
if (!maxMessageId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue