feat: add historical data
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user