user.dart 2.5 KB

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