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

@@ -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