user.dart 2.2 KB

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