From 99d415b1fe8f9da6cdf5f9e96fadfd830aaa72b1 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Mon, 22 Jan 2024 13:30:39 -0500
Subject: [PATCH] chat view: don't attempt to redefine a Loader's final
 property

We can't define a property called `status` for a Loader as it exists already. At best, the app will crash as it should be unable to create the chat view. At worst, this will introduce undefined behavior by confounding transfer/loader status assignments and comparisons.

Gitlab: #1537 (crash)
Change-Id: I66fb6da25cae695f7f1f520200f6eed8a2c93d03
---
 .../DataTransferMessageDelegate.qml            | 18 +++++++++---------
 .../src/tst_DataTransferMessageDelegate.qml    |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/app/commoncomponents/DataTransferMessageDelegate.qml b/src/app/commoncomponents/DataTransferMessageDelegate.qml
index bbf2c4994..f06a02724 100644
--- a/src/app/commoncomponents/DataTransferMessageDelegate.qml
+++ b/src/app/commoncomponents/DataTransferMessageDelegate.qml
@@ -40,12 +40,12 @@ Loader {
     property int seq: MsgSeq.single
     property string author: Author
     property string body: Body
-    property var status: Status
+    property var transferStatus: Status
 
     width: ListView.view ? ListView.view.width : 0
 
     sourceComponent: {
-        if (root.status === Interaction.Status.TRANSFER_FINISHED) {
+        if (root.transferStatus === Interaction.Status.TRANSFER_FINISHED) {
             mediaInfo = MessagesAdapter.getMediaInfo(root.body)
             if (Object.keys(mediaInfo).length !== 0 && WITH_WEBENGINE)
                 return localMediaMsgComp
@@ -64,8 +64,8 @@ Loader {
             id: dataTransferItem
 
             transferId: Id
-            property var transferStats: MessagesAdapter.getTransferStats(transferId, root.Status)
-            property bool canOpen: root.status === Interaction.Status.TRANSFER_FINISHED || isOutgoing
+            property var transferStats: MessagesAdapter.getTransferStats(transferId, root.transferStatus)
+            property bool canOpen: root.transferStatus === Interaction.Status.TRANSFER_FINISHED || isOutgoing
             property real maxMsgWidth: root.width - senderMargin -
                                        2 * hPadding - avatarBlockWidth
                                        - buttonsLoader.width - 24 - 6 - 24
@@ -110,7 +110,7 @@ Loader {
                         Layout.margins: 8
 
                         sourceComponent: {
-                            switch (root.status) {
+                            switch (root.transferStatus) {
                             case Interaction.Status.TRANSFER_CREATED:
                             case Interaction.Status.TRANSFER_FINISHED:
                                 iconSource = JamiResources.link_black_24dp_svg
@@ -157,7 +157,7 @@ Loader {
                                 normalColor: JamiTheme.chatviewBgColor
                                 imageColor: JamiTheme.chatviewButtonColor
                                 onClicked: {
-                                    if (root.status === Interaction.Status.TRANSFER_ONGOING) {
+                                    if (root.transferStatus === Interaction.Status.TRANSFER_ONGOING) {
                                         return MessagesAdapter.cancelFile(transferId)
                                     } else {
                                         return MessagesAdapter.acceptFile(transferId)
@@ -226,7 +226,7 @@ Loader {
                 ,ProgressBar {
                     id: progressBar
 
-                    visible: root.status === Interaction.Status.TRANSFER_ONGOING
+                    visible: root.transferStatus === Interaction.Status.TRANSFER_ONGOING
                     height: visible * implicitHeight
                     value: transferStats.progress / transferStats.totalSize
                     width: transferItem.width
@@ -244,7 +244,7 @@ Loader {
 
             isOutgoing: Author === CurrentAccount.uri
             transferId: Id
-            property var transferStats: MessagesAdapter.getTransferStats(transferId, root.status)
+            property var transferStats: MessagesAdapter.getTransferStats(transferId, root.transferStatus)
             showTime: root.showTime
             seq: root.seq
             author: Author
@@ -398,7 +398,7 @@ Loader {
                             readonly property real aspectRatio: paintedWidth / paintedHeight
                             readonly property real idealWidth: innerContent.width - senderMargin
                             onStatusChanged: {
-                                if (root.status == Image.Ready && aspectRatio) {
+                                if (img.status == Image.Ready && aspectRatio) {
                                     height = Qt.binding(() => JamiQmlUtils.clamp(idealWidth / aspectRatio, 64, 256))
                                     width = Qt.binding(() => height * aspectRatio)
 
diff --git a/tests/qml/src/tst_DataTransferMessageDelegate.qml b/tests/qml/src/tst_DataTransferMessageDelegate.qml
index 91d9553b2..884226755 100644
--- a/tests/qml/src/tst_DataTransferMessageDelegate.qml
+++ b/tests/qml/src/tst_DataTransferMessageDelegate.qml
@@ -31,7 +31,7 @@ import "../../../src/app/commoncomponents"
 DataTransferMessageDelegate {
     id: uut
     timestamp: 0
-    status: Interaction.Status.TRANSFER_FINISHED
+    transferStatus: Interaction.Status.TRANSFER_FINISHED
     author: ""
     body: ""
 
@@ -39,9 +39,9 @@ DataTransferMessageDelegate {
         name: "Check basic visibility for header buttons"
         function test_checkBasicVisibility() {
             var buttonsLoader = findChild(uut, "buttonsLoader")
-            uut.status = Interaction.Status.TRANSFER_AWAITING_HOST
+            uut.transferStatus = Interaction.Status.TRANSFER_AWAITING_HOST
             compare(buttonsLoader.iconSource, JamiResources.download_black_24dp_svg)
-            uut.status = Interaction.Status.TRANSFER_FINISHED
+            uut.transferStatus = Interaction.Status.TRANSFER_FINISHED
             compare(buttonsLoader.iconSource, JamiResources.link_black_24dp_svg)
         }
     }
-- 
GitLab