2020-12-11 20:29:46 +00:00
|
|
|
|
import QtQuick 2.12
|
2021-07-19 12:25:52 +00:00
|
|
|
|
import QtQuick.Controls 2.3
|
2020-12-11 20:29:46 +00:00
|
|
|
|
import QtQuick.Dialogs 1.3
|
2021-07-19 12:25:52 +00:00
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
StatusModal {
|
2021-02-11 20:37:31 +00:00
|
|
|
|
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
|
2021-02-10 20:37:17 +00:00
|
|
|
|
property string source: community.thumbnailImage
|
2020-12-11 20:38:10 +00:00
|
|
|
|
property int nbMembers: community.nbMembers
|
2021-02-10 20:37:17 +00:00
|
|
|
|
property bool ensOnly: community.ensOnly
|
|
|
|
|
property bool canJoin: community.canJoin
|
|
|
|
|
property bool canRequestAccess: community.canRequestAccess
|
2021-03-09 11:50:45 +00:00
|
|
|
|
property bool isMember: community.isMember
|
2021-03-23 19:13:36 +00:00
|
|
|
|
property string communityColor: community.communityColor || Style.current.blue
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
|
|
id: popup
|
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
header.title: name
|
|
|
|
|
header.subTitle: {
|
|
|
|
|
let subTitle = ""
|
|
|
|
|
switch(access) {
|
|
|
|
|
case Constants.communityChatPublicAccess:
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "Public community"
|
|
|
|
|
subTitle = qsTrId("public-community");
|
2021-07-19 12:25:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case Constants.communityChatInvitationOnlyAccess:
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "Invitation only community"
|
|
|
|
|
subTitle = qsTrId("invitation-only-community");
|
2021-07-19 12:25:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case Constants.communityChatOnRequestAccess:
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "On request community"
|
|
|
|
|
subTitle = qsTrId("on-request-community");
|
2021-07-19 12:25:52 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
subTitle = qsTrId("Unknown community");
|
|
|
|
|
break;
|
2021-03-23 19:13:36 +00:00
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
if (ensOnly) {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% " - ENS only"
|
|
|
|
|
subTitle += qsTrId("---ens-only")
|
2021-03-23 19:13:36 +00:00
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
return subTitle
|
|
|
|
|
}
|
2021-03-23 19:13:36 +00:00
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
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
|
2021-07-26 13:53:39 +00:00
|
|
|
|
width: parent.width
|
2021-03-23 19:13:36 +00:00
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
2021-07-19 12:25:52 +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
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
StatusBaseText {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "%1 members"
|
|
|
|
|
text: qsTrId("-1-members").arg(nbMembers)
|
2021-07-19 12:25:52 +00:00
|
|
|
|
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
|
|
|
|
}
|
2021-02-10 20:37:17 +00:00
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
StatusModalDivider {
|
|
|
|
|
topPadding: 8
|
|
|
|
|
bottomPadding: 8
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
Item {
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: parent.width - 32
|
|
|
|
|
height: 34
|
|
|
|
|
StatusBaseText {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "Channels"
|
|
|
|
|
text: qsTrId("channels")
|
2021-07-19 12:25:52 +00:00
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 4
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 12:25:52 +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
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
leftButtons: [
|
|
|
|
|
StatusRoundButton {
|
2020-12-11 20:29:46 +00:00
|
|
|
|
id: backButton
|
2021-07-19 12:25:52 +00:00
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
]
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
2021-07-19 12:25:52 +00:00
|
|
|
|
rightButtons: [
|
2020-12-11 20:29:46 +00:00
|
|
|
|
StatusButton {
|
2021-02-10 20:37:17 +00:00
|
|
|
|
property bool isPendingRequest: {
|
|
|
|
|
if (access !== Constants.communityChatOnRequestAccess) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
return chatsModel.communities.isCommunityRequestPending(popup.communityId)
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
|
|
|
|
text: {
|
2021-07-19 12:25:52 +00:00
|
|
|
|
if (popup.ensOnly && !profileModel.profile.ensVerified) {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "Membership requires an ENS username"
|
|
|
|
|
return qsTrId("membership-requires-an-ens-username")
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
if (popup.canJoin) {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "Join ‘%1’"
|
|
|
|
|
return qsTrId("join---1-").arg(popup.name);
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
|
|
|
|
if (isPendingRequest) {
|
2021-07-16 20:22:50 +00:00
|
|
|
|
//% "Pending"
|
|
|
|
|
return qsTrId("invite-chat-pending")
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
switch(popup.access) {
|
2021-07-22 15:03:59 +00:00
|
|
|
|
//% "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");
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
enabled: {
|
2021-07-19 12:25:52 +00:00
|
|
|
|
if (popup.ensOnly && !profileModel.profile.ensVerified) {
|
2021-02-10 20:37:17 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
if (popup.access === Constants.communityChatInvitationOnlyAccess || isPendingRequest) {
|
2021-02-10 20:37:17 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
2021-04-29 19:54:09 +00:00
|
|
|
|
if (canJoin) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2021-02-10 20:37:17 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
onClicked: {
|
2021-02-10 20:37:17 +00:00
|
|
|
|
let error
|
2021-03-09 11:50:45 +00:00
|
|
|
|
if (access === Constants.communityChatOnRequestAccess && !popup.isMember) {
|
2021-02-11 20:37:31 +00:00
|
|
|
|
error = chatsModel.communities.requestToJoinCommunity(popup.communityId,
|
2021-02-10 20:37:17 +00:00
|
|
|
|
profileModel.profile.ensVerified ? profileModel.profile.username : "")
|
|
|
|
|
if (!error) {
|
|
|
|
|
enabled = false
|
2021-07-16 20:22:50 +00:00
|
|
|
|
//% "Pending"
|
|
|
|
|
text = qsTrId("invite-chat-pending")
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-03-05 09:05:04 +00:00
|
|
|
|
error = chatsModel.communities.joinCommunity(popup.communityId, true)
|
2021-02-10 20:37:17 +00:00
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
joiningError.text = error
|
|
|
|
|
return joiningError.open()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 12:25:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|