Skip to content

Commit

Permalink
persist pending remote sync actions until there are sent to the server (
Browse files Browse the repository at this point in the history
  • Loading branch information
casimir authored Mar 19, 2024
1 parent 7d2ad3d commit 77b97f2
Show file tree
Hide file tree
Showing 6 changed files with 1,033 additions and 14 deletions.
8 changes: 7 additions & 1 deletion lib/models/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../constants.dart';
import 'app_log.dart';
import 'article.dart';
import 'article_scroll_position.dart';
import 'remote_action.dart';

typedef DBInstance = Isar;

Expand All @@ -18,7 +19,12 @@ class DB {

final dir = await getApplicationDocumentsDirectory();
_instance = await Isar.open(
[AppLogSchema, ArticleSchema, ArticleScrollPositionSchema],
[
AppLogSchema,
ArticleSchema,
ArticleScrollPositionSchema,
RemoteActionSchema,
],
directory: dir.path,
name: 'frigoligo${devmode ? '-dev' : ''}',
);
Expand Down
31 changes: 31 additions & 0 deletions lib/models/remote_action.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:convert';

import 'package:isar/isar.dart';

import '../services/remote_sync_actions/base.dart';

part 'remote_action.g.dart';

@collection
class RemoteAction {
RemoteAction();

Id? id;
DateTime? createdAt;
int? key;
String? className;
String? jsonParams;

factory RemoteAction.fromRSA(RemoteSyncAction action) {
return RemoteAction()
..key = action.hashCode
..createdAt = DateTime.now()
..className = action.runtimeType.toString()
..jsonParams = jsonEncode(action.params());
}

RemoteSyncAction toRSA() {
final json = jsonDecode(jsonParams!);
return RemoteSyncAction.fromParams(className!, json);
}
}
Loading

0 comments on commit 77b97f2

Please sign in to comment.