diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index d6fbe17fd2..b868b4c3a5 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -141,6 +141,13 @@ QtObject: if community.id == communityId: return community.joined and community.isMember return false + + proc userCanJoin*(self: CommunitiesView, communityId: string): bool {.slot.} = + let communities = self.getCommunitiesIfNotFetched() + for community in communities.communities: + if community.id == communityId: + return community.canJoin + return false proc activeCommunityChanged*(self: CommunitiesView) {.signal.} @@ -162,6 +169,8 @@ QtObject: proc joinCommunity*(self: CommunitiesView, communityId: string, setActive: bool = true): string {.slot.} = result = "" try: + if (not self.userCanJoin(communityId) or self.isUserMemberOfCommunity(communityId)): + return self.status.chat.joinCommunity(communityId) self.joinedCommunityList.addCommunityItemToList(self.communityList.getCommunityById(communityId)) if (setActive): diff --git a/ui/imports/Utils.qml b/ui/imports/Utils.qml index 1130823194..e2ecfb3304 100644 --- a/ui/imports/Utils.qml +++ b/ui/imports/Utils.qml @@ -411,7 +411,11 @@ QtObject { chatsModel.communities.setActiveCommunity(communityId) return } - chatsModel.communities.joinCommunity(communityId, true) + const userCanJoin = chatsModel.communities.userCanJoin(communityId) + // TODO find what to do when you can't join + if (userCanJoin) { + chatsModel.communities.joinCommunity(communityId, true) + } } return result }