feat(message): implement version-based incremental sync and WS compression
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:
@@ -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 });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user