From ce88a3071241bbf6b70868eee6778f325e3b9c57 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Mon, 19 Apr 2021 13:10:53 -0400
Subject: [PATCH] conference: show avatar for videoMuted peer

GitLab: #379
Change-Id: I885ad338d7a5c06fca7c765680e644c44f33228d
---
 src/avatarimageprovider.h                     |  6 +-
 src/calladapter.cpp                           |  3 +-
 src/mainview/components/CallOverlay.qml       |  8 +-
 .../components/ParticipantOverlay.qml         | 99 ++++++++++---------
 4 files changed, 62 insertions(+), 54 deletions(-)

diff --git a/src/avatarimageprovider.h b/src/avatarimageprovider.h
index 60b9f4d74..3099b9747 100644
--- a/src/avatarimageprovider.h
+++ b/src/avatarimageprovider.h
@@ -29,8 +29,8 @@ class AvatarImageProvider : public QuickImageProviderBase
 public:
     AvatarImageProvider(LRCInstance* instance = nullptr)
         : QuickImageProviderBase(QQuickImageProvider::Image,
-                                  QQmlImageProviderBase::ForceAsynchronousImageLoading,
-                                  instance)
+                                 QQmlImageProviderBase::ForceAsynchronousImageLoading,
+                                 instance)
     {}
 
     /*
@@ -65,7 +65,7 @@ public:
         } else if (idType == "contact") {
             return Utils::contactPhoto(lrcInstance_, idContent, requestedSize);
         } else if (idType == "fallback") {
-            return Utils::fallbackAvatar(QString(), idContent, requestedSize);
+            return Utils::fallbackAvatar(idContent, QString(), requestedSize);
         } else if (idType == "default") {
             return Utils::fallbackAvatar(QString(), QString(), requestedSize);
         } else if (idType == "base64") {
diff --git a/src/calladapter.cpp b/src/calladapter.cpp
index 7dd9a84e8..58598b72a 100644
--- a/src/calladapter.cpp
+++ b/src/calladapter.cpp
@@ -339,6 +339,7 @@ CallAdapter::fillParticipantData(QMap<QString, QString> participant)
     data["videoMuted"] = participant["videoMuted"] == "true";
     data["audioLocalMuted"] = participant["audioLocalMuted"] == "true";
     data["audioModeratorMuted"] = participant["audioModeratorMuted"] == "true";
+    data["isContact"] = false;
 
     auto bestName = participant["uri"];
     auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId_);
@@ -356,7 +357,7 @@ CallAdapter::fillParticipantData(QMap<QString, QString> participant)
                 participant["uri"]);
             if (participant["videoMuted"] == "true")
                 data["avatar"] = contact.profileInfo.avatar;
-
+            data["isContact"] = true;
         } catch (...) {
         }
     }
diff --git a/src/mainview/components/CallOverlay.qml b/src/mainview/components/CallOverlay.qml
index 07082f912..b0c611e95 100644
--- a/src/mainview/components/CallOverlay.qml
+++ b/src/mainview/components/CallOverlay.qml
@@ -130,9 +130,9 @@ Rectangle {
                     participantOverlays[p].setMenu(participant.uri, participant.bestName,
                                                    participant.isLocal, participant.active, showMax)
                     if (participant.videoMuted)
-                        participantOverlays[p].setAvatar(participant.avatar)
+                        participantOverlays[p].setAvatar(true, participant.avatar, participant.uri, participant.isLocal, participant.isContact)
                     else
-                        participantOverlays[p].setAvatar("")
+                        participantOverlays[p].setAvatar(false)
                     currentUris.push(participantOverlays[p].uri)
                 } else {
                     // Participant is no longer in conference
@@ -173,9 +173,9 @@ Rectangle {
                     hover.setMenu(infos[infoVariant].uri, infos[infoVariant].bestName,
                                   infos[infoVariant].isLocal, infos[infoVariant].active, showMax)
                     if (infos[infoVariant].videoMuted)
-                        hover.setAvatar(infos[infoVariant].avatar)
+                        hover.setAvatar(true, infos[infoVariant].avatar, infos[infoVariant].uri, infos[infoVariant].isLocal, infos[infoVariant].isContact)
                     else
-                        hover.setAvatar("")
+                        hover.setAvatar(false)
                     participantOverlays.push(hover)
                 }
             }
diff --git a/src/mainview/components/ParticipantOverlay.qml b/src/mainview/components/ParticipantOverlay.qml
index 23739d725..f800ba07a 100644
--- a/src/mainview/components/ParticipantOverlay.qml
+++ b/src/mainview/components/ParticipantOverlay.qml
@@ -47,15 +47,26 @@ Rectangle {
     property bool participantIsModerator: false
     property bool participantIsMuted: false
     property bool participantIsModeratorMuted: false
-
     property bool participantMenuActive: false
 
-    // TODO: try to use AvatarImage as well
-    function setAvatar(avatar) {
-        if (avatar === "") {
-            contactImage.source = ""
-        } else {
-            contactImage.source = JamiQmlUtils.base64StringTitle + avatar
+    function setAvatar(show, avatar, uri, local, isContact) {
+        if (!show)
+            contactImage.visible = false
+        else {
+            if (avatar) {
+                contactImage.mode = AvatarImage.Mode.FromBase64
+                contactImage.updateImage(avatar)
+            } else if (local) {
+                contactImage.mode = AvatarImage.Mode.FromAccount
+                contactImage.updateImage(AccountAdapter.currentAccountId)
+            } else if (isContact) {
+                contactImage.mode = AvatarImage.Mode.FromContactUri
+                contactImage.updateImage(uri)
+            } else {
+                contactImage.mode = AvatarImage.Mode.FromTemporaryName
+                contactImage.updateImage(uri)
+            }
+            contactImage.visible = true
         }
     }
 
@@ -173,6 +184,35 @@ Rectangle {
         }
     }
 
+    AvatarImage {
+        id: contactImage
+
+        anchors.centerIn: parent
+        height:  Math.min(parent.width / 2, parent.height / 2)
+        width:  Math.min(parent.width / 2, parent.height / 2)
+
+        fillMode: Image.PreserveAspectFit
+        imageId: ""
+        visible: false
+        mode: AvatarImage.Mode.Default
+        showPresenceIndicator: false
+
+        layer.enabled: true
+        layer.effect: OpacityMask {
+            maskSource: Rectangle {
+                width: contactImage.width
+                height: contactImage.height
+                radius: {
+                    var size = ((contactImage.width <= contactImage.height)?
+                                    contactImage.width : contactImage.height)
+                    return size / 2
+                }
+            }
+        }
+        layer.mipmap: false
+        layer.smooth: true
+    }
+
     // Participant background, mousearea, hover and buttons for moderation
     Rectangle {
         id: participantRect
@@ -190,42 +230,13 @@ Rectangle {
             propagateComposedEvents: true
             acceptedButtons: Qt.LeftButton
 
-            Image {
-                id: contactImage
-
-                anchors.centerIn: parent
-                height:  Math.min(parent.width / 2, parent.height / 2)
-                width:  Math.min(parent.width / 2, parent.height / 2)
-
-                fillMode: Image.PreserveAspectFit
-                source: ""
-                asynchronous: true
-
-                layer.enabled: true
-                layer.effect: OpacityMask {
-                    maskSource: Rectangle{
-                        width: contactImage.width
-                        height: contactImage.height
-                        radius: {
-                            var size = ((contactImage.width <= contactImage.height)?
-                                            contactImage.width : contactImage.height)
-                            return size / 2
-                        }
-                    }
-                }
-                layer.mipmap: false
-                layer.smooth: true
-            }
-
             ParticipantOverlayMenu {
                 id: overlayMenu
                 visible: participantRect.opacity !== 0
 
                 onMouseAreaExited: {
-                    if (contactImage.status === Image.Null) {
-                        root.z = 1
-                        participantRect.state = "exited"
-                    }
+                    root.z = 1
+                    participantRect.state = "exited"
                 }
                 onMouseChanged: {
                     participantRect.state = "entered"
@@ -235,17 +246,13 @@ Rectangle {
             }
 
             onEntered: {
-                if (contactImage.status === Image.Null) {
-                    root.z = 2
-                    participantRect.state = "entered"
-                }
+                root.z = 2
+                participantRect.state = "entered"
             }
 
             onExited: {
-                if (contactImage.status === Image.Null) {
-                    root.z = 1
-                    participantRect.state = "exited"
-                }
+                root.z = 1
+                participantRect.state = "exited"
             }
 
             onMouseXChanged: {
-- 
GitLab