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,
|
|
|
|
required this.firstName,
|
|
|
|
required this.lastName,
|
|
|
|
required this.isAdmin,
|
|
|
|
});
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
Id get isarId => fastHash(id);
|
|
|
|
|
2023-02-06 09:13:32 +02:00
|
|
|
User.fromDto(UserResponseDto dto)
|
|
|
|
: id = dto.id,
|
2023-03-04 00:38:30 +02:00
|
|
|
updatedAt = dto.updatedAt != null
|
|
|
|
? DateTime.parse(dto.updatedAt!).toUtc()
|
|
|
|
: DateTime.now().toUtc(),
|
2023-02-06 09:13:32 +02:00
|
|
|
email = dto.email,
|
|
|
|
firstName = dto.firstName,
|
|
|
|
lastName = dto.lastName,
|
2023-03-04 00:38:30 +02:00
|
|
|
isAdmin = dto.isAdmin;
|
2023-02-06 09:13:32 +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;
|
|
|
|
String firstName;
|
|
|
|
String lastName;
|
|
|
|
bool isAdmin;
|
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-03-04 00:38:30 +02:00
|
|
|
updatedAt == other.updatedAt &&
|
2023-02-06 09:13:32 +02:00
|
|
|
email == other.email &&
|
|
|
|
firstName == other.firstName &&
|
|
|
|
lastName == other.lastName &&
|
2023-03-04 00:38:30 +02:00
|
|
|
isAdmin == other.isAdmin;
|
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 ^
|
|
|
|
firstName.hashCode ^
|
|
|
|
lastName.hashCode ^
|
2023-03-04 00:38:30 +02:00
|
|
|
isAdmin.hashCode;
|
2023-02-06 09:13:32 +02:00
|
|
|
}
|