2023-03-04 00:38:30 +02:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
|
|
|
import 'package:immich_mobile/utils/hash.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
2023-02-06 09:13:32 +02:00
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
part 'user.g.dart';
|
|
|
|
|
|
|
|
@Collection(inheritance: false)
|
2023-02-06 09:13:32 +02:00
|
|
|
class User {
|
|
|
|
User({
|
|
|
|
required this.id,
|
2023-03-04 00:38:30 +02:00
|
|
|
required this.updatedAt,
|
2023-02-06 09:13:32 +02:00
|
|
|
required this.email,
|
2023-11-12 03:03:32 +02:00
|
|
|
required this.name,
|
2023-02-06 09:13:32 +02:00
|
|
|
required this.isAdmin,
|
2023-05-25 05:52:43 +02:00
|
|
|
this.isPartnerSharedBy = false,
|
|
|
|
this.isPartnerSharedWith = false,
|
2023-07-28 05:05:27 +02:00
|
|
|
this.profileImagePath = '',
|
2023-08-10 04:01:16 +02:00
|
|
|
this.memoryEnabled = true,
|
2023-11-11 23:06:19 +02:00
|
|
|
this.inTimeline = false,
|
2023-02-06 09:13:32 +02:00
|
|
|
});
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
Id get isarId => fastHash(id);
|
|
|
|
|
2023-11-11 23:06:19 +02:00
|
|
|
User.fromUserDto(UserResponseDto dto)
|
2023-02-06 09:13:32 +02:00
|
|
|
: id = dto.id,
|
2023-05-30 15:15:56 +02:00
|
|
|
updatedAt = dto.updatedAt,
|
2023-02-06 09:13:32 +02:00
|
|
|
email = dto.email,
|
2023-11-12 03:03:32 +02:00
|
|
|
name = dto.name,
|
2023-05-25 05:52:43 +02:00
|
|
|
isPartnerSharedBy = false,
|
|
|
|
isPartnerSharedWith = false,
|
2023-07-28 05:05:27 +02:00
|
|
|
profileImagePath = dto.profileImagePath,
|
2023-08-10 04:01:16 +02:00
|
|
|
isAdmin = dto.isAdmin,
|
2023-11-13 17:54:41 +02:00
|
|
|
memoryEnabled = dto.memoriesEnabled ?? false,
|
|
|
|
inTimeline = false;
|
2023-02-06 09:13:32 +02:00
|
|
|
|
2023-11-11 23:06:19 +02:00
|
|
|
User.fromPartnerDto(PartnerResponseDto dto)
|
|
|
|
: id = dto.id,
|
|
|
|
updatedAt = dto.updatedAt,
|
|
|
|
email = dto.email,
|
2023-11-12 03:03:32 +02:00
|
|
|
name = dto.name,
|
2023-11-11 23:06:19 +02:00
|
|
|
isPartnerSharedBy = false,
|
|
|
|
isPartnerSharedWith = false,
|
|
|
|
profileImagePath = dto.profileImagePath,
|
|
|
|
isAdmin = dto.isAdmin,
|
2023-11-13 17:54:41 +02:00
|
|
|
memoryEnabled = dto.memoriesEnabled ?? false,
|
|
|
|
inTimeline = dto.inTimeline ?? false;
|
2023-11-11 23:06:19 +02:00
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
@Index(unique: true, replace: false, type: IndexType.hash)
|
2023-02-06 09:13:32 +02:00
|
|
|
String id;
|
2023-03-04 00:38:30 +02:00
|
|
|
DateTime updatedAt;
|
2023-02-06 09:13:32 +02:00
|
|
|
String email;
|
2023-11-12 03:03:32 +02:00
|
|
|
String name;
|
2023-05-25 05:52:43 +02:00
|
|
|
bool isPartnerSharedBy;
|
|
|
|
bool isPartnerSharedWith;
|
2023-02-06 09:13:32 +02:00
|
|
|
bool isAdmin;
|
2023-07-28 05:05:27 +02:00
|
|
|
String profileImagePath;
|
2023-11-13 17:54:41 +02:00
|
|
|
bool memoryEnabled;
|
|
|
|
bool inTimeline;
|
2023-11-11 23:06:19 +02:00
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
@Backlink(to: 'owner')
|
|
|
|
final IsarLinks<Album> albums = IsarLinks<Album>();
|
|
|
|
@Backlink(to: 'sharedUsers')
|
|
|
|
final IsarLinks<Album> sharedAlbums = IsarLinks<Album>();
|
2023-02-06 09:13:32 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(other) {
|
|
|
|
if (other is! User) return false;
|
|
|
|
return id == other.id &&
|
2023-05-25 05:52:43 +02:00
|
|
|
updatedAt.isAtSameMomentAs(other.updatedAt) &&
|
2023-02-06 09:13:32 +02:00
|
|
|
email == other.email &&
|
2023-11-12 03:03:32 +02:00
|
|
|
name == other.name &&
|
2023-05-25 05:52:43 +02:00
|
|
|
isPartnerSharedBy == other.isPartnerSharedBy &&
|
|
|
|
isPartnerSharedWith == other.isPartnerSharedWith &&
|
2023-07-28 05:05:27 +02:00
|
|
|
profileImagePath == other.profileImagePath &&
|
2023-08-10 04:01:16 +02:00
|
|
|
isAdmin == other.isAdmin &&
|
2023-11-11 23:06:19 +02:00
|
|
|
memoryEnabled == other.memoryEnabled &&
|
|
|
|
inTimeline == other.inTimeline;
|
2023-02-06 09:13:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-03-04 00:38:30 +02:00
|
|
|
@ignore
|
2023-02-06 09:13:32 +02:00
|
|
|
int get hashCode =>
|
|
|
|
id.hashCode ^
|
2023-03-04 00:38:30 +02:00
|
|
|
updatedAt.hashCode ^
|
2023-02-06 09:13:32 +02:00
|
|
|
email.hashCode ^
|
2023-11-12 03:03:32 +02:00
|
|
|
name.hashCode ^
|
2023-05-25 05:52:43 +02:00
|
|
|
isPartnerSharedBy.hashCode ^
|
|
|
|
isPartnerSharedWith.hashCode ^
|
2023-07-28 05:05:27 +02:00
|
|
|
profileImagePath.hashCode ^
|
2023-08-10 04:01:16 +02:00
|
|
|
isAdmin.hashCode ^
|
2023-11-11 23:06:19 +02:00
|
|
|
memoryEnabled.hashCode ^
|
|
|
|
inTimeline.hashCode;
|
2023-02-06 09:13:32 +02:00
|
|
|
}
|