From 82405cc425be4deab90a7cb3dbd8fae3686e8ca0 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 18 Dec 2020 15:15:00 -0500 Subject: [PATCH] add export function and button --- src/app/chat/view.nim | 9 +++- src/status/chat.nim | 5 +- src/status/libstatus/chat.nim | 5 +- .../CommunityProfilePopup.qml | 47 ++++++++++++++++++- 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 1321154f1d..12bef2e779 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -714,4 +714,11 @@ QtObject: self.status.chat.inviteUserToCommunity(self.activeCommunity.id(), pubKey) except Exception as e: error "Error inviting to the community", msg = e.msg - result = fmt"Error inviting to the community: {e.msg}" \ No newline at end of file + result = fmt"Error inviting to the community: {e.msg}" + + proc exportComumnity*(self: ChatsView): string {.slot.} = + try: + result = self.status.chat.exportCommunity(self.activeCommunity.communityItem.id) + except Exception as e: + error "Error exporting the community", msg = e.msg + result = fmt"Error exporting the community: {e.msg}" diff --git a/src/status/chat.nim b/src/status/chat.nim index 1967280bca..9a80dca21f 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -396,4 +396,7 @@ proc leaveCommunity*(self: ChatModel, communityId: string) = proc inviteUserToCommunity*(self: ChatModel, communityId: string, pubKey: string) = status_chat.inviteUserToCommunity(communityId, pubKey) # After sending the invite, we send a message with the community ID so they can join - self.sendMessage(pubKey, "Upgrade here to see an invitation to community", "", ContentType.Community.int, communityId) \ No newline at end of file + 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 diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index 3c95a09d92..c9fe5f3f22 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -300,4 +300,7 @@ proc leaveCommunity*(communityId: string) = proc inviteUserToCommunity*(communityId: string, pubKey: string) = let res = callPrivateRPC("inviteUserToCommunity".prefix, %*[communityId, pubKey])#.parseJSON()["result"] - debug "RESULT", res \ No newline at end of file + debug "RESULT", res + +proc exportCommunity*(communityId: string):string = + result = callPrivateRPC("exportCommunity".prefix, %*[communityId]).parseJson()["result"].getStr \ No newline at end of file diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopup.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopup.qml index ba6eabeddc..1820468598 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopup.qml @@ -17,7 +17,7 @@ ModalPopup { property string source: "../../../img/ens-header-dark@2x.png" property int nbMembers: community.nbMembers property bool isAdmin: true // TODO: - height: isAdmin ? 627 : 509 + height: isAdmin ? 640 : 509 id: popup @@ -181,6 +181,7 @@ ModalPopup { } } } + CommunityPopupButton { id: notificationsBtn label: qsTr("Notifications") @@ -199,9 +200,11 @@ ModalPopup { } } } + Separator { width: parent.width } + Loader { active: isAdmin width: parent.width @@ -217,10 +220,52 @@ ModalPopup { } } } + + Loader { + property string exportResult: "" + + active: isAdmin + width: parent.width + sourceComponent: !exportResult ? exportBtn : resultComponent + + Component { + id: exportBtn + CommunityPopupButton { + label: qsTr("Export community") + iconName: "../fetch" + onClicked: exportResult = chatsModel.exportComumnity() + } + } + + Component { + id: resultComponent + StyledText { + property bool isError: !exportResult.startsWith("0x") + + text: exportResult + color: isError ? Style.current.danger : Style.current.textColor + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: Style.current.smallPadding + copyToClipboardBtn.width + wrapMode: TextEdit.WrapAnywhere + + CopyToClipBoardButton { + id: copyToClipboardBtn + visible: !isError + textToCopy: exportResult + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.right + anchors.leftMargin: Style.current.smallPadding + } + } + } + } + CommunityPopupButton { label: qsTr("Leave community") iconName: "leave" } + Loader { active: isAdmin width: parent.width