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.} =
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:

View File

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

View File

@ -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)
}
}
}

View File

@ -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,

View File

@ -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
}
}

View File

@ -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)

View File

@ -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
}