fix(link-message): fix link unfurling display and height

Fixes #4608
This commit is contained in:
Jonathan Rainville 2022-02-10 15:02:02 -05:00
parent 306471be60
commit 426b230b3a
4 changed files with 89 additions and 89 deletions

View File

@ -41,6 +41,7 @@ QtObject {
// property var profileModelInst: profileModel
property var contactStore: profileSectionStore.contactsStore
property var privacyStore: profileSectionStore.privacyStore
property bool hasAddedContacts: contactStore.myContactsModel.count > 0
property var assets: walletSectionAccountTokens.model

View File

@ -826,56 +826,51 @@ Item {
}
Component.onCompleted: {
// Since https://github.com/status-im/status-desktop/commit/93668ff75
// we're hiding the setting to change appearance for compact normal mode
// of the UI. For now, compact mode is the new default.
const whitelist = appMain.rootStore.privacyStore.getLinkPreviewWhitelist()
try {
const whiteListedSites = JSON.parse(whitelist)
let settingsUpdated = false
// Not Refactored Yet
// const whitelist = profileModel.getLinkPreviewWhitelist()
// try {
// const whiteListedSites = JSON.parse(whitelist)
// let settingsUpdated = false
// Add Status links to whitelist
whiteListedSites.push({title: "Status", address: Constants.deepLinkPrefix, imageSite: false})
whiteListedSites.push({title: "Status", address: Constants.joinStatusLink, imageSite: false})
let settings = localAccountSensitiveSettings.whitelistedUnfurlingSites
// // Add Status links to whitelist
// whiteListedSites.push({title: "Status", address: Constants.deepLinkPrefix, imageSite: false})
// whiteListedSites.push({title: "Status", address: Constants.joinStatusLink, imageSite: false})
// let settings = localAccountSensitiveSettings.whitelistedUnfurlingSites
if (!settings) {
settings = {}
}
// if (!settings) {
// settings = {}
// }
// Set Status links as true. We intercept thoseURLs so it is privacy-safe
if (!settings[Constants.deepLinkPrefix] || !settings[Constants.joinStatusLink]) {
settings[Constants.deepLinkPrefix] = true
settings[Constants.joinStatusLink] = true
settingsUpdated = true
}
// // Set Status links as true. We intercept thoseURLs so it is privacy-safe
// if (!settings[Constants.deepLinkPrefix] || !settings[Constants.joinStatusLink]) {
// settings[Constants.deepLinkPrefix] = true
// settings[Constants.joinStatusLink] = true
// settingsUpdated = true
// }
const whitelistedHostnames = []
// const whitelistedHostnames = []
// // Add whitelisted sites in to app settings that are not already there
// whiteListedSites.forEach(site => {
// if (!settings.hasOwnProperty(site.address)) {
// settings[site.address] = false
// settingsUpdated = true
// }
// whitelistedHostnames.push(site.address)
// })
// // Remove any whitelisted sites from app settings that don't exist in the
// // whitelist from status-go
// Object.keys(settings).forEach(settingsHostname => {
// if (!whitelistedHostnames.includes(settingsHostname)) {
// delete settings[settingsHostname]
// settingsUpdated = true
// }
// })
// if (settingsUpdated) {
// localAccountSensitiveSettings.whitelistedUnfurlingSites = settings
// }
// } catch (e) {
// console.error('Could not parse the whitelist for sites', e)
// }
// Add whitelisted sites in to app settings that are not already there
whiteListedSites.forEach(site => {
if (!settings.hasOwnProperty(site.address)) {
settings[site.address] = false
settingsUpdated = true
}
whitelistedHostnames.push(site.address)
})
// Remove any whitelisted sites from app settings that don't exist in the
// whitelist from status-go
Object.keys(settings).forEach(settingsHostname => {
if (!whitelistedHostnames.includes(settingsHostname)) {
delete settings[settingsHostname]
settingsUpdated = true
}
})
if (settingsUpdated) {
localAccountSensitiveSettings.whitelistedUnfurlingSites = settings
}
} catch (e) {
console.error('Could not parse the whitelist for sites', e)
}
Global.settingsHasLoaded();
Global.errorSound = errorSound;
}

View File

@ -18,8 +18,8 @@ Item {
property bool allCornersRounded: false
id: imageContainer
width: loadingImage.visible ? loadingImage.width : imageMessage.width
height: loadingImage.visible ? loadingImage.height : imageMessage.paintedHeight
width: loadingImageLoader.active ? loadingImageLoader.width : imageMessage.width
height: loadingImageLoader.active ? loadingImageLoader.height : imageMessage.paintedHeight
Connections {
target: Global.applicationWindow
@ -88,27 +88,30 @@ Item {
}
}
Rectangle {
id: loadingImage
visible: imageMessage.status === Image.Loading
|| imageMessage.status === Image.Error
width: parent.width
Loader {
id: loadingImageLoader
active: imageMessage.status === Image.Loading
|| imageMessage.status === Image.Error
width: 300
height: width
border.width: 1
border.color: Style.current.border
radius: Style.current.radius
sourceComponent: Rectangle {
anchors.fill: parent
border.width: 1
border.color: Style.current.border
radius: Style.current.radius
StyledText {
anchors.centerIn: parent
text: imageMessage.status === Image.Error?
//% "Error loading the image"
qsTrId("error-loading-the-image") :
//% "Loading image..."
qsTrId("loading-image---")
color: imageMessage.status === Image.Error?
Style.current.red :
Style.current.textColor
font.pixelSize: 15
StyledText {
anchors.centerIn: parent
text: imageMessage.status === Image.Error?
//% "Error loading the image"
qsTrId("error-loading-the-image") :
//% "Loading image..."
qsTrId("loading-image---")
color: imageMessage.status === Image.Error?
Style.current.red :
Style.current.textColor
font.pixelSize: 15
}
}
}
}

View File

@ -46,7 +46,6 @@ Column {
property int linkWidth: linksRepeater.width
readonly property string uuid: Utils.uuid()
active: true
Connections {
@ -71,30 +70,31 @@ Column {
enabled: false
target: root.messageStore.messageModule
onLinkPreviewDataWasReceived: {
let response
try {
response = JSON.parse(previewData)
} catch (e) {
console.error(previewData, e)
return
}
if (response.uuid !== linkMessageLoader.uuid) return
linkFetchConnections.enabled = false
let response
try {
response = JSON.parse(previewData)
} catch (e) {
console.error(previewData, e)
return
}
if (response.uuid !== linkMessageLoader.uuid) return
linkFetchConnections.enabled = false
if (!response.success) {
console.error("could not get preview data")
return undefined
}
if (!response.success) {
console.error("could not get preview data")
return undefined
}
linkData = response.result
linkData = response.result
if (linkData.contentType.startsWith("image/")) {
return linkMessageLoader.sourceComponent = unfurledImageComponent
}
if (linkData.site && linkData.title) {
linkData.address = link
return linkMessageLoader.sourceComponent = unfurledLinkComponent
}
linkMessageLoader.height = undefined // Reset height so it's not 0
if (linkData.contentType.startsWith("image/")) {
return linkMessageLoader.sourceComponent = unfurledImageComponent
}
if (linkData.site && linkData.title) {
linkData.address = link
return linkMessageLoader.sourceComponent = unfurledLinkComponent
}
}
}
@ -169,7 +169,8 @@ Column {
if (data) {
linkData = data
if (data.fetching && data.communityId) {
linkCommunityFetchConnections.enabled = true
// TODO uncomment when linkCommunityFetchConnections is refactored
// linkCommunityFetchConnections.enabled = true
return
}
if (data.communityId) {