feat: add historical data

This commit is contained in:
2026-10-19 23:31:54 +02:00
parent b0074aeb3f
commit 5754ae742d
10 changed files with 1211 additions and 4 deletions
+32
View File
@@ -59,15 +59,34 @@ class RemoteCommand {
}
}
/// A tab event the server refused to store. Re-sending won't help.
class RejectedEvent {
final String? id;
final String reason;
const RejectedEvent({this.id, required this.reason});
factory RejectedEvent.fromJson(Map<String, dynamic> json) {
return RejectedEvent(
id: json['id'] as String?,
reason: json['reason'] as String? ?? '',
);
}
}
class SyncResponse {
final List<RemoteCommand> commands;
final String? cursor;
final List<String> plannedTabNames;
final List<String> acknowledgedEventIds;
final List<RejectedEvent> rejectedEvents;
const SyncResponse({
required this.commands,
this.cursor,
this.plannedTabNames = const [],
this.acknowledgedEventIds = const [],
this.rejectedEvents = const [],
});
factory SyncResponse.fromJson(Map<String, dynamic> json) {
@@ -81,6 +100,14 @@ class SyncResponse {
for (final name in json['plannedTabNames'] as List<dynamic>? ?? [])
name as String,
],
acknowledgedEventIds: [
for (final id in json['acknowledgedEventIds'] as List<dynamic>? ?? [])
id as String,
],
rejectedEvents: [
for (final event in json['rejectedEvents'] as List<dynamic>? ?? [])
RejectedEvent.fromJson(event as Map<String, dynamic>),
],
);
}
}
@@ -136,16 +163,21 @@ class SyncRequest {
final String? cursor;
final List<SnapshotTab> openTabs;
/// Outbox tab events, oldest first, as their stored JSON objects.
final List<Map<String, dynamic>> events;
const SyncRequest({
required this.deviceId,
this.cursor,
required this.openTabs,
this.events = const [],
});
Map<String, dynamic> toJson() => {
'deviceId': deviceId,
if (cursor != null) 'cursor': cursor,
'openTabs': openTabs.map((tab) => tab.toJson()).toList(),
'events': events,
};
}