shared_user.model.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'dart:convert';
  2. import 'package:immich_mobile/shared/models/user_info.model.dart';
  3. class SharedUsers {
  4. final int id;
  5. final String albumId;
  6. final String sharedUserId;
  7. final UserInfo userInfo;
  8. SharedUsers({
  9. required this.id,
  10. required this.albumId,
  11. required this.sharedUserId,
  12. required this.userInfo,
  13. });
  14. SharedUsers copyWith({
  15. int? id,
  16. String? albumId,
  17. String? sharedUserId,
  18. UserInfo? userInfo,
  19. }) {
  20. return SharedUsers(
  21. id: id ?? this.id,
  22. albumId: albumId ?? this.albumId,
  23. sharedUserId: sharedUserId ?? this.sharedUserId,
  24. userInfo: userInfo ?? this.userInfo,
  25. );
  26. }
  27. Map<String, dynamic> toMap() {
  28. final result = <String, dynamic>{};
  29. result.addAll({'id': id});
  30. result.addAll({'albumId': albumId});
  31. result.addAll({'sharedUserId': sharedUserId});
  32. result.addAll({'userInfo': userInfo.toMap()});
  33. return result;
  34. }
  35. factory SharedUsers.fromMap(Map<String, dynamic> map) {
  36. return SharedUsers(
  37. id: map['id']?.toInt() ?? 0,
  38. albumId: map['albumId'] ?? '',
  39. sharedUserId: map['sharedUserId'] ?? '',
  40. userInfo: UserInfo.fromMap(map['userInfo']),
  41. );
  42. }
  43. String toJson() => json.encode(toMap());
  44. factory SharedUsers.fromJson(String source) => SharedUsers.fromMap(json.decode(source));
  45. @override
  46. String toString() {
  47. return 'SharedUsers(id: $id, albumId: $albumId, sharedUserId: $sharedUserId, userInfo: $userInfo)';
  48. }
  49. @override
  50. bool operator ==(Object other) {
  51. if (identical(this, other)) return true;
  52. return other is SharedUsers &&
  53. other.id == id &&
  54. other.albumId == albumId &&
  55. other.sharedUserId == sharedUserId &&
  56. other.userInfo == userInfo;
  57. }
  58. @override
  59. int get hashCode {
  60. return id.hashCode ^ albumId.hashCode ^ sharedUserId.hashCode ^ userInfo.hashCode;
  61. }
  62. }