feat(chat): implement sequence-based unread count tracking
Introduce a new mechanism for tracking read positions using message sequences (hasReadSeq), similar to OpenIM, to allow for O(1) unread count calculations. - Implement `UserReadSeq` caching in Redis with Lua scripts to prevent sequence regression (ensuring updates only occur if the new sequence is greater than the current one). - Update `ConversationCache` to support sequence-based unread count computation (`maxSeq - hasReadSeq`). - Refactor `MessageRepository` to use conditional updates for `last_read_seq` in the database. - Update `ChatService` to automatically update the sender's read sequence when sending a message. - Optimize `MarkAsRead` logic to update both database and Redis sequence caches and refine notification targets for private vs group chats. - Update `jpush` client to use pointer types for boolean fields to properly handle optional values in JSON.
This commit is contained in:
@@ -758,7 +758,7 @@ func (h *MessageHandler) HandleGetConversation(c *gin.Context) {
|
||||
// 获取参与者信息
|
||||
participants, _ := h.getConversationParticipants(c.Request.Context(), conversationID, userID)
|
||||
|
||||
// 获取当前用户的已读位置
|
||||
// 获取当前用户的已读位置(优先从 Redis 缓存读取)
|
||||
myLastReadSeq := int64(0)
|
||||
isPinned := false
|
||||
notificationMuted := false
|
||||
@@ -772,7 +772,7 @@ func (h *MessageHandler) HandleGetConversation(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取对方用户的已读位置
|
||||
// 获取对方用户的已读位置(优先从 Redis 缓存读取)
|
||||
otherLastReadSeq := int64(0)
|
||||
for _, p := range allParticipants {
|
||||
if p.UserID != userID {
|
||||
|
||||
Reference in New Issue
Block a user