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
This commit is contained in:
Igor Sirotin 2023-10-26 14:58:05 +01:00 committed by GitHub
parent c22dc23ce0
commit 9881c15f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 128 deletions

View File

@ -786,12 +786,12 @@ QtObject:
proc asyncContactInfoLoaded*(self: Service, pubkeyAndRpcResponse: string) {.slot.} = proc asyncContactInfoLoaded*(self: Service, pubkeyAndRpcResponse: string) {.slot.} =
let rpcResponseObj = pubkeyAndRpcResponse.parseJson let rpcResponseObj = pubkeyAndRpcResponse.parseJson
let publicKey = $rpcResponseObj{"publicKey"} let publicKey = rpcResponseObj{"publicKey"}.getStr
let requestError = rpcResponseObj{"error"} let requestError = rpcResponseObj{"error"}
var error : string var error : string
if requestError.kind != JNull: if requestError.kind != JNull:
error = $requestError error = requestError.getStr
else: else:
let responseError = rpcResponseObj{"response"}{"error"} let responseError = rpcResponseObj{"response"}{"error"}
if responseError.kind != JNull: if responseError.kind != JNull:

View File

@ -25,10 +25,9 @@ QtObject:
proc parseSharedUrl*(self: Service, url: string): UrlDataDto = proc parseSharedUrl*(self: Service, url: string): UrlDataDto =
try: try:
let response = status_general.parseSharedUrl(url) let response = status_general.parseSharedUrl(url)
if(response.result.contains("error")): if not response.result.contains("error"):
let errMsg = response.result["error"].getStr() return response.result.toUrlDataDto()
error "error while pasring shared url: ", errDesription = errMsg let errMsg = response.result["error"].getStr()
return error "failed to parse shared url: ", url, errDesription = errMsg
return response.result.toUrlDataDto()
except Exception as e: except Exception as e:
error "error while parsing shared url: ", msg = e.msg error "failed to parse shared url: ", url, errDesription = e.msg

View File

@ -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() { function getPubkey() {
return userProfile.getPubKey() return userProfile.getPubKey()
} }

View File

@ -63,17 +63,18 @@ MembersSelectorBase {
property ListModel selectedMembers: ListModel {} property ListModel selectedMembers: ListModel {}
function lookupContact(value) { function lookupContact(value) {
let contactObj = Utils.parseContactUrl(value) const urlContactData = Utils.parseContactUrl(value)
if (urlContactData) {
if (contactObj) { // Ignore all the data from the link, because it might be malformed.
processContact(contactObj) // Except for the publicKey.
processContact(urlContactData.publicKey)
return return
} }
value = Utils.dropUserLinkPrefix(value.trim()) value = Utils.dropUserLinkPrefix(value.trim())
if (Utils.isChatKey(value)) { if (Utils.isChatKey(value)) {
processContact({publicKey: value}) processContact(value)
return return
} }
@ -85,12 +86,11 @@ MembersSelectorBase {
root.suggestionsDialog.forceHide = false root.suggestionsDialog.forceHide = false
} }
function processContact(contactData) { function processContact(publicKey) {
const contactDetails = Utils.getContactDetailsAsJson(contactData.publicKey, false) const contactDetails = Utils.getContactDetailsAsJson(publicKey, false)
if (contactDetails.publicKey === "") { if (contactDetails.publicKey === "") {
// not a valid key given // not a valid key given
root.suggestionsDialog.forceHide = false root.suggestionsDialog.forceHide = false
return return
} }
@ -101,31 +101,22 @@ MembersSelectorBase {
return return
} }
let hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey) const hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey)
if ((root.model.count === 0 && hasPendingContactRequest) || if ((root.model.count === 0 && hasPendingContactRequest) ||
contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey || contactDetails.isBlocked) { contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey || contactDetails.isBlocked) {
// List is empty and we have a contact request // List is empty and we have a contact request
// OR it's our own chat key or a banned user // OR it's our own chat key or a banned user
// Then open the contact's profile popup // 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 return
} }
if (root.model.count === 0 && !hasPendingContactRequest) { if (root.model.count === 0 && !hasPendingContactRequest) {
// List is empty and not a contact yet. Open the contact request popup // List is empty and not a contact yet. Open the contact request popup
Global.openContactRequestPopup(contactDetails.publicKey,
// If `displayName` is not undefined and not empty, popup => popup.closed.connect(root.rejected))
// 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))
}
return return
} }
@ -174,7 +165,7 @@ MembersSelectorBase {
root.suggestionsDialog.forceHide = false root.suggestionsDialog.forceHide = false
return return
} }
d.processContact({publicKey: resolvedPubKey}) d.processContact(resolvedPubKey)
} }
} }
} }

View File

@ -42,7 +42,6 @@ QtObject {
Global.openIncomingIDRequestPopup.connect(openIncomingIDRequestPopup) Global.openIncomingIDRequestPopup.connect(openIncomingIDRequestPopup)
Global.openInviteFriendsToCommunityPopup.connect(openInviteFriendsToCommunityPopup) Global.openInviteFriendsToCommunityPopup.connect(openInviteFriendsToCommunityPopup)
Global.openContactRequestPopup.connect(openContactRequestPopup) Global.openContactRequestPopup.connect(openContactRequestPopup)
Global.openContactRequestPopupWithContactData.connect(openContactRequestPopupWithContactData)
Global.openChooseBrowserPopup.connect(openChooseBrowserPopup) Global.openChooseBrowserPopup.connect(openChooseBrowserPopup)
Global.openDownloadModalRequested.connect(openDownloadModal) Global.openDownloadModalRequested.connect(openDownloadModal)
Global.openImagePopup.connect(openImagePopup) Global.openImagePopup.connect(openImagePopup)
@ -202,14 +201,6 @@ QtObject {
openPopup(sendContactRequestPopupComponent, popupProperties, cb) 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) { function openPinnedMessagesPopup(store, messageStore, pinnedMessagesModel, messageToPin, chatId) {
openPopup(pinnedMessagesPopup, { openPopup(pinnedMessagesPopup, {
store: store, store: store,

View File

@ -66,9 +66,10 @@ StatusDialog {
target: root.rootStore.contactStore.contactsModule target: root.rootStore.contactStore.contactsModule
function onContactInfoRequestFinished(publicKey, ok) { function onContactInfoRequestFinished(publicKey, ok) {
if (ok && publicKey === root.userPublicKey) { if (publicKey !== root.userPublicKey)
d.contactDetails = Utils.getContactDetailsAsJson(userPublicKey, false) return
} if (ok)
d.contactDetails = Utils.getContactDetailsAsJson(root.userPublicKey, false)
d.loadingContactDetails = false d.loadingContactDetails = false
} }
} }

View File

@ -38,7 +38,6 @@ QtObject {
signal openActivityCenterPopupRequested() signal openActivityCenterPopupRequested()
signal openSendIDRequestPopup(string publicKey, var cb) signal openSendIDRequestPopup(string publicKey, var cb)
signal openContactRequestPopup(string publicKey, var cb) signal openContactRequestPopup(string publicKey, var cb)
signal openContactRequestPopupWithContactData(var contactData, var cb)
signal removeContactRequested(string displayName, string publicKey) signal removeContactRequested(string displayName, string publicKey)
signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb) signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb)
signal openIncomingIDRequestPopup(string publicKey, var cb) signal openIncomingIDRequestPopup(string publicKey, var cb)

View File

@ -535,22 +535,19 @@ QtObject {
} }
function getCommunityDataFromSharedLink(link) { function getCommunityDataFromSharedLink(link) {
let index = link.lastIndexOf("/c/") const index = link.lastIndexOf("/c/")
if (index === -1) { if (index === -1)
return null return null
}
let communityDataString = sharedUrlsModuleInst.parseCommunitySharedUrl(link) const communityDataString = sharedUrlsModuleInst.parseCommunitySharedUrl(link)
try { try {
let communityData = JSON.parse(communityDataString) return JSON.parse(communityDataString)
return communityData
} catch (e) { } catch (e) {
console.warn("Error while parsing community data from url:", e.message) console.warn("Error while parsing community data from url:", e.message)
return null return null
} }
} }
function changeCommunityKeyCompression(communityKey) { function changeCommunityKeyCompression(communityKey) {
return globalUtilsInst.changeCommunityKeyCompression(communityKey) return globalUtilsInst.changeCommunityKeyCompression(communityKey)
} }
@ -701,15 +698,13 @@ QtObject {
} }
function parseContactUrl(link) { function parseContactUrl(link) {
let index = link.lastIndexOf("/u/") const index = link.lastIndexOf("/u/")
if (index === -1) { if (index === -1)
return null return null
}
let contactDataString = sharedUrlsModuleInst.parseContactSharedUrl(link) const contactDataString = sharedUrlsModuleInst.parseContactSharedUrl(link)
try { try {
let contactObj = JSON.parse(contactDataString) return JSON.parse(contactDataString)
return contactObj
} catch (e) { } catch (e) {
return null return null
} }