|
@@ -1,28 +1,25 @@
|
|
-// @dart=2.9
|
|
|
|
-
|
|
|
|
import 'dart:convert';
|
|
import 'dart:convert';
|
|
import 'dart:core';
|
|
import 'dart:core';
|
|
|
|
|
|
-import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:photos/models/magic_metadata.dart';
|
|
import 'package:photos/models/magic_metadata.dart';
|
|
|
|
|
|
class Collection {
|
|
class Collection {
|
|
final int id;
|
|
final int id;
|
|
- final User owner;
|
|
|
|
|
|
+ final User? owner;
|
|
final String encryptedKey;
|
|
final String encryptedKey;
|
|
- final String keyDecryptionNonce;
|
|
|
|
- final String name;
|
|
|
|
|
|
+ final String? keyDecryptionNonce;
|
|
|
|
+ final String? name;
|
|
final String encryptedName;
|
|
final String encryptedName;
|
|
final String nameDecryptionNonce;
|
|
final String nameDecryptionNonce;
|
|
final CollectionType type;
|
|
final CollectionType type;
|
|
- final CollectionAttributes attributes;
|
|
|
|
- final List<User> sharees;
|
|
|
|
- final List<PublicURL> publicURLs;
|
|
|
|
|
|
+ final CollectionAttributes? attributes;
|
|
|
|
+ final List<User?>? sharees;
|
|
|
|
+ final List<PublicURL?>? publicURLs;
|
|
final int updationTime;
|
|
final int updationTime;
|
|
final bool isDeleted;
|
|
final bool isDeleted;
|
|
- String mMdEncodedJson;
|
|
|
|
|
|
+ String? mMdEncodedJson;
|
|
int mMdVersion = 0;
|
|
int mMdVersion = 0;
|
|
- CollectionMagicMetadata _mmd;
|
|
|
|
|
|
+ CollectionMagicMetadata? _mmd;
|
|
|
|
|
|
CollectionMagicMetadata get magicMetadata =>
|
|
CollectionMagicMetadata get magicMetadata =>
|
|
_mmd ?? CollectionMagicMetadata.fromEncodedJson(mMdEncodedJson ?? '{}');
|
|
_mmd ?? CollectionMagicMetadata.fromEncodedJson(mMdEncodedJson ?? '{}');
|
|
@@ -46,7 +43,7 @@ class Collection {
|
|
});
|
|
});
|
|
|
|
|
|
bool isArchived() {
|
|
bool isArchived() {
|
|
- return mMdVersion > 0 && magicMetadata.visibility == kVisibilityArchive;
|
|
|
|
|
|
+ return mMdVersion > 0 && magicMetadata.visibility == visibilityArchive;
|
|
}
|
|
}
|
|
|
|
|
|
static CollectionType typeFromString(String type) {
|
|
static CollectionType typeFromString(String type) {
|
|
@@ -71,21 +68,21 @@ class Collection {
|
|
}
|
|
}
|
|
|
|
|
|
Collection copyWith({
|
|
Collection copyWith({
|
|
- int id,
|
|
|
|
- User owner,
|
|
|
|
- String encryptedKey,
|
|
|
|
- String keyDecryptionNonce,
|
|
|
|
- String name,
|
|
|
|
- String encryptedName,
|
|
|
|
- String nameDecryptionNonce,
|
|
|
|
- CollectionType type,
|
|
|
|
- CollectionAttributes attributes,
|
|
|
|
- List<User> sharees,
|
|
|
|
- List<PublicURL> publicURLs,
|
|
|
|
- int updationTime,
|
|
|
|
- bool isDeleted,
|
|
|
|
- String mMdEncodedJson,
|
|
|
|
- int mMdVersion,
|
|
|
|
|
|
+ int? id,
|
|
|
|
+ User? owner,
|
|
|
|
+ String? encryptedKey,
|
|
|
|
+ String? keyDecryptionNonce,
|
|
|
|
+ String? name,
|
|
|
|
+ String? encryptedName,
|
|
|
|
+ String? nameDecryptionNonce,
|
|
|
|
+ CollectionType? type,
|
|
|
|
+ CollectionAttributes? attributes,
|
|
|
|
+ List<User>? sharees,
|
|
|
|
+ List<PublicURL>? publicURLs,
|
|
|
|
+ int? updationTime,
|
|
|
|
+ bool? isDeleted,
|
|
|
|
+ String? mMdEncodedJson,
|
|
|
|
+ int? mMdVersion,
|
|
}) {
|
|
}) {
|
|
final Collection result = Collection(
|
|
final Collection result = Collection(
|
|
id ?? this.id,
|
|
id ?? this.id,
|
|
@@ -118,15 +115,17 @@ class Collection {
|
|
'nameDecryptionNonce': nameDecryptionNonce,
|
|
'nameDecryptionNonce': nameDecryptionNonce,
|
|
'type': typeToString(type),
|
|
'type': typeToString(type),
|
|
'attributes': attributes?.toMap(),
|
|
'attributes': attributes?.toMap(),
|
|
- 'sharees': sharees?.map((x) => x?.toMap())?.toList(),
|
|
|
|
- 'publicURLs': publicURLs?.map((x) => x?.toMap())?.toList(),
|
|
|
|
|
|
+ 'sharees': sharees?.map((x) => x?.toMap()).toList(),
|
|
|
|
+ 'publicURLs': publicURLs?.map((x) => x?.toMap()).toList(),
|
|
'updationTime': updationTime,
|
|
'updationTime': updationTime,
|
|
'isDeleted': isDeleted,
|
|
'isDeleted': isDeleted,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- factory Collection.fromMap(Map<String, dynamic> map) {
|
|
|
|
- if (map == null) return null;
|
|
|
|
|
|
+ factory Collection.fromMap(Map<String, dynamic>? map) {
|
|
|
|
+ if (map == null) {
|
|
|
|
+ throw Exception('Argument is null');
|
|
|
|
+ }
|
|
final sharees = (map['sharees'] == null || map['sharees'].length == 0)
|
|
final sharees = (map['sharees'] == null || map['sharees'].length == 0)
|
|
? <User>[]
|
|
? <User>[]
|
|
: List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
|
|
: List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
|
|
@@ -152,53 +151,6 @@ class Collection {
|
|
isDeleted: map['isDeleted'] ?? false,
|
|
isDeleted: map['isDeleted'] ?? false,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
- String toJson() => json.encode(toMap());
|
|
|
|
-
|
|
|
|
- factory Collection.fromJson(String source) =>
|
|
|
|
- Collection.fromMap(json.decode(source));
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- String toString() {
|
|
|
|
- return 'Collection(id: $id, owner: $owner, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, encryptedName: $encryptedName, nameDecryptionNonce: $nameDecryptionNonce, type: $type, attributes: $attributes, sharees: $sharees, publicURLs: $publicURLs, updationTime: $updationTime, isDeleted: $isDeleted)';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- bool operator ==(Object o) {
|
|
|
|
- if (identical(this, o)) return true;
|
|
|
|
-
|
|
|
|
- return o is Collection &&
|
|
|
|
- o.id == id &&
|
|
|
|
- o.owner == owner &&
|
|
|
|
- o.encryptedKey == encryptedKey &&
|
|
|
|
- o.keyDecryptionNonce == keyDecryptionNonce &&
|
|
|
|
- o.name == name &&
|
|
|
|
- o.encryptedName == encryptedName &&
|
|
|
|
- o.nameDecryptionNonce == nameDecryptionNonce &&
|
|
|
|
- o.type == type &&
|
|
|
|
- o.attributes == attributes &&
|
|
|
|
- listEquals(o.sharees, sharees) &&
|
|
|
|
- listEquals(o.publicURLs, publicURLs) &&
|
|
|
|
- o.updationTime == updationTime &&
|
|
|
|
- o.isDeleted == isDeleted;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- int get hashCode {
|
|
|
|
- return id.hashCode ^
|
|
|
|
- owner.hashCode ^
|
|
|
|
- encryptedKey.hashCode ^
|
|
|
|
- keyDecryptionNonce.hashCode ^
|
|
|
|
- name.hashCode ^
|
|
|
|
- encryptedName.hashCode ^
|
|
|
|
- nameDecryptionNonce.hashCode ^
|
|
|
|
- type.hashCode ^
|
|
|
|
- attributes.hashCode ^
|
|
|
|
- sharees.hashCode ^
|
|
|
|
- publicURLs.hashCode ^
|
|
|
|
- updationTime.hashCode ^
|
|
|
|
- isDeleted.hashCode;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
enum CollectionType {
|
|
enum CollectionType {
|
|
@@ -208,9 +160,9 @@ enum CollectionType {
|
|
}
|
|
}
|
|
|
|
|
|
class CollectionAttributes {
|
|
class CollectionAttributes {
|
|
- final String encryptedPath;
|
|
|
|
- final String pathDecryptionNonce;
|
|
|
|
- final int version;
|
|
|
|
|
|
+ final String? encryptedPath;
|
|
|
|
+ final String? pathDecryptionNonce;
|
|
|
|
+ final int? version;
|
|
|
|
|
|
CollectionAttributes({
|
|
CollectionAttributes({
|
|
this.encryptedPath,
|
|
this.encryptedPath,
|
|
@@ -218,18 +170,6 @@ class CollectionAttributes {
|
|
this.version,
|
|
this.version,
|
|
});
|
|
});
|
|
|
|
|
|
- CollectionAttributes copyWith({
|
|
|
|
- String encryptedPath,
|
|
|
|
- String pathDecryptionNonce,
|
|
|
|
- int version,
|
|
|
|
- }) {
|
|
|
|
- return CollectionAttributes(
|
|
|
|
- encryptedPath: encryptedPath ?? this.encryptedPath,
|
|
|
|
- pathDecryptionNonce: pathDecryptionNonce ?? this.pathDecryptionNonce,
|
|
|
|
- version: version ?? this.version,
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
Map<String, dynamic> toMap() {
|
|
Map<String, dynamic> toMap() {
|
|
final map = <String, dynamic>{};
|
|
final map = <String, dynamic>{};
|
|
if (encryptedPath != null) {
|
|
if (encryptedPath != null) {
|
|
@@ -242,8 +182,10 @@ class CollectionAttributes {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
- factory CollectionAttributes.fromMap(Map<String, dynamic> map) {
|
|
|
|
- if (map == null) return null;
|
|
|
|
|
|
+ factory CollectionAttributes.fromMap(Map<String, dynamic>? map) {
|
|
|
|
+ if (map == null) {
|
|
|
|
+ throw Exception('Argument is null');
|
|
|
|
+ }
|
|
|
|
|
|
return CollectionAttributes(
|
|
return CollectionAttributes(
|
|
encryptedPath: map['encryptedPath'],
|
|
encryptedPath: map['encryptedPath'],
|
|
@@ -251,54 +193,19 @@ class CollectionAttributes {
|
|
version: map['version'] ?? 0,
|
|
version: map['version'] ?? 0,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
- String toJson() => json.encode(toMap());
|
|
|
|
-
|
|
|
|
- factory CollectionAttributes.fromJson(String source) =>
|
|
|
|
- CollectionAttributes.fromMap(json.decode(source));
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- String toString() =>
|
|
|
|
- 'CollectionAttributes(encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce, version: $version)';
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- bool operator ==(Object o) {
|
|
|
|
- if (identical(this, o)) return true;
|
|
|
|
-
|
|
|
|
- return o is CollectionAttributes &&
|
|
|
|
- o.encryptedPath == encryptedPath &&
|
|
|
|
- o.pathDecryptionNonce == pathDecryptionNonce &&
|
|
|
|
- o.version == version;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- int get hashCode =>
|
|
|
|
- encryptedPath.hashCode ^ pathDecryptionNonce.hashCode ^ version.hashCode;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
class User {
|
|
class User {
|
|
- int id;
|
|
|
|
|
|
+ int? id;
|
|
String email;
|
|
String email;
|
|
- String name;
|
|
|
|
|
|
+ String? name;
|
|
|
|
|
|
User({
|
|
User({
|
|
this.id,
|
|
this.id,
|
|
- this.email,
|
|
|
|
|
|
+ required this.email,
|
|
this.name,
|
|
this.name,
|
|
});
|
|
});
|
|
|
|
|
|
- User copyWith({
|
|
|
|
- int id,
|
|
|
|
- String email,
|
|
|
|
- String name,
|
|
|
|
- }) {
|
|
|
|
- return User(
|
|
|
|
- id: id ?? this.id,
|
|
|
|
- email: email ?? this.email,
|
|
|
|
- name: name ?? this.name,
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
Map<String, dynamic> toMap() {
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
return {
|
|
'id': id,
|
|
'id': id,
|
|
@@ -307,8 +214,10 @@ class User {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- factory User.fromMap(Map<String, dynamic> map) {
|
|
|
|
- if (map == null) return null;
|
|
|
|
|
|
+ factory User.fromMap(Map<String, dynamic>? map) {
|
|
|
|
+ if (map == null) {
|
|
|
|
+ throw Exception('Argument is null');
|
|
|
|
+ }
|
|
|
|
|
|
return User(
|
|
return User(
|
|
id: map['id'],
|
|
id: map['id'],
|
|
@@ -320,34 +229,21 @@ class User {
|
|
String toJson() => json.encode(toMap());
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
|
factory User.fromJson(String source) => User.fromMap(json.decode(source));
|
|
factory User.fromJson(String source) => User.fromMap(json.decode(source));
|
|
-
|
|
|
|
- @override
|
|
|
|
- String toString() => 'CollectionOwner(id: $id, email: $email, name: $name)';
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- bool operator ==(Object o) {
|
|
|
|
- if (identical(this, o)) return true;
|
|
|
|
-
|
|
|
|
- return o is User && o.id == id && o.email == email && o.name == name;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- int get hashCode => id.hashCode ^ email.hashCode ^ name.hashCode;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
class PublicURL {
|
|
class PublicURL {
|
|
String url;
|
|
String url;
|
|
int deviceLimit;
|
|
int deviceLimit;
|
|
int validTill;
|
|
int validTill;
|
|
- bool enableDownload = true;
|
|
|
|
- bool passwordEnabled = false;
|
|
|
|
|
|
+ bool enableDownload;
|
|
|
|
+ bool passwordEnabled;
|
|
|
|
|
|
PublicURL({
|
|
PublicURL({
|
|
- this.url,
|
|
|
|
- this.deviceLimit,
|
|
|
|
- this.validTill,
|
|
|
|
- this.enableDownload,
|
|
|
|
- this.passwordEnabled,
|
|
|
|
|
|
+ required this.url,
|
|
|
|
+ required this.deviceLimit,
|
|
|
|
+ required this.validTill,
|
|
|
|
+ this.enableDownload = true,
|
|
|
|
+ this.passwordEnabled = false,
|
|
});
|
|
});
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
Map<String, dynamic> toMap() {
|
|
@@ -360,8 +256,10 @@ class PublicURL {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- factory PublicURL.fromMap(Map<String, dynamic> map) {
|
|
|
|
- if (map == null) return null;
|
|
|
|
|
|
+ factory PublicURL.fromMap(Map<String, dynamic>? map) {
|
|
|
|
+ if (map == null) {
|
|
|
|
+ throw Exception('Argument is null');
|
|
|
|
+ }
|
|
|
|
|
|
return PublicURL(
|
|
return PublicURL(
|
|
url: map['url'],
|
|
url: map['url'],
|
|
@@ -371,33 +269,4 @@ class PublicURL {
|
|
passwordEnabled: map['passwordEnabled'] ?? false,
|
|
passwordEnabled: map['passwordEnabled'] ?? false,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
- String toJson() => json.encode(toMap());
|
|
|
|
-
|
|
|
|
- factory PublicURL.fromJson(String source) =>
|
|
|
|
- PublicURL.fromMap(json.decode(source));
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- String toString() =>
|
|
|
|
- 'PublicUrl( url: $url, deviceLimit: $deviceLimit, validTill: $validTill, , enableDownload: $enableDownload, , passwordEnabled: $passwordEnabled)';
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- bool operator ==(Object o) {
|
|
|
|
- if (identical(this, o)) return true;
|
|
|
|
-
|
|
|
|
- return o is PublicURL &&
|
|
|
|
- o.deviceLimit == deviceLimit &&
|
|
|
|
- o.url == url &&
|
|
|
|
- o.validTill == validTill &&
|
|
|
|
- o.enableDownload == enableDownload &&
|
|
|
|
- o.passwordEnabled == passwordEnabled;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- int get hashCode =>
|
|
|
|
- deviceLimit.hashCode ^
|
|
|
|
- url.hashCode ^
|
|
|
|
- validTill.hashCode ^
|
|
|
|
- enableDownload.hashCode ^
|
|
|
|
- passwordEnabled.hashCode;
|
|
|
|
}
|
|
}
|