fix(StatusMessage): updated GIFs behavior

Closes #7518
This commit is contained in:
Alexandra Betouni 2023-02-01 18:20:42 +02:00 committed by Alexandra Betouni
parent 3f52df4f87
commit b037d724ed
3 changed files with 74 additions and 22 deletions

View File

@ -13,12 +13,13 @@ Item {
property bool isCurrentUser: false
property url source
property bool isActiveChannel: false
property bool playing: Global.applicationWindow.active && isChatActive
property bool playing: Global.applicationWindow.active
property bool isAnimated: !!source && source.toString().endsWith('.gif')
property var container
property alias imageAlias: imageMessage
property bool allCornersRounded: false
property bool isOnline: true // TODO: mark as required when migrating to 5.15 or above
property bool imageLoaded: (imageMessage.status === Image.Ready)
signal clicked(var image, var mouse)
@ -114,9 +115,11 @@ Item {
Loader {
id: loadingImageLoader
active: imageMessage.status === Image.Loading
|| imageMessage.status === Image.Error
width: 300
|| imageMessage.status === Image.Error
visible: active
width: active ? 300 : 0
height: width
sourceComponent: Rectangle {
anchors.fill: parent
border.width: 1

View File

@ -252,12 +252,16 @@ Column {
Component {
id: unfurledLinkComponent
MessageBorder {
id: unfurledLink
readonly property bool isGIFImage: linkData.thumbnailUrl.endsWith(".gif")
width: linkImage.visible ? linkImage.width + 2 : 300
height: {
if (linkImage.visible) {
return linkImage.height + (Style.current.smallPadding * 2) + linkTitle.height + 2 + linkSite.height
return linkImage.height + (!unfurledLink.isGIFImage ?
((Style.current.smallPadding * 2) + (linkTitle.height + 2 + linkSite.height)) : 0)
}
return (Style.current.smallPadding * 2) + linkTitle.height + 2 + linkSite.height
return (Style.current.smallPadding * 2) + (!unfurledLink.isGIFImage ?
(linkTitle.height + 2 + linkSite.height) : 0)
}
isCurrentUser: root.isCurrentUser
@ -272,8 +276,65 @@ Column {
isCurrentUser: root.isCurrentUser
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
playing: root.messageStore.playAnimation
isOnline: root.store.mainModuleInst.isOnline
onClicked: {
if (unfurledLink.isGIFImage) {
if (playing) {
imageClicked(linkImage.imageAlias);
} else {
if (root.messageStore.playAnimation) {
linkImage.playing = true;
animationPlayingTimer.restart();
}
}
} else {
if (!!linkData.callback) {
return linkData.callback()
}
Global.openLink(linkData.address)
}
}
onImageLoadedChanged: {
if (imageLoaded && root.messageStore.playAnimation) {
playing = true;
animationPlayingTimer.start();
}
}
Timer {
id: animationPlayingTimer
interval: 10000
running: false
onTriggered: {
if (root.messageStore.playAnimation) {
linkImage.playing = false;
}
}
}
}
Loader {
width: 45
height: 38
anchors.left: parent.left
anchors.leftMargin: 12
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
active: !linkImage.playing
sourceComponent: Item {
anchors.fill: parent
Rectangle {
anchors.fill: parent
color: "black"
radius: Style.current.radius
opacity: .4
}
StatusBaseText {
anchors.centerIn: parent
text: "GIF"
font.pixelSize: 13
}
}
}
StatusBaseText {
@ -282,6 +343,7 @@ Column {
font.pixelSize: 13
font.weight: Font.Medium
wrapMode: Text.Wrap
visible: !unfurledLink.isGIFImage
anchors.top: linkImage.visible ? linkImage.bottom : parent.top
anchors.topMargin: Style.current.smallPadding
anchors.left: parent.left
@ -292,6 +354,7 @@ Column {
StatusBaseText {
id: linkSite
visible: !unfurledLink.isGIFImage
text: linkData.site
font.pixelSize: 12
font.weight: Font.Thin
@ -302,20 +365,6 @@ Column {
anchors.bottomMargin: Style.current.halfPadding
}
MouseArea {
anchors.top: linkImage.visible ? linkImage.top : linkTitle.top
anchors.left: linkImage.visible ? linkImage.left : linkTitle.left
anchors.right: linkImage.visible ? linkImage.right : linkTitle.right
anchors.bottom: linkSite.bottom
cursorShape: Qt.PointingHandCursor
onClicked: {
if (!!linkData.callback) {
return linkData.callback()
}
Global.openLink(linkData.address)
}
}
Component.onCompleted: d.unfurledLinksCount++
Component.onDestruction: d.unfurledLinksCount--
}

View File

@ -195,7 +195,7 @@ StatusMenu {
StatusAction {
id: copyImageAction
text: qsTr("Copy image")
text: (root.imageSource.endsWith(".gif")) ? qsTr("Copy GIF") : qsTr("Copy image")
onTriggered: {
if (root.imageSource) {
root.store.copyImageToClipboardByUrl(root.imageSource)
@ -208,7 +208,7 @@ StatusMenu {
StatusAction {
id: downloadImageAction
text: qsTr("Download image")
text: (root.imageSource.endsWith(".gif")) ? qsTr("Download GIF") : qsTr("Download image")
onTriggered: {
fileDialog.open()
root.close()