@@ -43,21 +43,21 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
43
43
}
44
44
45
45
Future <void > _refreshAccountInformation (RefreshAccountInformation event, Emitter <AccountState > emit) async {
46
- await _getAccountInformation (GetAccountInformation (), emit);
47
- await _getAccountSubscriptions (GetAccountSubscriptions (), emit);
48
- await _getFavoritedCommunities (GetFavoritedCommunities (), emit);
46
+ await _getAccountInformation (GetAccountInformation (reload : event.reload ), emit);
47
+ await _getAccountSubscriptions (GetAccountSubscriptions (reload : event.reload ), emit);
48
+ await _getFavoritedCommunities (GetFavoritedCommunities (reload : event.reload ), emit);
49
49
}
50
50
51
51
/// Fetches the current account's information. This updates [personView] which holds moderated community information.
52
52
Future <void > _getAccountInformation (GetAccountInformation event, Emitter <AccountState > emit) async {
53
53
Account ? account = await fetchActiveProfileAccount ();
54
54
55
55
if (account == null || account.jwt == null ) {
56
- return emit (state.copyWith (status: AccountStatus .success, personView: null , moderates: []));
56
+ return emit (state.copyWith (status: AccountStatus .success, personView: null , moderates: [], reload : event.reload ));
57
57
}
58
58
59
59
try {
60
- emit (state.copyWith (status: AccountStatus .loading));
60
+ emit (state.copyWith (status: AccountStatus .loading, reload : event.reload ));
61
61
LemmyApiV3 lemmy = LemmyClient .instance.lemmyApiV3;
62
62
63
63
GetPersonDetailsResponse ? getPersonDetailsResponse = await lemmy.run (GetPersonDetails (
@@ -70,12 +70,17 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
70
70
// This eliminates an issue which has plagued me a lot which is that there's a race condition
71
71
// with so many calls to GetAccountInformation, we can return success for the new and old account.
72
72
if (getPersonDetailsResponse? .personView.person.id == account.userId) {
73
- return emit (state.copyWith (status: AccountStatus .success, personView: getPersonDetailsResponse? .personView, moderates: getPersonDetailsResponse? .moderates));
73
+ return emit (state.copyWith (
74
+ status: AccountStatus .success,
75
+ personView: getPersonDetailsResponse? .personView,
76
+ moderates: getPersonDetailsResponse? .moderates,
77
+ reload: event.reload,
78
+ ));
74
79
} else {
75
- return emit (state.copyWith (status: AccountStatus .success, personView: null ));
80
+ return emit (state.copyWith (status: AccountStatus .success, personView: null , reload : event.reload ));
76
81
}
77
82
} catch (e) {
78
- emit (state.copyWith (status: AccountStatus .failure, errorMessage: e.toString ()));
83
+ emit (state.copyWith (status: AccountStatus .failure, errorMessage: e.toString (), reload : event.reload ));
79
84
}
80
85
}
81
86
@@ -84,11 +89,11 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
84
89
Account ? account = await fetchActiveProfileAccount ();
85
90
86
91
if (account == null || account.jwt == null ) {
87
- return emit (state.copyWith (status: AccountStatus .success, subsciptions: [], personView: null ));
92
+ return emit (state.copyWith (status: AccountStatus .success, subsciptions: [], personView: null , reload : event.reload ));
88
93
}
89
94
90
95
try {
91
- emit (state.copyWith (status: AccountStatus .loading));
96
+ emit (state.copyWith (status: AccountStatus .loading, reload : event.reload ));
92
97
93
98
LemmyApiV3 lemmy = LemmyClient .instance.lemmyApiV3;
94
99
List <CommunityView > subscriptions = [];
@@ -113,9 +118,9 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
113
118
114
119
// Sort subscriptions by their name
115
120
subscriptions.sort ((CommunityView a, CommunityView b) => a.community.title.toLowerCase ().compareTo (b.community.title.toLowerCase ()));
116
- return emit (state.copyWith (status: AccountStatus .success, subsciptions: subscriptions));
121
+ return emit (state.copyWith (status: AccountStatus .success, subsciptions: subscriptions, reload : event.reload ));
117
122
} catch (e) {
118
- emit (state.copyWith (status: AccountStatus .failure, errorMessage: e.toString ()));
123
+ emit (state.copyWith (status: AccountStatus .failure, errorMessage: e.toString (), reload : event.reload ));
119
124
}
120
125
}
121
126
@@ -124,13 +129,13 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
124
129
Account ? account = await fetchActiveProfileAccount ();
125
130
126
131
if (account == null || account.jwt == null ) {
127
- return emit (state.copyWith (status: AccountStatus .success));
132
+ return emit (state.copyWith (status: AccountStatus .success, reload : event.reload ));
128
133
}
129
134
130
135
List <Favorite > favorites = await Favorite .favorites (account.id);
131
136
List <CommunityView > favoritedCommunities =
132
137
state.subsciptions.where ((CommunityView communityView) => favorites.any ((Favorite favorite) => favorite.communityId == communityView.community.id)).toList ();
133
138
134
- return emit (state.copyWith (status: AccountStatus .success, favorites: favoritedCommunities));
139
+ return emit (state.copyWith (status: AccountStatus .success, favorites: favoritedCommunities, reload : event.reload ));
135
140
}
136
141
}
0 commit comments