From c02e33c2616b63b03910b9c0550a974444f5210d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 21 Aug 2020 12:09:08 -0400
Subject: [PATCH] conference: handle participants without video

Change-Id: I266ab31e31d85b6cd94356b63368540c02e16c6f
---
 src/calladapter.cpp                           |  9 +++-
 src/mainview/components/CallOverlay.qml       |  5 +++
 .../components/ParticipantOverlay.qml         | 41 ++++++++++++++++++-
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/src/calladapter.cpp b/src/calladapter.cpp
index 0ead73b69..962a5a783 100644
--- a/src/calladapter.cpp
+++ b/src/calladapter.cpp
@@ -308,19 +308,24 @@ CallAdapter::connectCallModel(const QString& accountId)
                     data["h"] = participant["h"].toInt();
                     data["uri"] = participant["uri"];
                     data["active"] = participant["active"] == "true";
+                    data["videoMuted"] = participant["videoMuted"] == "true";
+                    data["audioMuted"] = participant["audioMuted"] == "true";
                     auto bestName = participant["uri"];
                     data["isLocal"] = false;
                     auto& accInfo = LRCInstance::accountModel().getAccountInfo(accountId_);
                     if (bestName == accInfo.profileInfo.uri) {
                         bestName = tr("me");
                         data["isLocal"] = true;
+                        if (participant["videoMuted"] == "true")
+                            data["avatar"] = accInfo.profileInfo.avatar;
                     } else {
                         try {
                             auto& contact = LRCInstance::getCurrentAccountInfo()
                                                 .contactModel->getContact(participant["uri"]);
                             bestName = Utils::bestNameForContact(contact);
-                        } catch (...) {
-                        }
+                            if (participant["videoMuted"] == "true")
+                                data["avatar"] = contact.profileInfo.avatar;
+                        } catch (...) {}
                     }
                     data["bestName"] = bestName;
                     map.push_back(QVariant(data));
diff --git a/src/mainview/components/CallOverlay.qml b/src/mainview/components/CallOverlay.qml
index 1f2ed4ede..7977c399f 100644
--- a/src/mainview/components/CallOverlay.qml
+++ b/src/mainview/components/CallOverlay.qml
@@ -97,11 +97,16 @@ Rectangle {
                     console.log("Error when creating the hover")
                     return
                 }
+
                 hover.setParticipantName(infos[infoVariant].bestName)
                 hover.active = infos[infoVariant].active;
                 hover.isLocal = infos[infoVariant].isLocal;
                 hover.setMenuVisible(isMaster)
                 hover.uri = infos[infoVariant].uri
+                if (infos[infoVariant].videoMuted)
+                    hover.setAvatar(infos[infoVariant].avatar)
+                else
+                    hover.setAvatar("")
                 hover.injectedContextMenu = participantContextMenu
                 participantOverlays.push(hover)
             }
diff --git a/src/mainview/components/ParticipantOverlay.qml b/src/mainview/components/ParticipantOverlay.qml
index 2f17b0880..264fc7270 100644
--- a/src/mainview/components/ParticipantOverlay.qml
+++ b/src/mainview/components/ParticipantOverlay.qml
@@ -37,6 +37,16 @@ Rectangle {
         participantName.text = name
     }
 
+    function setAvatar(avatar) {
+        if (avatar === "") {
+            opacity = 0
+            contactImage.source = ""
+        } else {
+            opacity = 1
+            contactImage.source = "data:image/png;base64," + avatar
+        }
+    }
+
     function setMenuVisible(isVisible) {
         optionsButton.visible = isVisible
     }
@@ -53,6 +63,31 @@ 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
+                    }
+                }
+            }
+        }
+
         RowLayout {
             id: bottomLabel
 
@@ -130,11 +165,13 @@ Rectangle {
         }
 
         onEntered: {
-            root.state = "entered"
+            if (contactImage.status === Image.Null)
+                root.state = "entered"
         }
 
         onExited: {
-            root.state = "exited"
+            if (contactImage.status === Image.Null)
+                root.state = "exited"
         }
     }
 
-- 
GitLab