user.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. this.profileImagePath = '',
  18. });
  19. Id get isarId => fastHash(id);
  20. User.fromDto(UserResponseDto dto)
  21. : id = dto.id,
  22. updatedAt = dto.updatedAt,
  23. email = dto.email,
  24. firstName = dto.firstName,
  25. lastName = dto.lastName,
  26. isPartnerSharedBy = false,
  27. isPartnerSharedWith = false,
  28. profileImagePath = dto.profileImagePath,
  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. String profileImagePath;
  40. @Backlink(to: 'owner')
  41. final IsarLinks<Album> albums = IsarLinks<Album>();
  42. @Backlink(to: 'sharedUsers')
  43. final IsarLinks<Album> sharedAlbums = IsarLinks<Album>();
  44. @override
  45. bool operator ==(other) {
  46. if (other is! User) return false;
  47. return id == other.id &&
  48. updatedAt.isAtSameMomentAs(other.updatedAt) &&
  49. email == other.email &&
  50. firstName == other.firstName &&
  51. lastName == other.lastName &&
  52. isPartnerSharedBy == other.isPartnerSharedBy &&
  53. isPartnerSharedWith == other.isPartnerSharedWith &&
  54. profileImagePath == other.profileImagePath &&
  55. isAdmin == other.isAdmin;
  56. }
  57. @override
  58. @ignore
  59. int get hashCode =>
  60. id.hashCode ^
  61. updatedAt.hashCode ^
  62. email.hashCode ^
  63. firstName.hashCode ^
  64. lastName.hashCode ^
  65. isPartnerSharedBy.hashCode ^
  66. isPartnerSharedWith.hashCode ^
  67. profileImagePath.hashCode ^
  68. isAdmin.hashCode;
  69. }