From 4aef4a690d6bff2c1afba1968ad73ab0567d013e Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Tue, 13 Jul 2021 21:28:03 -0400
Subject: [PATCH] conference: avoid excessive image caching during resize
 events

Throttle avatar image queries to the image provider when the
component size changes.

Gitlab: #466
Change-Id: Ie619671a593bcca75899f3d97c2af2071c427ab4
---
 src/commoncomponents/Avatar.qml                |  1 +
 src/mainview/components/ParticipantOverlay.qml | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/commoncomponents/Avatar.qml b/src/commoncomponents/Avatar.qml
index bb6662b75..45e66fbb9 100644
--- a/src/commoncomponents/Avatar.qml
+++ b/src/commoncomponents/Avatar.qml
@@ -29,6 +29,7 @@ Item {
 
     enum Mode { Account, Contact, Conversation }
     property int mode: Avatar.Mode.Account
+    property alias sourceSize: image.sourceSize
 
     property string imageId
 
diff --git a/src/mainview/components/ParticipantOverlay.qml b/src/mainview/components/ParticipantOverlay.qml
index a223b4178..c7ebb70b7 100644
--- a/src/mainview/components/ParticipantOverlay.qml
+++ b/src/mainview/components/ParticipantOverlay.qml
@@ -171,8 +171,15 @@ Item {
         id: avatar
 
         anchors.centerIn: parent
-        height:  Math.min(parent.width / 2, parent.height / 2)
-        width:  Math.min(parent.width / 2, parent.height / 2)
+
+        property real size: Math.min(parent.width / 2, parent.height / 2)
+        height:  size
+        width:  size
+
+        // round the avatar source size up to some nearest multiple
+        readonly property real step: 96
+        property real imageSize: Math.floor((size + step - 1) / step) * step
+        sourceSize: Qt.size(imageSize, imageSize)
 
         visible: false
         showPresenceIndicator: false
-- 
GitLab