2020-12-18 20:55:33 +00:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.3
|
2022-11-28 14:57:56 +00:00
|
|
|
import QtQuick.Layouts 1.14
|
2020-12-18 20:55:33 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import QtQuick.Dialogs 1.3
|
2022-11-28 14:57:56 +00:00
|
|
|
import QtQml.Models 2.14
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.controls 1.0
|
2021-10-19 08:51:11 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-11-28 14:57:56 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2021-10-19 08:51:11 +00:00
|
|
|
|
2022-11-28 14:57:56 +00:00
|
|
|
StatusDialog {
|
2021-10-22 20:49:47 +00:00
|
|
|
id: root
|
2023-10-27 10:25:27 +00:00
|
|
|
|
2021-11-30 14:49:36 +00:00
|
|
|
property var store
|
2023-10-27 10:25:27 +00:00
|
|
|
property alias text: keyInput.text
|
|
|
|
|
|
|
|
signal joinCommunityRequested(string communityId, var communityDetails)
|
|
|
|
|
2022-11-28 14:57:56 +00:00
|
|
|
width: 640
|
|
|
|
title: qsTr("Import Community")
|
2021-10-22 20:49:47 +00:00
|
|
|
|
2022-11-28 14:57:56 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property string importErrorMessage
|
2023-07-31 15:56:00 +00:00
|
|
|
|
2023-10-27 10:25:27 +00:00
|
|
|
readonly property bool communityFound: !!d.communityDetails && !!d.communityDetails.name
|
|
|
|
property var communityDetails: null
|
|
|
|
|
|
|
|
property var requestedCommunityDetails: null
|
2023-07-31 15:56:00 +00:00
|
|
|
|
2022-11-28 14:57:56 +00:00
|
|
|
readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key")
|
|
|
|
readonly property string errorMessage: importErrorMessage || inputErrorMessage
|
2023-05-15 10:31:23 +00:00
|
|
|
readonly property string inputKey: keyInput.text.trim()
|
2023-11-08 19:59:45 +00:00
|
|
|
property int shardCluster: -1
|
|
|
|
property int shardIndex: -1
|
2023-05-15 10:31:23 +00:00
|
|
|
readonly property string publicKey: {
|
2023-10-27 10:25:27 +00:00
|
|
|
if (Utils.isStatusDeepLink(inputKey)) {
|
2023-11-08 19:59:45 +00:00
|
|
|
d.shardCluster = -1
|
|
|
|
d.shardIndex = -1
|
2023-10-27 10:25:27 +00:00
|
|
|
const linkData = Utils.getCommunityDataFromSharedLink(inputKey)
|
2023-11-08 19:59:45 +00:00
|
|
|
if (!linkData) {
|
|
|
|
return ""
|
|
|
|
}
|
2023-12-01 18:36:17 +00:00
|
|
|
if (linkData.shardCluster != undefined && linkData.shardIndex != undefined) {
|
|
|
|
d.shardCluster = linkData.shardCluster
|
|
|
|
d.shardIndex = linkData.shardIndex
|
|
|
|
}
|
2023-11-08 19:59:45 +00:00
|
|
|
return linkData.communityId
|
2023-10-27 10:25:27 +00:00
|
|
|
}
|
|
|
|
if (!Utils.isCommunityPublicKey(inputKey))
|
|
|
|
return ""
|
|
|
|
if (!Utils.isCompressedPubKey(inputKey))
|
|
|
|
return inputKey
|
|
|
|
return Utils.changeCommunityKeyCompression(inputKey)
|
|
|
|
}
|
|
|
|
readonly property bool isInputValid: publicKey !== ""
|
|
|
|
|
|
|
|
property bool communityInfoRequested: false
|
|
|
|
|
|
|
|
function updateCommunityDetails(requestIfNotFound) {
|
|
|
|
if (!isInputValid) {
|
|
|
|
d.communityInfoRequested = false
|
|
|
|
d.communityDetails = null
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const details = root.store.getCommunityDetails(publicKey)
|
|
|
|
|
|
|
|
if (!!details) {
|
|
|
|
d.communityInfoRequested = false
|
|
|
|
d.communityDetails = details
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestIfNotFound) {
|
2023-11-08 19:59:45 +00:00
|
|
|
root.store.requestCommunityInfo(publicKey, shardCluster, shardIndex, false)
|
2023-10-27 10:25:27 +00:00
|
|
|
d.communityInfoRequested = true
|
|
|
|
d.communityDetails = null
|
2023-07-21 17:21:11 +00:00
|
|
|
}
|
2023-05-15 10:31:23 +00:00
|
|
|
}
|
2021-03-10 14:25:06 +00:00
|
|
|
|
2023-10-27 10:25:27 +00:00
|
|
|
onPublicKeyChanged: {
|
|
|
|
// call later to make sure all proeprties used by `updateCommunityDetails` are udpated
|
|
|
|
Qt.callLater(() => { d.updateCommunityDetails(true) })
|
2023-10-12 14:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.store
|
|
|
|
|
2023-10-27 10:25:27 +00:00
|
|
|
function onCommunityInfoRequestCompleted(communityId, errorMsg) {
|
|
|
|
if (!d.communityInfoRequested)
|
|
|
|
return
|
|
|
|
|
|
|
|
d.communityInfoRequested = false
|
|
|
|
|
|
|
|
if (errorMsg !== "") {
|
|
|
|
d.importErrorMessage = qsTr("Couldn't find community")
|
2023-10-12 14:35:59 +00:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 10:25:27 +00:00
|
|
|
|
|
|
|
d.updateCommunityDetails(false)
|
|
|
|
d.importErrorMessage = ""
|
2023-10-12 14:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 14:57:56 +00:00
|
|
|
footer: StatusDialogFooter {
|
|
|
|
rightButtons: ObjectModel {
|
|
|
|
StatusButton {
|
2023-10-27 10:25:27 +00:00
|
|
|
enabled: d.isInputValid && d.communityFound
|
|
|
|
loading: d.isInputValid && !d.communityFound && d.communityInfoRequested
|
|
|
|
text: qsTr("Import")
|
2023-05-04 15:37:44 +00:00
|
|
|
onClicked: {
|
2023-10-27 10:25:27 +00:00
|
|
|
root.joinCommunityRequested(d.publicKey, d.communityDetails)
|
2023-05-04 15:37:44 +00:00
|
|
|
}
|
2022-11-28 14:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-18 20:55:33 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 15:56:00 +00:00
|
|
|
StatusScrollView {
|
|
|
|
id: scrollContent
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: Style.current.halfPadding
|
|
|
|
contentWidth: (root.width-Style.current.bigPadding-Style.current.padding)
|
|
|
|
padding: 0
|
2022-03-23 10:56:25 +00:00
|
|
|
|
2023-07-31 15:56:00 +00:00
|
|
|
ColumnLayout {
|
|
|
|
width: (scrollContent.width-Style.current.padding)
|
|
|
|
spacing: Style.current.halfPadding
|
2022-11-28 14:57:56 +00:00
|
|
|
|
2023-07-21 17:21:11 +00:00
|
|
|
StatusBaseText {
|
2023-07-31 15:56:00 +00:00
|
|
|
id: infoText1
|
|
|
|
Layout.fillWidth: true
|
2023-10-27 10:25:27 +00:00
|
|
|
text: qsTr("Enter the public key of the community you wish to access")
|
2023-07-31 15:56:00 +00:00
|
|
|
wrapMode: Text.WordWrap
|
2023-10-12 14:35:59 +00:00
|
|
|
font.pixelSize: Style.current.additionalTextSize
|
2023-07-31 15:56:00 +00:00
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: inputLabel
|
|
|
|
text: qsTr("Community key")
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
2024-02-08 11:42:40 +00:00
|
|
|
StatusScrollView {
|
|
|
|
padding: 0 // use our own (StatusTextArea) padding
|
2023-07-31 15:56:00 +00:00
|
|
|
Layout.fillWidth: true
|
2023-10-02 12:20:15 +00:00
|
|
|
Layout.preferredHeight: 108
|
2024-02-08 11:42:40 +00:00
|
|
|
StatusTextArea {
|
|
|
|
id: keyInput
|
|
|
|
anchors.fill: parent
|
|
|
|
placeholderText: "0x0..."
|
|
|
|
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
|
|
|
|
onTextChanged: d.importErrorMessage = ""
|
|
|
|
}
|
2023-07-31 15:56:00 +00:00
|
|
|
}
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumHeight: 46
|
|
|
|
Layout.maximumHeight: 46
|
|
|
|
StatusChatInfoButton {
|
|
|
|
visible: d.communityFound
|
|
|
|
title: visible ? d.communityDetails.name : ""
|
|
|
|
subTitle: visible ? qsTr("%n member(s)", "", d.communityDetails.nbMembers) : ""
|
|
|
|
asset.name: visible ? d.communityDetails.image : ""
|
|
|
|
asset.isImage: (asset.name !== "")
|
|
|
|
asset.color: visible ? d.communityDetails.color : ""
|
|
|
|
}
|
|
|
|
Item { Layout.fillWidth: true }
|
|
|
|
StatusBaseText {
|
|
|
|
id: detectionLabel
|
|
|
|
Layout.alignment: Qt.AlignRight
|
2023-10-12 14:35:59 +00:00
|
|
|
font.pixelSize: Style.current.additionalTextSize
|
|
|
|
visible: !!d.inputKey
|
2023-07-31 15:56:00 +00:00
|
|
|
text: {
|
2023-10-27 10:25:27 +00:00
|
|
|
if (d.errorMessage !== "")
|
2023-07-31 15:56:00 +00:00
|
|
|
return d.errorMessage
|
2023-10-27 10:25:27 +00:00
|
|
|
if (d.isInputValid)
|
2023-07-31 15:56:00 +00:00
|
|
|
return qsTr("Public key detected")
|
2023-10-27 10:25:27 +00:00
|
|
|
return ""
|
2023-07-21 17:21:11 +00:00
|
|
|
}
|
2023-07-31 15:56:00 +00:00
|
|
|
color: d.errorMessage === "" ? Theme.palette.successColor1 : Theme.palette.dangerColor1
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 18:19:31 +00:00
|
|
|
}
|
2020-12-18 20:55:33 +00:00
|
|
|
}
|
|
|
|
}
|