user_preferences.dart
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:json_annotation/json_annotation.dart';
import '../user/user_models.dart';
import '../vip/vip_info.dart';
part 'user_preferences.g.dart';
/// Local session snapshot.
@JsonSerializable()
class UserPreferences {
const UserPreferences({
this.meUserInfo,
this.partnerUserInfo,
this.accessToken = '',
this.rongcloudToken = '',
this.vipInfo,
});
@JsonKey(name: 'me_user_info')
final UserInfoResponse? meUserInfo;
@JsonKey(name: 'partner_user_info')
final UserInfoResponse? partnerUserInfo;
@JsonKey(name: 'access_token')
final String accessToken;
@JsonKey(name: 'rongcloud_token')
final String rongcloudToken;
@JsonKey(name: 'vip_info')
final UserPreferencesVipInfo? vipInfo;
static const empty = UserPreferences();
factory UserPreferences.fromJson(Map<String, dynamic> json) =>
_$UserPreferencesFromJson(json);
Map<String, dynamic> toJson() => _$UserPreferencesToJson(this);
UserPreferences copyWith({
UserInfoResponse? meUserInfo,
UserInfoResponse? partnerUserInfo,
String? accessToken,
String? rongcloudToken,
UserPreferencesVipInfo? vipInfo,
bool clearPartner = false,
}) {
return UserPreferences(
meUserInfo: meUserInfo ?? this.meUserInfo,
partnerUserInfo:
clearPartner ? null : (partnerUserInfo ?? this.partnerUserInfo),
accessToken: accessToken ?? this.accessToken,
rongcloudToken: rongcloudToken ?? this.rongcloudToken,
vipInfo: vipInfo ?? this.vipInfo,
);
}
}
@JsonSerializable()
class UserPreferencesVipInfo {
const UserPreferencesVipInfo({
this.isVip = false,
this.isForeverVip = false,
this.isShare = false,
this.vipStartDate = 0,
this.vipEndDate = 0,
});
@JsonKey(name: 'is_vip')
final bool isVip;
@JsonKey(name: 'is_forever_vip')
final bool isForeverVip;
@JsonKey(name: 'is_share')
final bool isShare;
@JsonKey(name: 'vip_start_date')
final int vipStartDate;
@JsonKey(name: 'vip_end_date')
final int vipEndDate;
factory UserPreferencesVipInfo.fromJson(Map<String, dynamic> json) =>
_$UserPreferencesVipInfoFromJson(json);
Map<String, dynamic> toJson() => _$UserPreferencesVipInfoToJson(this);
factory UserPreferencesVipInfo.fromVipInfo(VipInfo info) {
return UserPreferencesVipInfo(
isVip: info.isVip ?? false,
isForeverVip: info.isForeverVip ?? false,
isShare: info.isShare ?? false,
vipStartDate: info.vipStartDate ?? 0,
vipEndDate: info.vipEndDate ?? 0,
);
}
}