feat(chat): implement sequence-based unread count tracking
All checks were successful
Build Backend / build (push) Successful in 1m56s
Build Backend / build-docker (push) Successful in 1m9s

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:
2026-05-10 13:36:58 +08:00
parent 43348615c0
commit 628a6acbe9
6 changed files with 315 additions and 23 deletions

View File

@@ -93,8 +93,8 @@ type IOSNotif struct {
Alert any `json:"alert,omitempty"`
Sound any `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
MutableContent bool `json:"mutable-content,omitempty"`
ContentAvailable bool `json:"content-available,omitempty"`
MutableContent *bool `json:"mutable-content,omitempty"`
ContentAvailable *bool `json:"content-available,omitempty"`
Category string `json:"category,omitempty"`
ThreadID string `json:"thread-id,omitempty"`
Extras map[string]any `json:"extras,omitempty"`