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 profileModelInst: profileModel
property var contactStore: profileSectionStore.contactsStore property var contactStore: profileSectionStore.contactsStore
property var privacyStore: profileSectionStore.privacyStore
property bool hasAddedContacts: contactStore.myContactsModel.count > 0 property bool hasAddedContacts: contactStore.myContactsModel.count > 0
property var assets: walletSectionAccountTokens.model property var assets: walletSectionAccountTokens.model

View File

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

View File

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

View File

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