feat(message): implement version-based incremental sync and WS compression
Some checks failed
Frontend CI / ota-android (push) Successful in 1m58s
Frontend CI / ota-ios (push) Successful in 2m2s
Frontend CI / build-android-apk (push) Failing after 3m22s
Frontend CI / build-and-push-web (push) Successful in 4m19s

Implement a more efficient conversation synchronization mechanism using
version numbers instead of sequence numbers to reduce bandwidth usage.
This includes adding support for Gzip decompression on WebSocket
messages to optimize data transfer.

- Add `pako` for WebSocket message decompression
- Implement `getSyncByVersion` in `MessageService`
- Implement `syncByVersion` in `MessageSyncService` to handle incremental
  updates and conversation state changes
- Update `WebSocketService` to support binary frames and Gzip inflation
- Add `syncVersion` to `MessageStore` for tracking synchronization state
This commit is contained in:
2026-05-17 23:37:38 +08:00
parent 404b3fabe7
commit fb67fb6d5b
6 changed files with 132 additions and 4 deletions

View File

@@ -53,6 +53,9 @@ export interface MessageState {
// 会话免打扰状态 - 按会话ID存储
notificationMutedMap: Map<string, boolean>;
// 版本日志同步游标
syncVersion: number | null;
}
// ==================== Actions 接口 ====================
@@ -90,6 +93,7 @@ export interface MessageActions {
setTypingUsers: (groupId: string, users: string[]) => void;
setMutedStatus: (groupId: string, isMuted: boolean) => void;
setNotificationMuted: (conversationId: string, notificationMuted: boolean) => void;
setSyncVersion: (version: number) => void;
setInitialized: (initialized: boolean) => void;
// 原子性更新(避免中间渲染状态)
@@ -121,6 +125,7 @@ const initialState: MessageState = {
typingUsersMap: new Map(),
mutedStatusMap: new Map(),
notificationMutedMap: new Map(),
syncVersion: null,
};
// ==================== 工具函数 ====================
@@ -189,6 +194,7 @@ export const useMessageStore = create<MessageStore>((set, get) => ({
typingUsersMap: state.typingUsersMap,
mutedStatusMap: state.mutedStatusMap,
notificationMutedMap: state.notificationMutedMap,
syncVersion: state.syncVersion,
};
},
@@ -387,6 +393,10 @@ export const useMessageStore = create<MessageStore>((set, get) => ({
});
},
setSyncVersion: (version: number) => {
set({ syncVersion: version });
},
setInitialized: (initialized: boolean) => {
set({ isInitialized: initialized });
},