From a90a30af118d851fdd256ae568dc23280ba15371 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 18 Dec 2020 15:55:33 -0500 Subject: [PATCH] add import for a community --- src/app/chat/view.nim | 6 ++ src/status/chat.nim | 5 +- src/status/libstatus/chat.nim | 6 +- .../CommunityComponents/CommunitiesPopup.qml | 27 +++++-- .../ImportCommunityPopup.qml | 71 +++++++++++++++++++ ui/app/AppLayouts/Chat/ContactsColumn.qml | 9 +++ ui/nim-status-client.pro | 1 + 7 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 ui/app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 12bef2e779..3a422fe0ea 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -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 \ No newline at end of file diff --git a/src/status/chat.nim b/src/status/chat.nim index 9a80dca21f..02733a1e3a 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -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) \ No newline at end of file + result = status_chat.exportCommunity(communityId) + +proc importCommunity*(self: ChatModel, communityKey: string) = + status_chat.importCommunity(communityKey) \ No newline at end of file diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index c9fe5f3f22..4109c57320 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -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 \ No newline at end of file + result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr + +proc importCommunity*(communityKey: string) = + let res = callPrivateRPC("importCommunity".prefix, %*[communityKey]) + debug "RESULT", res \ No newline at end of file diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunitiesPopup.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunitiesPopup.qml index b344f7164b..1e5a7391b6 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunitiesPopup.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunitiesPopup.qml @@ -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() + } } } } diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml b/ui/app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml new file mode 100644 index 0000000000..45fa6219ef --- /dev/null +++ b/ui/app/AppLayouts/Chat/CommunityComponents/ImportCommunityPopup.qml @@ -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 + } + } +} + diff --git a/ui/app/AppLayouts/Chat/ContactsColumn.qml b/ui/app/AppLayouts/Chat/ContactsColumn.qml index fb2be21176..09d3757a13 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn.qml @@ -71,6 +71,15 @@ Item { } } + Component { + id: importCommunitiesPopupComponent + ImportCommunityPopup { + onClosed: { + destroy() + } + } + } + Component { id: communityDetailPopup CommunityDetailPopup { diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index cd796aea65..903ae8d35a 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -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 \