Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
🐛 Fix double-refresh of communities the user can view (public/member of)
Browse files Browse the repository at this point in the history
  • Loading branch information
Komposten committed Dec 2, 2019
1 parent 22d4632 commit 524df1b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/pages/home/pages/community/community.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ class OBCommunityPageState extends State<OBCommunityPage>
_localizationService = openbookProvider.localizationService;
_needsBootstrap = false;

// Refresh the community to make sure the model contains all relevant
// community information (like admins and moderators).
_refreshCommunity();
// If the user doesn't have permission to view the community we need to
// manually trigger a refresh here to make sure the model contains all
// relevant community information (like admins and moderators).
//
// If the user can see the content, a refresh will be triggered
// automatically by the OBPostsStream.
if (!_userCanSeeCommunityContent(_community)) {
_refreshCommunity();
}
}

return CupertinoPageScaffold(
Expand All @@ -95,16 +101,7 @@ class OBCommunityPageState extends State<OBCommunityPage>
AsyncSnapshot<Community> snapshot) {
Community latestCommunity = snapshot.data;

bool communityIsPrivate = latestCommunity.isPrivate();

User loggedInUser = _userService.getLoggedInUser();
bool userIsMember =
latestCommunity.isMember(loggedInUser);

bool userCanSeeCommunityContent =
!communityIsPrivate || userIsMember;

return userCanSeeCommunityContent
return _userCanSeeCommunityContent(latestCommunity)
? _buildCommunityContent()
: _buildPrivateCommunityContent();
}),
Expand All @@ -114,6 +111,15 @@ class OBCommunityPageState extends State<OBCommunityPage>
));
}

bool _userCanSeeCommunityContent(Community community) {
bool communityIsPrivate = community.isPrivate();

User loggedInUser = _userService.getLoggedInUser();
bool userIsMember = community.isMember(loggedInUser);

return !communityIsPrivate || userIsMember;
}

Widget _buildCommunityContent() {
List<Widget> prependedItems = [
OBCommunityCover(_community),
Expand Down

0 comments on commit 524df1b

Please sign in to comment.