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:
@@ -476,6 +476,37 @@ class MessageService {
|
||||
return response.data?.conversations || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量同步(基于版本号)
|
||||
* GET /api/v1/conversations/sync?version=N&limit=100
|
||||
*/
|
||||
async getSyncByVersion(version: number, limit: number = 100): Promise<{
|
||||
current_version: number;
|
||||
changes: Array<{
|
||||
conversation_id: string;
|
||||
change_type: string;
|
||||
max_seq?: number;
|
||||
last_message_at?: number;
|
||||
version: number;
|
||||
}>;
|
||||
full_sync: boolean;
|
||||
has_more: boolean;
|
||||
}> {
|
||||
const response = await api.get<{
|
||||
current_version: number;
|
||||
changes: Array<{
|
||||
conversation_id: string;
|
||||
change_type: string;
|
||||
max_seq?: number;
|
||||
last_message_at?: number;
|
||||
version: number;
|
||||
}>;
|
||||
full_sync: boolean;
|
||||
has_more: boolean;
|
||||
}>('/conversations/sync', { version, limit });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统消息未读数
|
||||
* GET /api/v1/messages/system/unread-count
|
||||
|
||||
Reference in New Issue
Block a user