From 395d5548b4ecc955bbb5b64970d97c1ee36c9cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Wed, 17 Aug 2022 14:44:53 +0200 Subject: [PATCH] feat(CreateCommunityPopup): Add Community Banner to Create Community Modal as status-go already supports parsing the banner JSON string, just pass it along the NIM backend Closes #6726 --- src/app/modules/main/communities/controller.nim | 6 ++++-- src/app/modules/main/communities/io_interface.nim | 2 +- src/app/modules/main/communities/module.nim | 5 +++-- src/app/modules/main/communities/view.nim | 6 +++--- src/app_service/service/community/service.nim | 6 ++++-- src/backend/communities.nim | 7 +++++-- ui/app/AppLayouts/Chat/stores/RootStore.qml | 5 +++-- .../CommunitiesPortal/popups/CreateCommunityPopup.qml | 8 +++++++- .../CommunitiesPortal/stores/CommunitiesStore.qml | 5 +++-- ui/app/AppLayouts/stores/RootStore.qml | 6 ++++-- ui/nim-status-client.pro | 1 + 11 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 53c2ce661b..429ab0b0b7 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -89,7 +89,8 @@ proc createCommunity*( imageUrl: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, - pinMessageAllMembersEnabled: bool) = + pinMessageAllMembersEnabled: bool, + bannerJsonStr: string) = self.communityService.createCommunity( name, description, @@ -101,7 +102,8 @@ proc createCommunity*( imageUrl, aX, aY, bX, bY, historyArchiveSupportEnabled, - pinMessageAllMembersEnabled) + pinMessageAllMembersEnabled, + bannerJsonStr) proc reorderCommunityChat*( self: Controller, diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index c8b2c39065..1307fdd5b0 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -30,7 +30,7 @@ method joinCommunity*(self: AccessInterface, communityId: string): string {.base method createCommunity*(self: AccessInterface, name: string, description, introMessage, outroMessage: string, access: int, color: string, tags: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, - historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool) {.base.} = + historyArchiveSupportEnabled: bool, pinMessageAllMembersEnabled: bool, bannerJsonStr: string) {.base.} = raise newException(ValueError, "No implementation available") method deleteCommunityCategory*(self: AccessInterface, communityId: string, categoryId: string) {.base.} = diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index bf1f7257b6..5287b73ad1 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -199,9 +199,10 @@ method createCommunity*(self: Module, name: string, imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, - pinMessageAllMembersEnabled: bool) = + pinMessageAllMembersEnabled: bool, + bannerJsonStr: string) = self.controller.createCommunity(name, description, introMessage, outroMessage, access, color, tags, - imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled) + imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, bannerJsonStr) method deleteCommunityCategory*(self: Module, communityId: string, categoryId: string) = self.controller.deleteCommunityCategory(communityId, categoryId) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 7214721f66..f76458fc54 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -101,9 +101,9 @@ QtObject: imagePath: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, - pinMessageAllMembersEnabled: bool) {.slot.} = + pinMessageAllMembersEnabled: bool, bannerJsonStr: string) {.slot.} = self.delegate.createCommunity(name, description, introMessage, outroMessage, access, color, tags, - imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled) + imagePath, aX, aY, bX, bY, historyArchiveSupportEnabled, pinMessageAllMembersEnabled, bannerJsonStr) proc deleteCommunityCategory*(self: View, communityId: string, categoryId: string): string {.slot.} = self.delegate.deleteCommunityCategory(communityId, categoryId) @@ -143,4 +143,4 @@ QtObject: let sectionItem = self.model.getItemById(communityId) if (section_item.id == ""): return false - return sectionItem.hasMember(pubKey) \ No newline at end of file + return sectionItem.hasMember(pubKey) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 0a5fca608c..52350f79fb 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -615,7 +615,8 @@ QtObject: imageUrl: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, - pinMessageAllMembersEnabled: bool) = + pinMessageAllMembersEnabled: bool, + bannerJsonStr: string) = try: var image = singletonInstance.utils.formatImagePath(imageUrl) var tagsString = tags @@ -633,7 +634,8 @@ QtObject: image, aX, aY, bX, bY, historyArchiveSupportEnabled, - pinMessageAllMembersEnabled) + pinMessageAllMembersEnabled, + bannerJsonStr) if response.error != nil: let error = Json.decode($response.error, RpcError) diff --git a/src/backend/communities.nim b/src/backend/communities.nim index d6b3dca3d9..dfc47639f6 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -57,8 +57,10 @@ proc createCommunity*( imageUrl: string, aX: int, aY: int, bX: int, bY: int, historyArchiveSupportEnabled: bool, - pinMessageAllMembersEnabled: bool + pinMessageAllMembersEnabled: bool, + bannerJsonStr: string ): RpcResponse[JsonNode] {.raises: [Exception].} = + let bannerImage = newCroppedImage(bannerJsonStr) result = callPrivateRPC("createCommunity".prefix, %*[{ # TODO this will need to be renamed membership (small m) "Membership": access, @@ -75,7 +77,8 @@ proc createCommunity*( "imageBx": bX, "imageBy": bY, "historyArchiveSupportEnabled": historyArchiveSupportEnabled, - "pinMessageAllMembersEnabled": pinMessageAllMembersEnabled + "pinMessageAllMembersEnabled": pinMessageAllMembersEnabled, + "banner": bannerImage }]) proc editCommunity*( diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 5fadaf1ef4..61ce3239ad 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -240,13 +240,14 @@ QtObject { historyArchiveSupportEnabled: false, checkedMembership: false, pinMessagesAllowedForMembers: false - } + }, + bannerJsonStr: "" }) { return communitiesModuleInst.createCommunity( args.name, args.description, args.introMessage, args.outroMessage, args.options.checkedMembership, args.color, args.tags, args.image.src, args.image.AX, args.image.AY, args.image.BX, args.image.BY, - args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers); + args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers, args.bannerJsonStr); } function importCommunity(communityKey) { diff --git a/ui/app/AppLayouts/CommunitiesPortal/popups/CreateCommunityPopup.qml b/ui/app/AppLayouts/CommunitiesPortal/popups/CreateCommunityPopup.qml index 029dcf8d18..efb2e21594 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/popups/CreateCommunityPopup.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/popups/CreateCommunityPopup.qml @@ -71,6 +71,11 @@ StatusStackModal { Layout.fillWidth: true } + CommunityBannerPicker { + id: bannerPicker + Layout.fillWidth: true + } + CommunityColorPicker { id: colorPicker onPick: root.replace(colorPanel) @@ -172,7 +177,8 @@ StatusStackModal { historyArchiveSupportEnabled: options.archiveSupportEnabled, checkedMembership: options.requestToJoinEnabled ? Constants.communityChatOnRequestAccess : Constants.communityChatPublicAccess, pinMessagesAllowedForMembers: options.pinMessagesEnabled - } + }, + bannerJsonStr: JSON.stringify({imagePath: String(bannerPicker.source).replace("file://", ""), cropRect: bannerPicker.cropRect}) }) if (error) { errorDialog.text = error.error diff --git a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml index fbbc08b72c..168b11bb90 100644 --- a/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/CommunitiesPortal/stores/CommunitiesStore.qml @@ -51,13 +51,14 @@ QtObject { historyArchiveSupportEnabled: false, checkedMembership: false, pinMessagesAllowedForMembers: false - } + }, + bannerJsonStr: "" }) { return communitiesModuleInst.createCommunity( args.name, args.description, args.introMessage, args.outroMessage, args.options.checkedMembership, args.color, args.tags, args.image.src, args.image.AX, args.image.AY, args.image.BX, args.image.BY, - args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers); + args.options.historyArchiveSupportEnabled, args.options.pinMessagesAllowedForMembers, args.bannerJsonStr); } function importCommunity(communityKey) { diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index bbf972af7f..27204ebdce 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -104,10 +104,12 @@ QtObject { } function createCommunity(communityName, communityDescription, checkedMembership, communityColor, communityTags, - communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY) { + communityImage, imageCropperModalaX, imageCropperModalaY, imageCropperModalbX, imageCropperModalbY, + historyArchiveSupportEnabled, pinMessagesAllowedForMembers, bannerJsonStr) { communitiesModuleInst.createCommunity(communityName, communityDescription, checkedMembership, communityColor, communityTags, communityImage, imageCropperModalaX, imageCropperModalaY, - imageCropperModalbX, imageCropperModalbY); + imageCropperModalbX, imageCropperModalbY, + historyArchiveSupportEnabled, pinMessagesAllowedForMembers, bannerJsonStr); } function copyToClipboard(text) { diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index 07901b6f31..c4aa47721d 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -23,6 +23,7 @@ TRANSLATIONS += \ OTHER_FILES += $$files("$$PWD/*.qml", true) OTHER_FILES += $$files("$$PWD/*.js", true) +OTHER_FILES += $$files("$$PWD/../src/*.nim", true) # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = $$PWD/imports \