Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Persist sharedAt on collections in model and DB

ashilknf750c43253c8
diff --git a/mobile/apps/photos/lib/db/collections_db.dart b/mobile/apps/photos/lib/db/collections_db.dart
index 3bfafecc82..0608043121 100644
--- a/mobile/apps/photos/lib/db/collections_db.dart
+++ b/mobile/apps/photos/lib/db/collections_db.dart
@@ -40,6 +40,7 @@ class CollectionsDB {
static const columnSharedMMdVersion = 'shared_mmd_ver';
static const columnUpdationTime = 'updation_time';
+ static const columnSharedAt = 'shared_at';
static const columnIsDeleted = 'is_deleted';
static final intitialScript = [...createTable(table)];
@@ -52,6 +53,7 @@ class CollectionsDB {
...addPrivateMetadata(),
...addPublicMetadata(),
...addShareeMetadata(),
+ ...addSharedAt(),
];
final dbConfig = MigrationConfig(
@@ -191,6 +193,14 @@ class CollectionsDB {
];
}
+ static List<String> addSharedAt() {
+ return [
+ '''
+ ALTER TABLE $table ADD COLUMN $columnSharedAt INTEGER;
+ ''',
+ ];
+ }
+
Future<void> insert(List<Collection> collections) async {
final db = await instance.database;
var batch = db.batch();
@@ -267,6 +277,7 @@ class CollectionsDB {
row[columnPublicURLs] =
json.encode(collection.publicURLs.map((x) => x.toMap()).toList());
row[columnUpdationTime] = collection.updationTime;
+ row[columnSharedAt] = collection.sharedAt;
if (collection.isDeleted) {
row[columnIsDeleted] = _sqlBoolTrue;
} else {
@@ -307,6 +318,7 @@ class CollectionsDB {
.map((x) => PublicURL.fromMap(x)),
),
int.parse(row[columnUpdationTime]),
+ sharedAt: _parseNullableInt(row[columnSharedAt]),
// default to False is columnIsDeleted is not set
isDeleted: (row[columnIsDeleted] ?? _sqlBoolFalse) == _sqlBoolTrue,
);
@@ -319,4 +331,17 @@ class CollectionsDB {
result.sharedMmdJson = row[columnSharedMMdJson] ?? '{}';
return result;
}
+
+ int? _parseNullableInt(dynamic value) {
+ if (value == null) {
+ return null;
+ }
+ if (value is int) {
+ return value;
+ }
+ if (value is String) {
+ return int.tryParse(value);
+ }
+ return null;
+ }
}
diff --git a/mobile/apps/photos/lib/models/collection/collection.dart b/mobile/apps/photos/lib/models/collection/collection.dart
index a9f6438c6c..66b4f47ddc 100644
--- a/mobile/apps/photos/lib/models/collection/collection.dart
+++ b/mobile/apps/photos/lib/models/collection/collection.dart
@@ -26,6 +26,7 @@ class Collection {
final List<User> sharees;
final List<PublicURL> publicURLs;
final int updationTime;
+ final int? sharedAt;
final bool isDeleted;
// In early days before public launch, we used to store collection name
@@ -93,6 +94,7 @@ class Collection {
this.sharees,
this.publicURLs,
this.updationTime, {
+ this.sharedAt,
this.isDeleted = false,
});
@@ -242,6 +244,7 @@ class Collection {
List<User>? sharees,
List<PublicURL>? publicURLs,
int? updationTime,
+ int? sharedAt,
bool? isDeleted,
String? mMdEncodedJson,
int? mMdVersion,
@@ -262,6 +265,7 @@ class Collection {
sharees ?? this.sharees,
publicURLs ?? this.publicURLs,
updationTime ?? this.updationTime,
+ sharedAt: sharedAt ?? this.sharedAt,
isDeleted: isDeleted ?? this.isDeleted,
);
result.mMdVersion = mMdVersion ?? this.mMdVersion;
@@ -299,9 +303,23 @@ class Collection {
sharees,
publicURLs,
map['updationTime'],
+ sharedAt: _parseNullableInt(map['sharedAt'] ?? map['shared_at']),
isDeleted: map['isDeleted'] ?? false,
);
}
+
+ static int? _parseNullableInt(dynamic value) {
+ if (value == null) {
+ return null;
+ }
+ if (value is int) {
+ return value;
+ }
+ if (value is String) {
+ return int.tryParse(value);
+ }
+ return null;
+ }
}
enum CollectionType {