|
@@ -7,8 +7,7 @@ class Collection {
|
|
|
final String keyDecryptionNonce;
|
|
|
final String name;
|
|
|
final CollectionType type;
|
|
|
- final String encryptedPath;
|
|
|
- final String pathDecryptionNonce;
|
|
|
+ final CollectionAttributes attributes;
|
|
|
final int creationTime;
|
|
|
|
|
|
Collection(
|
|
@@ -18,11 +17,31 @@ class Collection {
|
|
|
this.keyDecryptionNonce,
|
|
|
this.name,
|
|
|
this.type,
|
|
|
- this.encryptedPath,
|
|
|
- this.pathDecryptionNonce,
|
|
|
+ this.attributes,
|
|
|
this.creationTime,
|
|
|
);
|
|
|
|
|
|
+ static CollectionType typeFromString(String type) {
|
|
|
+ switch (type) {
|
|
|
+ case "folder":
|
|
|
+ return CollectionType.folder;
|
|
|
+ case "favorites":
|
|
|
+ return CollectionType.favorites;
|
|
|
+ }
|
|
|
+ return CollectionType.album;
|
|
|
+ }
|
|
|
+
|
|
|
+ static String typeToString(CollectionType type) {
|
|
|
+ switch (type) {
|
|
|
+ case CollectionType.folder:
|
|
|
+ return "folder";
|
|
|
+ case CollectionType.favorites:
|
|
|
+ return "favorites";
|
|
|
+ default:
|
|
|
+ return "album";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Collection copyWith({
|
|
|
int id,
|
|
|
int ownerID,
|
|
@@ -30,10 +49,8 @@ class Collection {
|
|
|
String keyDecryptionNonce,
|
|
|
String name,
|
|
|
CollectionType type,
|
|
|
- String encryptedPath,
|
|
|
- String pathDecryptionNonce,
|
|
|
+ CollectionAttributes attributes,
|
|
|
int creationTime,
|
|
|
- List<String> sharees,
|
|
|
}) {
|
|
|
return Collection(
|
|
|
id ?? this.id,
|
|
@@ -42,8 +59,7 @@ class Collection {
|
|
|
keyDecryptionNonce ?? this.keyDecryptionNonce,
|
|
|
name ?? this.name,
|
|
|
type ?? this.type,
|
|
|
- encryptedPath ?? this.encryptedPath,
|
|
|
- encryptedPath ?? this.pathDecryptionNonce,
|
|
|
+ attributes ?? this.attributes,
|
|
|
creationTime ?? this.creationTime,
|
|
|
);
|
|
|
}
|
|
@@ -56,9 +72,8 @@ class Collection {
|
|
|
'keyDecryptionNonce': keyDecryptionNonce,
|
|
|
'name': name,
|
|
|
'type': typeToString(type),
|
|
|
+ 'attributes': attributes?.toMap(),
|
|
|
'creationTime': creationTime,
|
|
|
- 'encryptedPath': encryptedPath,
|
|
|
- 'pathDecryptionNonce': pathDecryptionNonce,
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -72,8 +87,7 @@ class Collection {
|
|
|
map['keyDecryptionNonce'],
|
|
|
map['name'],
|
|
|
typeFromString(map['type']),
|
|
|
- map['encryptedPath'],
|
|
|
- map['pathDecryptionNonce'],
|
|
|
+ CollectionAttributes.fromMap(map['attributes']),
|
|
|
map['creationTime'],
|
|
|
);
|
|
|
}
|
|
@@ -85,7 +99,7 @@ class Collection {
|
|
|
|
|
|
@override
|
|
|
String toString() {
|
|
|
- return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce, creationTime: $creationTime)';
|
|
|
+ return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, attributes: $attributes, creationTime: $creationTime)';
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -99,8 +113,7 @@ class Collection {
|
|
|
o.keyDecryptionNonce == keyDecryptionNonce &&
|
|
|
o.name == name &&
|
|
|
o.type == type &&
|
|
|
- o.encryptedPath == encryptedPath &&
|
|
|
- o.pathDecryptionNonce == pathDecryptionNonce &&
|
|
|
+ o.attributes == attributes &&
|
|
|
o.creationTime == creationTime;
|
|
|
}
|
|
|
|
|
@@ -112,31 +125,9 @@ class Collection {
|
|
|
keyDecryptionNonce.hashCode ^
|
|
|
name.hashCode ^
|
|
|
type.hashCode ^
|
|
|
- encryptedPath.hashCode ^
|
|
|
- pathDecryptionNonce.hashCode ^
|
|
|
+ attributes.hashCode ^
|
|
|
creationTime.hashCode;
|
|
|
}
|
|
|
-
|
|
|
- static CollectionType typeFromString(String type) {
|
|
|
- switch (type) {
|
|
|
- case "folder":
|
|
|
- return CollectionType.folder;
|
|
|
- case "favorites":
|
|
|
- return CollectionType.favorites;
|
|
|
- }
|
|
|
- return CollectionType.album;
|
|
|
- }
|
|
|
-
|
|
|
- static String typeToString(CollectionType type) {
|
|
|
- switch (type) {
|
|
|
- case CollectionType.folder:
|
|
|
- return "folder";
|
|
|
- case CollectionType.favorites:
|
|
|
- return "favorites";
|
|
|
- default:
|
|
|
- return "album";
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
enum CollectionType {
|
|
@@ -144,3 +135,64 @@ enum CollectionType {
|
|
|
favorites,
|
|
|
album,
|
|
|
}
|
|
|
+
|
|
|
+class CollectionAttributes {
|
|
|
+ final String encryptedPath;
|
|
|
+ final String pathDecryptionNonce;
|
|
|
+
|
|
|
+ CollectionAttributes({
|
|
|
+ this.encryptedPath,
|
|
|
+ this.pathDecryptionNonce,
|
|
|
+ });
|
|
|
+
|
|
|
+ CollectionAttributes copyWith({
|
|
|
+ String encryptedPath,
|
|
|
+ String pathDecryptionNonce,
|
|
|
+ }) {
|
|
|
+ return CollectionAttributes(
|
|
|
+ encryptedPath: encryptedPath ?? this.encryptedPath,
|
|
|
+ pathDecryptionNonce: pathDecryptionNonce ?? this.pathDecryptionNonce,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, dynamic> toMap() {
|
|
|
+ final map = Map<String, dynamic>();
|
|
|
+ if (encryptedPath != null) {
|
|
|
+ map['encryptedPath'] = encryptedPath;
|
|
|
+ }
|
|
|
+ if (pathDecryptionNonce != null) {
|
|
|
+ map['pathDecryptionNonce'] = pathDecryptionNonce;
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ factory CollectionAttributes.fromMap(Map<String, dynamic> map) {
|
|
|
+ if (map == null) return null;
|
|
|
+
|
|
|
+ return CollectionAttributes(
|
|
|
+ encryptedPath: map['encryptedPath'],
|
|
|
+ pathDecryptionNonce: map['pathDecryptionNonce'],
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ String toJson() => json.encode(toMap());
|
|
|
+
|
|
|
+ factory CollectionAttributes.fromJson(String source) =>
|
|
|
+ CollectionAttributes.fromMap(json.decode(source));
|
|
|
+
|
|
|
+ @override
|
|
|
+ String toString() =>
|
|
|
+ 'CollectionAttributes(encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce)';
|
|
|
+
|
|
|
+ @override
|
|
|
+ bool operator ==(Object o) {
|
|
|
+ if (identical(this, o)) return true;
|
|
|
+
|
|
|
+ return o is CollectionAttributes &&
|
|
|
+ o.encryptedPath == encryptedPath &&
|
|
|
+ o.pathDecryptionNonce == pathDecryptionNonce;
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ int get hashCode => encryptedPath.hashCode ^ pathDecryptionNonce.hashCode;
|
|
|
+}
|