status-desktop/ui/app/AppLayouts/Chat/CommunityComponents/CommunityDetailPopup.qml

231 lines
7.6 KiB
QML
Raw Normal View History

2020-12-11 20:29:46 +00:00
import QtQuick 2.12
import QtQuick.Controls 2.3
2020-12-11 20:29:46 +00:00
import QtQuick.Dialogs 1.3
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
2020-12-11 20:29:46 +00:00
import "../../../../imports"
import "../../../../shared"
StatusModal {
property QtObject community: chatsModel.communities.observedCommunity
2020-12-11 20:29:46 +00:00
property string communityId: community.id
property string name: community.name
property string description: community.description
2020-12-11 20:38:10 +00:00
property int access: community.access
property string source: community.thumbnailImage
2020-12-11 20:38:10 +00:00
property int nbMembers: community.nbMembers
property bool ensOnly: community.ensOnly
property bool canJoin: community.canJoin
property bool canRequestAccess: community.canRequestAccess
fix(Communities): don't crash on rejoin attempt Prior to this commit there was a scenario where the application would crash due a memory bug when attempting to (re)join a community. The scenario is as follows: 1. User creates or has been invited to community with `ON_REQUEST` permissions 2. User leaves community 3. User decides to rejoin, so she selects the community she's been part of and hits the "Join" button At this point Status Desktop would send a new `RequestToJoin` request, as the community has a corresponding permissions setting. This would then result in an `already a member` error in status-go, because status-go checks whether the requestee is already part of the members list of the community. The error isn't handled inside Status Desktop which causes a crash because we're trying to access data in memory that doesn't exist. Why is this happening? While this might be unexpected, when leaving a community (as done on step 2 of the mentioned scenario), users don't actually lose membership but simply "unsubscribe" from all channels in the community in question and their `joined` flag is set to `false`. From that point on, re-joininng a community is done by sending a `JoinCommunity` request (instead of `RequestToJoin`), which will then set the `joined` flag to `true` and doesn't actually check the membership in the database. This commit ensures we're calling the right API by checking whether not only whether the community is needs `ON _REQUEST` permissions, but also whether the user isn't already a member of it. Fixes #2017
2021-03-09 11:50:45 +00:00
property bool isMember: community.isMember
property string communityColor: community.communityColor || Style.current.blue
2020-12-11 20:29:46 +00:00
id: popup
header.title: name
header.subTitle: {
let subTitle = ""
switch(access) {
case Constants.communityChatPublicAccess:
//% "Public community"
subTitle = qsTrId("public-community");
break;
case Constants.communityChatInvitationOnlyAccess:
//% "Invitation only community"
subTitle = qsTrId("invitation-only-community");
break;
case Constants.communityChatOnRequestAccess:
//% "On request community"
subTitle = qsTrId("on-request-community");
break;
default:
subTitle = qsTrId("Unknown community");
break;
}
if (ensOnly) {
//% " - ENS only"
subTitle += qsTrId("---ens-only")
}
return subTitle
}
content: Column {
width: popup.width
Item {
height: childrenRect.height + 8
width: parent.width - 32
anchors.horizontalCenter: parent.horizontalCenter
StatusBaseText {
id: description
anchors.top: parent.top
anchors.topMargin: 16
text: popup.description
font.pixelSize: 15
color: Theme.palette.directColor1
wrapMode: Text.WordWrap
width: parent.width
}
2020-12-11 20:29:46 +00:00
StatusIcon {
id: statusIcon
anchors.top: description.bottom
anchors.topMargin: 16
anchors.left: parent.left
icon: "tiny/contact"
width: 16
color: Theme.palette.directColor1
}
2020-12-11 20:29:46 +00:00
StatusBaseText {
//% "%1 members"
text: qsTrId("-1-members").arg(nbMembers)
font.pixelSize: 15
font.weight: Font.Medium
color: Theme.palette.directColor1
anchors.left: statusIcon.right
anchors.leftMargin: 2
anchors.verticalCenter: statusIcon.verticalCenter
2020-12-11 20:38:10 +00:00
}
2020-12-11 20:29:46 +00:00
}
StatusModalDivider {
topPadding: 8
bottomPadding: 8
}
2020-12-11 20:29:46 +00:00
Item {
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - 32
height: 34
StatusBaseText {
//% "Channels"
text: qsTrId("channels")
anchors.bottom: parent.bottom
anchors.bottomMargin: 4
font.pixelSize: 15
color: Theme.palette.baseColor1
}
2020-12-11 20:29:46 +00:00
}
ScrollView {
width: popup.width
height: 300
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
clip: true
ListView {
id: chatList
anchors.fill: parent
clip: true
model: community.chats
boundsBehavior: Flickable.StopAtBounds
delegate: StatusListItem {
anchors.horizontalCenter: parent.horizontalCenter
title: "#" + model.name
subTitle: model.description
icon.isLetterIdenticon: true
icon.background.color: popup.communityColor
}
}
2020-12-11 20:29:46 +00:00
}
}
2020-12-11 20:38:10 +00:00
2020-12-11 20:29:46 +00:00
leftButtons: [
StatusRoundButton {
2020-12-11 20:29:46 +00:00
id: backButton
icon.name: "arrow-right"
icon.height: 16
icon.width: 20
rotation: 180
2020-12-11 20:29:46 +00:00
onClicked: {
openPopup(communitiesPopupComponent)
popup.close()
}
}
]
2020-12-11 20:29:46 +00:00
rightButtons: [
2020-12-11 20:29:46 +00:00
StatusButton {
property bool isPendingRequest: {
if (access !== Constants.communityChatOnRequestAccess) {
return false
}
return chatsModel.communities.isCommunityRequestPending(popup.communityId)
}
text: {
if (popup.ensOnly && !profileModel.profile.ensVerified) {
//% "Membership requires an ENS username"
return qsTrId("membership-requires-an-ens-username")
}
if (popup.canJoin) {
//% "Join %1"
return qsTrId("join---1-").arg(popup.name);
}
if (isPendingRequest) {
//% "Pending"
return qsTrId("invite-chat-pending")
}
switch(popup.access) {
//% "Join %1"
case Constants.communityChatPublicAccess: return qsTrId("join---1-").arg(popup.name);
//% "You need to be invited"
case Constants.communityChatInvitationOnlyAccess: return qsTrId("you-need-to-be-invited");
//% "Request to join %1"
case Constants.communityChatOnRequestAccess: return qsTrId("request-to-join---1-").arg(popup.name);
//% "Unknown community"
default: return qsTrId("unknown-community");
}
}
enabled: {
if (popup.ensOnly && !profileModel.profile.ensVerified) {
return false
}
if (popup.access === Constants.communityChatInvitationOnlyAccess || isPendingRequest) {
return false
}
if (canJoin) {
return true
}
return true
}
2020-12-11 20:29:46 +00:00
onClicked: {
let error
fix(Communities): don't crash on rejoin attempt Prior to this commit there was a scenario where the application would crash due a memory bug when attempting to (re)join a community. The scenario is as follows: 1. User creates or has been invited to community with `ON_REQUEST` permissions 2. User leaves community 3. User decides to rejoin, so she selects the community she's been part of and hits the "Join" button At this point Status Desktop would send a new `RequestToJoin` request, as the community has a corresponding permissions setting. This would then result in an `already a member` error in status-go, because status-go checks whether the requestee is already part of the members list of the community. The error isn't handled inside Status Desktop which causes a crash because we're trying to access data in memory that doesn't exist. Why is this happening? While this might be unexpected, when leaving a community (as done on step 2 of the mentioned scenario), users don't actually lose membership but simply "unsubscribe" from all channels in the community in question and their `joined` flag is set to `false`. From that point on, re-joininng a community is done by sending a `JoinCommunity` request (instead of `RequestToJoin`), which will then set the `joined` flag to `true` and doesn't actually check the membership in the database. This commit ensures we're calling the right API by checking whether not only whether the community is needs `ON _REQUEST` permissions, but also whether the user isn't already a member of it. Fixes #2017
2021-03-09 11:50:45 +00:00
if (access === Constants.communityChatOnRequestAccess && !popup.isMember) {
error = chatsModel.communities.requestToJoinCommunity(popup.communityId,
profileModel.profile.ensVerified ? profileModel.profile.username : "")
if (!error) {
enabled = false
//% "Pending"
text = qsTrId("invite-chat-pending")
}
} else {
error = chatsModel.communities.joinCommunity(popup.communityId, true)
}
2020-12-11 20:29:46 +00:00
if (error) {
joiningError.text = error
return joiningError.open()
}
popup.close()
}
}
]
MessageDialog {
id: joiningError
//% "Error joining the community"
title: qsTrId("error-joining-the-community")
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
2020-12-11 20:29:46 +00:00
}
}