feat(chat): add unfurling message for images

Fixes #1940
This commit is contained in:
Jonathan Rainville 2021-07-23 15:41:17 -04:00 committed by Iuri Matias
parent 1be169bc7e
commit 39dace238b
1 changed files with 19 additions and 9 deletions

View File

@ -12,6 +12,7 @@ Column {
property string linkUrls: "" property string linkUrls: ""
property var container property var container
property bool isCurrentUser: false property bool isCurrentUser: false
property bool isImageLink: false
readonly property string uuid: Utils.uuid() readonly property string uuid: Utils.uuid()
spacing: Style.current.halfPadding spacing: Style.current.halfPadding
@ -116,12 +117,22 @@ Column {
// Reset the height in case we set it to 0 below. See note below // Reset the height in case we set it to 0 below. See note below
// for more information // for more information
this.height = undefined this.height = undefined
if (appSettings.displayChatImages && Utils.hasImageExtension(link)) { if (Utils.hasImageExtension(link)) {
linkData = { if (appSettings.displayChatImages) {
thumbnailUrl: link linkData = {
thumbnailUrl: link
}
return unfurledImageComponent
} else {
if (isImageLink && index > 0) {
return
}
isImageLink = true
return enableLinkComponent
} }
return unfurledImageComponent
} }
let linkWhiteListed = false let linkWhiteListed = false
const linkHostname = Utils.getHostname(link) const linkHostname = Utils.getHostname(link)
const linkExists = Object.keys(appSettings.whitelistedUnfurlingSites).some(function(whitelistedHostname) { const linkExists = Object.keys(appSettings.whitelistedUnfurlingSites).some(function(whitelistedHostname) {
@ -186,9 +197,7 @@ Column {
source: linkData.thumbnailUrl source: linkData.thumbnailUrl
imageWidth: 300 imageWidth: 300
isCurrentUser: root.isCurrentUser isCurrentUser: root.isCurrentUser
onClicked: { onClicked: clickMessage(false, false, true, linkImage.imageAlias)
clickMessage(false, false, true, linkImage.imageAlias)
}
} }
} }
} }
@ -299,8 +308,9 @@ Column {
StyledText { StyledText {
id: enableText id: enableText
//% "Enable link previews in chat?" text: isImageLink ? qsTr("Enable automatic image unfurling") :
text: qsTrId("enable-link-previews") //% "Enable link previews in chat?"
qsTrId("enable-link-previews")
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
width: parent.width width: parent.width
wrapMode: Text.WordWrap wrapMode: Text.WordWrap