add import for a community

This commit is contained in:
Jonathan Rainville 2020-12-18 15:55:33 -05:00 committed by Iuri Matias
parent 82405cc425
commit a90a30af11
7 changed files with 117 additions and 8 deletions

View File

@ -722,3 +722,9 @@ QtObject:
except Exception as e:
error "Error exporting the community", msg = e.msg
result = fmt"Error exporting the community: {e.msg}"
proc importCommunity*(self: ChatsView, communityKey: string) {.slot.} =
try:
self.status.chat.importCommunity(communityKey)
except Exception as e:
error "Error importing the community", msg = e.msg

View File

@ -399,4 +399,7 @@ proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string
self.sendMessage(pubKey, "Upgrade here to see an invitation to community", "", ContentType.Community.int, communityId)
proc exportCommunity*(self: ChatModel, communityId: string): string =
result = status_chat.exportCommunity(communityId)
result = status_chat.exportCommunity(communityId)
proc importCommunity*(self: ChatModel, communityKey: string) =
status_chat.importCommunity(communityKey)

View File

@ -303,4 +303,8 @@ proc inviteUserToCommunity*(communityId: string, pubKey: string) =
debug "RESULT", res
proc exportCommunity*(communityId: string):string =
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr
result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr
proc importCommunity*(communityKey: string) =
let res = callPrivateRPC("importCommunity".prefix, %*[communityKey])
debug "RESULT", res

View File

@ -126,12 +126,27 @@ ModalPopup {
}
}
footer: StatusButton {
text: qsTr("Create a community")
anchors.right: parent.right
onClicked: {
openPopup(createCommunitiesPopupComponent)
popup.close()
footer: Item {
anchors.fill: parent
StatusButton {
text: qsTr("Import a community")
anchors.right: createBtn.left
anchors.rightMargin: Style.current.smallPadding
onClicked: {
openPopup(importCommunitiesPopupComponent)
popup.close()
}
}
StatusButton {
id: createBtn
text: qsTr("Create a community")
anchors.right: parent.right
onClicked: {
openPopup(createCommunitiesPopupComponent)
popup.close()
}
}
}
}

View File

@ -0,0 +1,71 @@
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtGraphicalEffects 1.13
import QtQuick.Dialogs 1.3
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
ModalPopup {
property string keyValidationError: ""
id: popup
height: 300
onOpened: {
keyInput.text = isEdit ? community.name : "";
keyInput.forceActiveFocus(Qt.MouseFocusReason)
}
function validate() {
keyValidationError = ""
if (keyInput.text === "") {
keyValidationError = qsTr("You need to enter a key")
}
return !keyValidationError
}
title: qsTr("Import a community")
Input {
id: keyInput
label: qsTr("Community key")
placeholderText: qsTr("0x...")
validationError: popup.keyValidationError
}
footer: StatusButton {
text: qsTr("Import")
anchors.right: parent.right
onClicked: {
if (!validate()) {
return
}
let communityKey = keyInput.text
if (!communityKey.startsWith("0x")) {
communityKey = "0x" + communityKey
}
const error = chatsModel.importCommunity(communityKey)
if (error) {
creatingError.text = error
return creatingError.open()
}
// popup.close()
}
MessageDialog {
id: creatingError
title: qsTr("Error importing the community")
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
}
}

View File

@ -71,6 +71,15 @@ Item {
}
}
Component {
id: importCommunitiesPopupComponent
ImportCommunityPopup {
onClosed: {
destroy()
}
}
}
Component {
id: communityDetailPopup
CommunityDetailPopup {

View File

@ -177,6 +177,7 @@ DISTFILES += \
app/AppLayouts/Chat/CommunityComponents/CommunityWelcomeBanner.qml \
app/AppLayouts/Chat/CommunityComponents/CreateChannelPopup.qml \
app/AppLayouts/Chat/CommunityComponents/CreateCommunityPopup.qml \
app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml \
app/AppLayouts/Chat/CommunityComponents/InviteFriendsToCommunityPopup.qml \
app/AppLayouts/Chat/ContactsColumn/AddChat.qml \
app/AppLayouts/Chat/ContactsColumn/ClosedEmptyView.qml \