Skip to content

Commit

Permalink
fix: fix message ack not trigger update problem
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Aug 12, 2023
1 parent 6081918 commit 7900a3e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions client/shared/redux/slices/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ const chatSlice = createSlice({

state.converses[converseId].messages = newMessages;

const lastMessageId = _last(
newMessages.filter((m) => !isLocalMessageId(m._id))
)?._id;

if (isValidStr(lastMessageId)) {
state.lastMessageMap[converseId] = lastMessageId;

if (state.currentConverseId === converseId) {
// 如果是当前会话,则立即已读
state.ack[converseId] = lastMessageId;
/**
* 如果在当前会话中,则暂时不更新最后收到的消息的本地状态,避免可能出现的瞬间更新最后消息(出现小红点) 但是会立即已读(小红点消失)
* 所以仅对非当前会话的消息进行更新最后消息
*/
if (state.currentConverseId !== converseId) {
const lastMessageId = _last(
newMessages.filter((m) => !isLocalMessageId(m._id))
)?._id;
if (isValidStr(lastMessageId)) {
state.lastMessageMap[converseId] = lastMessageId;
}
}
},
Expand Down

0 comments on commit 7900a3e

Please sign in to comment.