Pascal Precht 81d4ea05e9 fix(communities): only require auth for token gated communities
There's a bug that all requests to join a community require the user to
authenticate themselves. This should only be needed for community that
are token permissioned.

This commit fixes it by only performing auth when requesting from the
tokengated community view.

Fixes #10010
2023-03-24 15:22:47 -04:00

163 lines
5.6 KiB
QML

import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import utils 1.0
import shared.popups 1.0
import "views"
import "views/communities"
import "stores"
import "popups/community"
import AppLayouts.Chat.stores 1.0
StackLayout {
id: root
property RootStore rootStore
readonly property var contactsStore: rootStore.contactsStore
readonly property var permissionsStore: rootStore.permissionsStore
property var sectionItemModel
property var emojiPopup
property var stickersPopup
signal importCommunityClicked()
signal createCommunityClicked()
signal profileButtonClicked()
signal openAppSearch()
onCurrentIndexChanged: {
Global.closeCreateChatView()
}
Component {
id: membershipRequestPopupComponent
MembershipRequestsPopup {
anchors.centerIn: parent
store: root.rootStore
communityData: sectionItemModel
onClosed: {
destroy()
}
}
}
Loader {
readonly property var chatItem: root.rootStore.chatCommunitySectionModule
sourceComponent: chatItem.isCommunity() && chatItem.requiresTokenPermissionToJoin && !chatItem.amIMember ? joinCommunityViewComponent : chatViewComponent
}
Component {
id: joinCommunityViewComponent
JoinCommunityView {
id: joinCommunityView
readonly property var communityData: sectionItemModel
name: communityData.name
communityDesc: communityData.description
color: communityData.color
image: communityData.image
membersCount: communityData.members.count
accessType: communityData.access
joinCommunity: true
amISectionAdmin: communityData.amISectionAdmin
communityItemsModel: root.rootStore.communityItemsModel
requirementsMet: root.permissionsStore.allTokenRequirementsMet
communityHoldingsModel: root.permissionsStore.permissionsModel
assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel
isInvitationPending: root.rootStore.isCommunityRequestPending(communityData.id)
notificationCount: activityCenterStore.unreadNotificationsCount
hasUnseenNotifications: activityCenterStore.hasUnseenNotifications
openCreateChat: rootStore.openCreateChat
onNotificationButtonClicked: Global.openActivityCenterPopup()
onAdHocChatButtonClicked: rootStore.openCloseCreateChatView()
onRevealAddressClicked: {
communityIntroDialog.open()
}
onInvitationPendingClicked: {
root.rootStore.cancelPendingRequest(communityData.id)
joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityData.id)
}
Connections {
target: root.rootStore.communitiesModuleInst
function onCommunityAccessRequested(communityId: string) {
if (communityId === joinCommunityView.communityData.id) {
joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityData.id)
}
}
}
CommunityIntroDialog {
id: communityIntroDialog
isInvitationPending: joinCommunityView.isInvitationPending
name: communityData.name
introMessage: communityData.introMessage
imageSrc: communityData.image
accessType: communityData.access
onJoined: {
root.rootStore.requestToJoinCommunityWithAuthentication(communityData.id, root.rootStore.userProfileInst.name)
}
onCancelMembershipRequest: {
root.rootStore.cancelPendingRequest(communityData.id)
joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityData.id)
}
}
}
}
Component {
id: chatViewComponent
ChatView {
id: chatView
emojiPopup: root.emojiPopup
stickersPopup: root.stickersPopup
contactsStore: root.contactsStore
rootStore: root.rootStore
sectionItemModel: root.sectionItemModel
membershipRequestPopup: membershipRequestPopupComponent
onCommunityInfoButtonClicked: root.currentIndex = 1
onCommunityManageButtonClicked: root.currentIndex = 1
onImportCommunityClicked: {
root.importCommunityClicked();
}
onCreateCommunityClicked: {
root.createCommunityClicked();
}
onProfileButtonClicked: {
root.profileButtonClicked()
}
onOpenAppSearch: {
root.openAppSearch()
}
}
}
Loader {
active: root.rootStore.chatCommunitySectionModule.isCommunity()
sourceComponent: CommunitySettingsView {
rootStore: root.rootStore
hasAddedContacts: root.contactsStore.myContactsModel.count > 0
chatCommunitySectionModule: root.rootStore.chatCommunitySectionModule
community: sectionItemModel
onBackToCommunityClicked: root.currentIndex = 0
// TODO: remove me when migration to new settings is done
onOpenLegacyPopupClicked: Global.openCommunityProfilePopupRequested(root.rootStore, community, chatCommunitySectionModule)
}
}
}