From 9881c15f3cc1b6fe731b6cc80f66d3b537bd50e2 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Thu, 26 Oct 2023 14:58:05 +0100 Subject: [PATCH] Fix/issue 12356 no shared url data (#12557) * refactor service `parseSharedUrl` functino * drop unused RootStore functions * refactor Utils shared urls functions * fix(MembersSeectprView): ignore shared url data * drop `openContactRequestPopupWithContactData` * fix loading of data to popup --- src/app_service/service/contacts/service.nim | 4 +- .../service/shared_urls/service.nim | 11 ++- ui/app/AppLayouts/Chat/stores/RootStore.qml | 71 ------------------- .../Chat/views/MembersSelectorView.qml | 37 ++++------ ui/app/mainui/Popups.qml | 9 --- .../shared/popups/SendContactRequestModal.qml | 7 +- ui/imports/utils/Global.qml | 1 - ui/imports/utils/Utils.qml | 21 +++--- 8 files changed, 33 insertions(+), 128 deletions(-) diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 72d5657d2b..f7a6d9ed6d 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -786,12 +786,12 @@ QtObject: proc asyncContactInfoLoaded*(self: Service, pubkeyAndRpcResponse: string) {.slot.} = let rpcResponseObj = pubkeyAndRpcResponse.parseJson - let publicKey = $rpcResponseObj{"publicKey"} + let publicKey = rpcResponseObj{"publicKey"}.getStr let requestError = rpcResponseObj{"error"} var error : string if requestError.kind != JNull: - error = $requestError + error = requestError.getStr else: let responseError = rpcResponseObj{"response"}{"error"} if responseError.kind != JNull: diff --git a/src/app_service/service/shared_urls/service.nim b/src/app_service/service/shared_urls/service.nim index 6780be0392..07ea38ab3d 100644 --- a/src/app_service/service/shared_urls/service.nim +++ b/src/app_service/service/shared_urls/service.nim @@ -25,10 +25,9 @@ QtObject: proc parseSharedUrl*(self: Service, url: string): UrlDataDto = try: let response = status_general.parseSharedUrl(url) - if(response.result.contains("error")): - let errMsg = response.result["error"].getStr() - error "error while pasring shared url: ", errDesription = errMsg - return - return response.result.toUrlDataDto() + if not response.result.contains("error"): + return response.result.toUrlDataDto() + let errMsg = response.result["error"].getStr() + error "failed to parse shared url: ", url, errDesription = errMsg except Exception as e: - error "error while parsing shared url: ", msg = e.msg \ No newline at end of file + error "failed to parse shared url: ", url, errDesription = e.msg diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index 6441d4dfdd..afc2c8f688 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -465,77 +465,6 @@ QtObject { } } - function getLinkTitleAndCb(link) { - const result = { - title: "Status", - callback: null, - fetching: true, - communityData: null - } - - // User profile - // There is invitation bubble only for /c/ link for now - /*let index = link.indexOf("/u/") - if (index > -1) { - //const pk = link.substring(index + 3) - result.title = qsTr("Display user profile") - result.callback = function () { - mainModuleInst.activateStatusDeepLink(link) - } - return result - }*/ - - // Community - result.communityData = Utils.getCommunityDataFromSharedLink(link) - if(!result.communityData) return result - - const communityName = getSectionNameById(result.communityData.communityId) - if (!communityName) { - // Unknown community, fetch the info if possible - root.requestCommunityInfo(result.communityData.communityId) - - result.title = qsTr("Join the %1 community").arg(result.communityData.displayName) - return result - } - - result.title = qsTr("Join the %1 community").arg(communityName) - result.fetching = false - result.callback = function () { - const isUserMemberOfCommunity = isUserMemberOfCommunity(result.communityData.communityId) - if (isUserMemberOfCommunity) { - setActiveCommunity(result.communityData.communityId) - return - } - - const userCanJoin = userCanJoin(result.communityData.communityId) - // TODO find what to do when you can't join - if (userCanJoin) { - requestToJoinCommunityWithAuthentication(result.communityData.communityId, userProfileInst.preferredName) // FIXME what addresses to share? - } - } - return result - } - - function getLinkDataForStatusLinks(link) { - if (!Utils.isStatusDeepLink(link)) { - return - } - - const result = getLinkTitleAndCb(link) - - return { - site: Constants.externalStatusLinkWithHttps, - title: result.title, - communityData: result.communityData, - fetching: result.fetching, - thumbnailUrl: Style.png("status"), - contentType: "", - height: 0, - width: 0, - callback: result.callback - } - } - function getPubkey() { return userProfile.getPubKey() } diff --git a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml index 07f07821c1..1693ca9617 100644 --- a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml +++ b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml @@ -63,17 +63,18 @@ MembersSelectorBase { property ListModel selectedMembers: ListModel {} function lookupContact(value) { - let contactObj = Utils.parseContactUrl(value) - - if (contactObj) { - processContact(contactObj) + const urlContactData = Utils.parseContactUrl(value) + if (urlContactData) { + // Ignore all the data from the link, because it might be malformed. + // Except for the publicKey. + processContact(urlContactData.publicKey) return } value = Utils.dropUserLinkPrefix(value.trim()) if (Utils.isChatKey(value)) { - processContact({publicKey: value}) + processContact(value) return } @@ -85,12 +86,11 @@ MembersSelectorBase { root.suggestionsDialog.forceHide = false } - function processContact(contactData) { - const contactDetails = Utils.getContactDetailsAsJson(contactData.publicKey, false) + function processContact(publicKey) { + const contactDetails = Utils.getContactDetailsAsJson(publicKey, false) if (contactDetails.publicKey === "") { // not a valid key given root.suggestionsDialog.forceHide = false - return } @@ -101,31 +101,22 @@ MembersSelectorBase { return } - let hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey) + const hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey) if ((root.model.count === 0 && hasPendingContactRequest) || contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey || contactDetails.isBlocked) { // List is empty and we have a contact request // OR it's our own chat key or a banned user // Then open the contact's profile popup - Global.openProfilePopup(contactDetails.publicKey, null, popup => popup.closed.connect(root.rejected)) + Global.openProfilePopup(contactDetails.publicKey, null, + popup => popup.closed.connect(root.rejected)) return } if (root.model.count === 0 && !hasPendingContactRequest) { // List is empty and not a contact yet. Open the contact request popup - - // If `displayName` is not undefined and not empty, - // then we open the popup with given `contactData`, which probably came from URL. - if (contactData.displayName) { - // Open contact request if we have data from url - Global.openContactRequestPopupWithContactData(contactData, - popup => popup.closed.connect(root.rejected)) - - } else { - Global.openContactRequestPopup(contactDetails.publicKey, - popup => popup.closed.connect(root.rejected)) - } + Global.openContactRequestPopup(contactDetails.publicKey, + popup => popup.closed.connect(root.rejected)) return } @@ -174,7 +165,7 @@ MembersSelectorBase { root.suggestionsDialog.forceHide = false return } - d.processContact({publicKey: resolvedPubKey}) + d.processContact(resolvedPubKey) } } } diff --git a/ui/app/mainui/Popups.qml b/ui/app/mainui/Popups.qml index 5fd7f189e4..9a6a3d7a58 100644 --- a/ui/app/mainui/Popups.qml +++ b/ui/app/mainui/Popups.qml @@ -42,7 +42,6 @@ QtObject { Global.openIncomingIDRequestPopup.connect(openIncomingIDRequestPopup) Global.openInviteFriendsToCommunityPopup.connect(openInviteFriendsToCommunityPopup) Global.openContactRequestPopup.connect(openContactRequestPopup) - Global.openContactRequestPopupWithContactData.connect(openContactRequestPopupWithContactData) Global.openChooseBrowserPopup.connect(openChooseBrowserPopup) Global.openDownloadModalRequested.connect(openDownloadModal) Global.openImagePopup.connect(openImagePopup) @@ -202,14 +201,6 @@ QtObject { openPopup(sendContactRequestPopupComponent, popupProperties, cb) } - function openContactRequestPopupWithContactData(contactData, cb) { - const popupProperties = { - userPublicKey: contactData.publicKey, - contactDetails: { displayName: contactData.displayName } - } - openPopup(sendContactRequestPopupComponent, popupProperties, cb) - } - function openPinnedMessagesPopup(store, messageStore, pinnedMessagesModel, messageToPin, chatId) { openPopup(pinnedMessagesPopup, { store: store, diff --git a/ui/imports/shared/popups/SendContactRequestModal.qml b/ui/imports/shared/popups/SendContactRequestModal.qml index 3aae6d1a5a..ed31744c49 100644 --- a/ui/imports/shared/popups/SendContactRequestModal.qml +++ b/ui/imports/shared/popups/SendContactRequestModal.qml @@ -66,9 +66,10 @@ StatusDialog { target: root.rootStore.contactStore.contactsModule function onContactInfoRequestFinished(publicKey, ok) { - if (ok && publicKey === root.userPublicKey) { - d.contactDetails = Utils.getContactDetailsAsJson(userPublicKey, false) - } + if (publicKey !== root.userPublicKey) + return + if (ok) + d.contactDetails = Utils.getContactDetailsAsJson(root.userPublicKey, false) d.loadingContactDetails = false } } diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index f75814587c..134c466ea9 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -38,7 +38,6 @@ QtObject { signal openActivityCenterPopupRequested() signal openSendIDRequestPopup(string publicKey, var cb) signal openContactRequestPopup(string publicKey, var cb) - signal openContactRequestPopupWithContactData(var contactData, var cb) signal removeContactRequested(string displayName, string publicKey) signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb) signal openIncomingIDRequestPopup(string publicKey, var cb) diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 1bb2448aa8..7b03900b56 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -535,22 +535,19 @@ QtObject { } function getCommunityDataFromSharedLink(link) { - let index = link.lastIndexOf("/c/") - if (index === -1) { + const index = link.lastIndexOf("/c/") + if (index === -1) return null - } - let communityDataString = sharedUrlsModuleInst.parseCommunitySharedUrl(link) + const communityDataString = sharedUrlsModuleInst.parseCommunitySharedUrl(link) try { - let communityData = JSON.parse(communityDataString) - return communityData + return JSON.parse(communityDataString) } catch (e) { console.warn("Error while parsing community data from url:", e.message) return null } } - function changeCommunityKeyCompression(communityKey) { return globalUtilsInst.changeCommunityKeyCompression(communityKey) } @@ -701,15 +698,13 @@ QtObject { } function parseContactUrl(link) { - let index = link.lastIndexOf("/u/") - if (index === -1) { + const index = link.lastIndexOf("/u/") + if (index === -1) return null - } - let contactDataString = sharedUrlsModuleInst.parseContactSharedUrl(link) + const contactDataString = sharedUrlsModuleInst.parseContactSharedUrl(link) try { - let contactObj = JSON.parse(contactDataString) - return contactObj + return JSON.parse(contactDataString) } catch (e) { return null }