zhixi-document-runtime/docs/reading-event-v2-api-mapping.md
wangdl b22df85891 feat: DOC-FULL Batch 1 FFI + Compat
#56 FFI DTO V2 exports (done in A1)
#83 V1 deprecated annotations
#84 V2→API protocol mapping doc

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-07 20:26:05 +08:00

51 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ReadingEvent V2 → API 上传协议映射
## 字段映射
| Rust ReadingEventV2 | API ReadingEventUploadItem | 来源 |
|---------------------|---------------------------|------|
| event_id | eventId | Rust 生成 UUID |
| client_session_id | clientSessionId | Rust 生成 UUIDstart_reading_session_v2 |
| material_id | materialId | Rust 保存iOS 传入 |
| event_type | eventType | Rust→iOS 转 snake_case |
| position | position | RustcamelCase JSONclamped |
| active_seconds_delta | activeSecondsDelta | Rust ActiveTimeTracker 计算 |
| timestamp_ms | clientTimestampMs | Rust |
| sequence | sequence | Rustsession 内递增) |
| — | readingTargetType | **iOS 补充** |
| — | platform | **iOS 补充**= "ios" |
| — | appVersion | **iOS 补充** |
| — | clientTimezoneOffsetMinutes | **iOS 补充** |
## iOS 上传适配流程
```
1. Rust export_pending_events_v2(limit, ts)
2. iOS 获得 Vec<ReadingEventV2>
3. iOS 遍历每个 event补充 readingTargetType/platform/appVersion/timezone
4. iOS 写入本地上传队列
5. 成功后调用 Rust ack_events_v2(eventIds)
6. 失败后调用 Rust mark_events_failed_v2(eventIds)
7. App 启动时调用 reload_stale_events_v2() 恢复未 ack 的事件
```
## eventType 映射
| Rust | API |
|------|-----|
| MaterialOpened | material_opened |
| MaterialClosed | material_closed |
| PositionChanged | position_changed |
| Heartbeat | heartbeat |
| MarkedAsRead | marked_as_read |
## delta 规则
| 事件 | delta |
|------|-------|
| MaterialOpened | 0 |
| PositionChanged | 0 |
| MarkedAsRead | 0 |
| Heartbeat | tracker.tick() 返回值 |
| MaterialClosed | tracker.close() 返回值 |