Skip to content

Commit

Permalink
fixed issue with search throwing error when subscribing to community
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu committed Jul 1, 2023
1 parent 25a047b commit 8927816
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Fixed issue where reply button would cover actions and comments for short posts
- Removed mark as read for mentions and replies that have already been read
- Fixed issue where setting a default sort type would cause the app to infinitely load
- Fixed issue where an error would pop up when subscribing to a community from the search page

## 0.2.1+8 - 2023-06-28
### Added
Expand Down
22 changes: 18 additions & 4 deletions lib/search/bloc/search_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,25 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
follow: event.follow,
));

// Search for the community that was updated and update it with the response
int communityToUpdateIndex = state.results!.communities.indexWhere((CommunityView communityView) => communityView.community.id == communityResponse.community.id);
state.results!.communities[communityToUpdateIndex] = communityResponse;
// Refetch the status of the community - communityResponse does not return back with the proper subscription status
FullCommunityView fullCommunityView = await lemmy.run(GetCommunity(
auth: account.jwt,
id: event.communityId,
));

List<CommunityView> communities = state.results?.communities ?? [];

communities = state.results?.communities.map((CommunityView communityView) {
if (communityView.community.id == fullCommunityView.communityView.community.id) {
return fullCommunityView.communityView;
}
return communityView;
}).toList() ??
[];

SearchResults updatedResults = state.results!.copyWith(communities: communities);

return emit(state.copyWith(status: SearchStatus.success, results: state.results));
return emit(state.copyWith(status: SearchStatus.success, results: updatedResults));
} catch (e, s) {
await Sentry.captureException(e, stackTrace: s);

Expand Down

0 comments on commit 8927816

Please sign in to comment.