user.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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,
  22. email = dto.email,
  23. firstName = dto.firstName,
  24. lastName = dto.lastName,
  25. isPartnerSharedBy = false,
  26. isPartnerSharedWith = false,
  27. isAdmin = dto.isAdmin;
  28. @Index(unique: true, replace: false, type: IndexType.hash)
  29. String id;
  30. DateTime updatedAt;
  31. String email;
  32. String firstName;
  33. String lastName;
  34. bool isPartnerSharedBy;
  35. bool isPartnerSharedWith;
  36. bool isAdmin;
  37. @Backlink(to: 'owner')
  38. final IsarLinks<Album> albums = IsarLinks<Album>();
  39. @Backlink(to: 'sharedUsers')
  40. final IsarLinks<Album> sharedAlbums = IsarLinks<Album>();
  41. @override
  42. bool operator ==(other) {
  43. if (other is! User) return false;
  44. return id == other.id &&
  45. updatedAt.isAtSameMomentAs(other.updatedAt) &&
  46. email == other.email &&
  47. firstName == other.firstName &&
  48. lastName == other.lastName &&
  49. isPartnerSharedBy == other.isPartnerSharedBy &&
  50. isPartnerSharedWith == other.isPartnerSharedWith &&
  51. isAdmin == other.isAdmin;
  52. }
  53. @override
  54. @ignore
  55. int get hashCode =>
  56. id.hashCode ^
  57. updatedAt.hashCode ^
  58. email.hashCode ^
  59. firstName.hashCode ^
  60. lastName.hashCode ^
  61. isPartnerSharedBy.hashCode ^
  62. isPartnerSharedWith.hashCode ^
  63. isAdmin.hashCode;
  64. }