user.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:immich_mobile/shared/models/album.dart';
  2. import 'package:immich_mobile/utils/hash.dart';
  3. import 'package:isar/isar.dart';
  4. import 'package:openapi/api.dart';
  5. part 'user.g.dart';
  6. @Collection(inheritance: false)
  7. class User {
  8. User({
  9. required this.id,
  10. required this.updatedAt,
  11. required this.email,
  12. required this.firstName,
  13. required this.lastName,
  14. required this.isAdmin,
  15. this.isPartnerSharedBy = false,
  16. this.isPartnerSharedWith = false,
  17. });
  18. Id get isarId => fastHash(id);
  19. User.fromDto(UserResponseDto dto)
  20. : id = dto.id,
  21. updatedAt = dto.updatedAt != null
  22. ? DateTime.parse(dto.updatedAt!).toUtc()
  23. : DateTime.now().toUtc(),
  24. email = dto.email,
  25. firstName = dto.firstName,
  26. lastName = dto.lastName,
  27. isPartnerSharedBy = false,
  28. isPartnerSharedWith = false,
  29. isAdmin = dto.isAdmin;
  30. @Index(unique: true, replace: false, type: IndexType.hash)
  31. String id;
  32. DateTime updatedAt;
  33. String email;
  34. String firstName;
  35. String lastName;
  36. bool isPartnerSharedBy;
  37. bool isPartnerSharedWith;
  38. bool isAdmin;
  39. @Backlink(to: 'owner')
  40. final IsarLinks<Album> albums = IsarLinks<Album>();
  41. @Backlink(to: 'sharedUsers')
  42. final IsarLinks<Album> sharedAlbums = IsarLinks<Album>();
  43. @override
  44. bool operator ==(other) {
  45. if (other is! User) return false;
  46. return id == other.id &&
  47. updatedAt.isAtSameMomentAs(other.updatedAt) &&
  48. email == other.email &&
  49. firstName == other.firstName &&
  50. lastName == other.lastName &&
  51. isPartnerSharedBy == other.isPartnerSharedBy &&
  52. isPartnerSharedWith == other.isPartnerSharedWith &&
  53. isAdmin == other.isAdmin;
  54. }
  55. @override
  56. @ignore
  57. int get hashCode =>
  58. id.hashCode ^
  59. updatedAt.hashCode ^
  60. email.hashCode ^
  61. firstName.hashCode ^
  62. lastName.hashCode ^
  63. isPartnerSharedBy.hashCode ^
  64. isPartnerSharedWith.hashCode ^
  65. isAdmin.hashCode;
  66. }