From c3c74b9f6193486fd81911e9315ff48dc741ef52 Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Thu, 6 Jul 2023 14:26:30 +0300 Subject: [PATCH] feat(new-links-format): Adds new links to UI Part of: #10852 --- .../modules/main/communities/controller.nim | 12 +++++++++ .../modules/main/communities/io_interface.nim | 12 +++++++++ src/app/modules/main/communities/module.nim | 14 +++++++++- src/app/modules/main/communities/view.nim | 12 +++++++++ .../profile_section/contacts/controller.nim | 11 +++++++- .../profile_section/contacts/io_interface.nim | 9 +++++++ .../main/profile_section/contacts/module.nim | 9 +++++++ .../main/profile_section/contacts/view.nim | 9 +++++++ src/app_service/service/community/service.nim | 27 +++++++++++++++++++ src/app_service/service/contacts/service.nim | 21 +++++++++++++++ src/backend/communities.nim | 18 +++++++++++++ src/backend/contacts.nim | 11 +++++++- .../Profile/stores/ContactsStore.qml | 4 +++ ui/imports/shared/views/ProfileDialogView.qml | 11 +------- ui/imports/utils/Utils.qml | 10 +++---- 15 files changed, 170 insertions(+), 20 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index e1aef1ad2c..7494849344 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -260,3 +260,15 @@ proc getNetwork*(self:Controller, chainId: int): NetworkDto = proc getTokenList*(self: Controller): seq[TokenDto] = return self.tokenService.getTokenList() + +proc shareCommunityUrlWithChatKey*(self: Controller, communityId: string): string = + return self.communityService.shareCommunityUrlWithChatKey(communityId) + +proc shareCommunityUrlWithData*(self: Controller, communityId: string): string = + return self.communityService.shareCommunityUrlWithData(communityId) + +proc shareCommunityChannelUrlWithChatKey*(self: Controller, communityId: string, chatId: string): string = + return self.communityService.shareCommunityChannelUrlWithChatKey(communityId, chatId) + +proc shareCommunityChannelUrlWithData*(self: Controller, communityId: string, chatId: string): string = + return self.communityService.shareCommunityChannelUrlWithData(communityId, chatId) \ No newline at end of file diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index e936863fbd..6c44b9c189 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -159,3 +159,15 @@ method onOwnedCollectiblesUpdated*(self: AccessInterface) {.base.} = method onWalletAccountTokensRebuilt*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") + +method shareCommunityUrlWithChatKey*(self: AccessInterface, communityId: string): string {.base.} = + raise newException(ValueError, "No implementation available") + +method shareCommunityUrlWithData*(self: AccessInterface, communityId: string): string {.base.} = + raise newException(ValueError, "No implementation available") + +method shareCommunityChannelUrlWithChatKey*(self: AccessInterface, communityId: string, chatId: string): string {.base.} = + raise newException(ValueError, "No implementation available") + +method shareCommunityChannelUrlWithData*(self: AccessInterface, communityId: string, chatId: string): string {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 0ffc7ddec4..b2c196afb9 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -448,4 +448,16 @@ method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMe if tokenMetadata.tokenType == community_dto.TokenType.ERC20 and not self.view.tokenListModel().hasItem(tokenMetadata.symbol): - self.view.tokenListModel.addItems(@[tokenListItem]) \ No newline at end of file + self.view.tokenListModel.addItems(@[tokenListItem]) + +method shareCommunityUrlWithChatKey*(self: Module, communityId: string): string = + return self.controller.shareCommunityUrlWithChatKey(communityId) + +method shareCommunityUrlWithData*(self: Module, communityId: string): string = + return self.controller.shareCommunityUrlWithData(communityId) + +method shareCommunityChannelUrlWithChatKey*(self: Module, communityId: string, chatId: string): string = + return self.controller.shareCommunityChannelUrlWithChatKey(communityId, chatId) + +method shareCommunityChannelUrlWithData*(self: Module, communityId: string, chatId: string): string = + return self.controller.shareCommunityChannelUrlWithData(communityId, chatId) \ No newline at end of file diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 61af3ac311..22d5caf772 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -586,3 +586,15 @@ QtObject: proc setCollectiblesListItems*(self: View, tokenListItems: seq[TokenListItem]) = self.collectiblesListModel.setItems(tokenListItems) + + proc shareCommunityUrlWithChatKey*(self: View, communityId: string): string {.slot.} = + return self.delegate.shareCommunityUrlWithChatKey(communityId) + + proc shareCommunityUrlWithData*(self: View, communityId: string): string {.slot.} = + return self.delegate.shareCommunityUrlWithData(communityId) + + proc shareCommunityChannelUrlWithChatKey*(self: View, communityId: string, chatId: string): string {.slot.} = + return self.delegate.shareCommunityChannelUrlWithChatKey(communityId, chatId) + + proc shareCommunityChannelUrlWithData*(self: View, communityId: string, chatId: string): string {.slot.} = + return self.delegate.shareCommunityChannelUrlWithData(communityId, chatId) diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index 412defb6a1..d64dc4915d 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -163,4 +163,13 @@ proc getStatusForContactWithId*(self: Controller, publicKey: string): StatusUpda return self.contactsService.getStatusForContactWithId(publicKey) proc requestContactInfo*(self: Controller, publicKey: string) = - self.contactsService.requestContactInfo(publicKey) \ No newline at end of file + self.contactsService.requestContactInfo(publicKey) + +proc shareUserUrlWithData*(self: Controller, pubkey: string): string = + self.contactsService.shareUserUrlWithData(pubkey) + +proc shareUserUrlWithChatKey*(self: Controller, pubkey: string): string = + self.contactsService.shareUserUrlWithChatKey(pubkey) + +proc shareUserUrlWithENS*(self: Controller, pubkey: string): string = + self.contactsService.shareUserUrlWithENS(pubkey) diff --git a/src/app/modules/main/profile_section/contacts/io_interface.nim b/src/app/modules/main/profile_section/contacts/io_interface.nim index db89819033..3d6c1d7dfb 100644 --- a/src/app/modules/main/profile_section/contacts/io_interface.nim +++ b/src/app/modules/main/profile_section/contacts/io_interface.nim @@ -123,4 +123,13 @@ method requestContactInfo*(self: AccessInterface, publicKey: string) {.base.} = raise newException(ValueError, "No implementation available") method onContactInfoRequestFinished*(self: AccessInterface, publicKey: string, ok: bool) {.base.} = + raise newException(ValueError, "No implementation available") + +method shareUserUrlWithData*(self: AccessInterface, pubkey: string): string {.base.} = + raise newException(ValueError, "No implementation available") + +method shareUserUrlWithChatKey*(self: AccessInterface, pubkey: string): string {.base.} = + raise newException(ValueError, "No implementation available") + +method shareUserUrlWithENS*(self: AccessInterface, pubkey: string): string {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 15186e1639..43183a5c9d 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -280,3 +280,12 @@ method requestContactInfo*(self: Module, publicKey: string) = method onContactInfoRequestFinished*(self: Module, publicKey: string, ok: bool) = self.view.onContactInfoRequestFinished(publicKey, ok) + +method shareUserUrlWithData*(self: Module, pubkey: string): string = + return self.controller.shareUserUrlWithData(pubkey) + +method shareUserUrlWithChatKey*(self: Module, pubkey: string): string = + return self.controller.shareUserUrlWithChatKey(pubkey) + +method shareUserUrlWithENS*(self: Module, pubkey: string): string = + return self.controller.shareUserUrlWithENS(pubkey) diff --git a/src/app/modules/main/profile_section/contacts/view.nim b/src/app/modules/main/profile_section/contacts/view.nim index 9e89e852a8..5132253eed 100644 --- a/src/app/modules/main/profile_section/contacts/view.nim +++ b/src/app/modules/main/profile_section/contacts/view.nim @@ -179,6 +179,15 @@ QtObject: proc verifiedUntrustworthy*(self: View, publicKey: string) {.slot.} = self.delegate.verifiedUntrustworthy(publicKey) + proc shareUserUrlWithData*(self: View, pubkey: string): string {.slot.} = + return self.delegate.shareUserUrlWithData(pubkey) + + proc shareUserUrlWithChatKey*(self: View, pubkey: string): string {.slot.} = + return self.delegate.shareUserUrlWithChatKey(pubkey) + + proc shareUserUrlWithENS*(self: View, pubkey: string): string {.slot.} = + return self.delegate.shareUserUrlWithENS(pubkey) + proc declineVerificationRequest*(self: View, publicKey: string) {.slot.} = self.delegate.declineVerificationRequest(publicKey) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 18b701d5ce..0b42188358 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1865,3 +1865,30 @@ QtObject: let community = self.getCommunityById(communityId) return community.channelPermissions.channels.hasKey(chatId) and not community.channelPermissions.channels[chatId].viewAndPostPermissions.satisfied + proc shareCommunityUrlWithChatKey*(self: Service, communityId: string): string = + try: + let response = status_go.shareCommunityUrlWithChatKey(communityId) + return response.result.getStr + except Exception as e: + error "error while getting community url with chat key", msg = e.msg + + proc shareCommunityUrlWithData*(self: Service, communityId: string): string = + try: + let response = status_go.shareCommunityUrlWithData(communityId) + return response.result.getStr + except Exception as e: + error "error while getting community url with data", msg = e.msg + + proc shareCommunityChannelUrlWithChatKey*(self: Service, communityId: string, chatId: string): string = + try: + let response = status_go.shareCommunityChannelUrlWithChatKey(communityId, chatId) + return response.result.getStr + except Exception as e: + error "error while getting community channel url with chat key ", msg = e.msg + + proc shareCommunityChannelUrlWithData*(self: Service, communityId: string, chatId: string): string = + try: + let response = status_go.shareCommunityChannelUrlWithData(communityId, chatId) + return response.result.getStr + except Exception as e: + error "error while getting community channel url with data ", msg = e.msg diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 6e01203156..a4451047ce 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -816,3 +816,24 @@ QtObject: self.threadpool.start(arg) except Exception as e: error "Error requesting contact info", msg = e.msg, pubkey + + proc shareUserUrlWithData*(self: Service, pubkey: string): string = + try: + let response = status_contacts.shareUserUrlWithData(pubkey) + return response.result.getStr + except Exception as e: + error "Error getting user url with data", msg = e.msg, pubkey + + proc shareUserUrlWithChatKey*(self: Service, pubkey: string): string = + try: + let response = status_contacts.shareUserUrlWithChatKey(pubkey) + return response.result.getStr + except Exception as e: + error "Error getting user url with chat key", msg = e.msg, pubkey + + proc shareUserUrlWithENS*(self: Service, pubkey: string): string = + try: + let response = status_contacts.shareUserUrlWithENS(pubkey) + return response.result.getStr + except Exception as e: + error "Error getting user url with ens name", msg = e.msg, pubkey diff --git a/src/backend/communities.nim b/src/backend/communities.nim index aedc3695c7..7a2a95a4ea 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -397,6 +397,24 @@ proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string], inviteMes "inviteMessage": inviteMessage }]) +proc shareCommunityUrlWithChatKey*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + return callPrivateRPC("shareCommunityURLWithChatKey".prefix, %*[communityId]) + +proc shareCommunityUrlWithData*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + return callPrivateRPC("shareCommunityURLWithData".prefix, %*[communityId]) + +proc shareCommunityChannelUrlWithChatKey*(communityId: string, channelId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + return callPrivateRPC("shareCommunityChannelURLWithChatKey".prefix, %*[{ + "communityId": communityId, + "channelId": channelId + }]) + +proc shareCommunityChannelUrlWithData*(communityId: string, channelId: string): RpcResponse[JsonNode] {.raises: [Exception].} = + return callPrivateRPC("shareCommunityChannelURLWithData".prefix, %*[{ + "communityId": communityId, + "channelId": channelId + }]) + proc getCommunitiesSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} = return callPrivateRPC("getCommunitiesSettings".prefix, %*[]) diff --git a/src/backend/contacts.nim b/src/backend/contacts.nim index 2be2f72c73..787e586582 100644 --- a/src/backend/contacts.nim +++ b/src/backend/contacts.nim @@ -126,4 +126,13 @@ proc retractContactRequest*(pubkey: string): RpcResponse[JsonNode] {.raises: [Ex result = callPrivateRPC("retractContactRequest".prefix, payload) proc requestContactInfo*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} = - result = callPrivateRPC("requestContactInfoFromMailserver".prefix, %*[pubkey]) \ No newline at end of file + result = callPrivateRPC("requestContactInfoFromMailserver".prefix, %*[pubkey]) + +proc shareUserUrlWithData*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} = + result = callPrivateRPC("shareUserURLWithData".prefix, %*[pubkey]) + +proc shareUserUrlWithChatKey*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} = + result = callPrivateRPC("shareUserURLWithChatKey".prefix, %*[pubkey]) + +proc shareUserUrlWithENS*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} = + result = callPrivateRPC("shareUserURLWithENS".prefix, %*[pubkey]) \ No newline at end of file diff --git a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml index a7d04c6d84..e27d8f52dd 100644 --- a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml @@ -126,4 +126,8 @@ QtObject { function getContactPublicKeyByAddress(address) { return "" // TODO retrive contact public key from address } + + function getLinkToProfile(publicKey) { + return root.contactsModule.shareUserUrlWithData(publicKey) + } } diff --git a/ui/imports/shared/views/ProfileDialogView.qml b/ui/imports/shared/views/ProfileDialogView.qml index bf7b26882f..d423a48c89 100644 --- a/ui/imports/shared/views/ProfileDialogView.qml +++ b/ui/imports/shared/views/ProfileDialogView.qml @@ -82,16 +82,7 @@ Pane { incomingVerificationStatus === Constants.verificationStatus.trusted readonly property bool isVerified: outgoingVerificationStatus === Constants.verificationStatus.verified - readonly property string linkToProfile: { - let user = "" - if (d.isCurrentUser) - user = root.profileStore.preferredName - else - user = contactDetails.name - if (!user) - user = Utils.getCompressedPk(root.publicKey) - return Constants.userLinkPrefix + user - } + readonly property string linkToProfile: root.contactsStore.getLinkToProfile(root.publicKey) readonly property var conns: Connections { target: root.contactsStore.myContactsModel ?? null diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index f275e217db..8709348d22 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -11,6 +11,7 @@ import StatusQ.Core.Utils 0.1 as StatusQUtils QtObject { property var mainModuleInst: typeof mainModule !== "undefined" ? mainModule : null property var globalUtilsInst: typeof globalUtils !== "undefined" ? globalUtils : null + property var communitiesModuleInst: typeof communitiesModule !== "undefined" ? communitiesModule : null readonly property int maxImgSizeBytes: Constants.maxUploadFilesizeMB * 1048576 /* 1 MB in bytes */ @@ -485,17 +486,12 @@ QtObject { return colorForColorId(pubKeyColorId) } - function getCommunityShareLink(communityId, elided = false) { + function getCommunityShareLink(communityId) { if (communityId === "") { return "" } - let compressedPk = communityId - if (!globalUtilsInst.isCompressedPubKey(compressedPk)) { - compressedPk = globalUtilsInst.changeCommunityKeyCompression(compressedPk) - } - return Constants.communityLinkPrefix + - (elided ? StatusQUtils.Utils.elideText(compressedPk, 4, 2) : compressedPk) + return communitiesModuleInst.shareCommunityUrlWithData(communityId) } function getChatKeyFromShareLink(link) {