feat(chat): implement batch mark-as-read and message sync data
All checks were successful
Build Backend / build (push) Successful in 2m2s
Build Backend / build-docker (push) Successful in 1m41s

Refactor unread count logic to use arithmetic calculation (maxSeq - readSeq)
instead of manual incrementing/decrementing. This simplifies the cache
management and improves consistency.

New features:
- Batch mark-as-read functionality for multiple conversations.
- Lightweight sync data endpoint to retrieve conversation metadata
  (maxSeq and last message timestamp) for client synchronization.
- Optimized batch retrieval of conversation max sequences using Redis MGet.

Technical changes:
- Deprecated `IncrementUnread` and `ClearUnread` in `ConversationCache`.
- Added `GetConvMaxSeqBatch` to reduce network round-trips.
- Added `HandleMarkReadAll` and `HandleGetSyncData` handlers.
- Updated `ChatService` to support batch operations and sync data retrieval.
This commit is contained in:
2026-05-12 18:04:59 +08:00
parent 2f2bbc646e
commit 8d7e8c427b
5 changed files with 236 additions and 175 deletions

View File

@@ -437,6 +437,23 @@ type MarkReadRequest struct {
LastReadSeq int64 `json:"last_read_seq" binding:"required"` // 已读到的seq位置
}
// BatchMarkReadItem 批量标记已读单项
type BatchMarkReadItem struct {
ConversationID string `json:"conversation_id" binding:"required"`
LastReadSeq int64 `json:"last_read_seq" binding:"required"`
}
// BatchMarkReadRequest 批量标记已读请求
type BatchMarkReadRequest struct {
Conversations []BatchMarkReadItem `json:"conversations" binding:"required"`
}
// BatchMarkReadResponse 批量标记已读响应
type BatchMarkReadResponse struct {
SuccessCount int `json:"success_count"`
TotalCount int `json:"total_count"`
}
// SetConversationPinnedRequest 设置会话置顶请求
type SetConversationPinnedRequest struct {
ConversationID string `json:"conversation_id" binding:"required"`
@@ -481,6 +498,18 @@ type ConversationUnreadCountResponse struct {
UnreadCount int64 `json:"unread_count"`
}
// SyncDataItem 同步数据单项(轻量级,仅包含 seq 和时间)
type SyncDataItem struct {
ConversationID string `json:"id"`
MaxSeq int64 `json:"max_seq"`
LastMessageAt string `json:"last_message_at"`
}
// SyncDataResponse 同步数据响应
type SyncDataResponse struct {
Conversations []SyncDataItem `json:"conversations"`
}
// MessageListResponse 消息列表响应
type MessageListResponse struct {
Messages []*MessageResponse `json:"messages"`