From cfa10ce2681ac9fdaf9b312e0f55699c34ff060d Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Fri, 9 Apr 2021 13:22:48 -0400
Subject: [PATCH] calls: fix call overlay updates

- don't query the recording state in the set time text function
- change set time text function interval from 20ms to 1000ms
- stop the account-wide time text update timer when there are
  no calls

Change-Id: Iaaabfd52a50ba61aaabade59cae4f061c562cb2d
---
 src/accountadapter.cpp                    |  4 ++--
 src/calladapter.cpp                       | 18 +++++++++++++++---
 src/lrcinstance.cpp                       | 13 +++++++++----
 src/lrcinstance.h                         |  2 +-
 src/mainview/components/AudioCallPage.qml |  4 ++++
 src/mainview/components/VideoCallPage.qml |  1 -
 6 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/accountadapter.cpp b/src/accountadapter.cpp
index 18477fd0f..d05f58e1f 100644
--- a/src/accountadapter.cpp
+++ b/src/accountadapter.cpp
@@ -246,7 +246,7 @@ AccountAdapter::startPreviewing(bool force)
 void
 AccountAdapter::stopPreviewing()
 {
-    if (!lrcInstance_->hasVideoCall() && lrcInstance_->renderer()->isPreviewing()) {
+    if (!lrcInstance_->hasActiveCall(true) && lrcInstance_->renderer()->isPreviewing()) {
         lrcInstance_->renderer()->stopPreviewing();
     }
 }
@@ -254,7 +254,7 @@ AccountAdapter::stopPreviewing()
 bool
 AccountAdapter::hasVideoCall()
 {
-    return lrcInstance_->hasVideoCall();
+    return lrcInstance_->hasActiveCall(true);
 }
 
 bool
diff --git a/src/calladapter.cpp b/src/calladapter.cpp
index 9775f0861..c63132504 100644
--- a/src/calladapter.cpp
+++ b/src/calladapter.cpp
@@ -86,6 +86,10 @@ CallAdapter::onAccountChanged()
 void
 CallAdapter::onCallStatusChanged(const QString& accountId, const QString& callId)
 {
+    // :/ one timer for all the call overlays
+    if (!lrcInstance_->hasActiveCall())
+        oneSecondTimer_->stop();
+
 #ifdef Q_OS_LINUX
     auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId);
     auto& callModel = accInfo.callModel;
@@ -119,6 +123,9 @@ CallAdapter::onCallStatusChanged(const QString& accountId, const QString& callId
                                           Utils::QImageToByteArray(contactPhoto));
         }
     }
+#else
+    Q_UNUSED(accountId)
+    Q_UNUSED(callId)
 #endif
 }
 
@@ -420,6 +427,13 @@ CallAdapter::connectCallModel(const QString& accountId)
 {
     auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId);
 
+    QObject::connect(
+        oneSecondTimer_,
+        &QTimer::timeout,
+        this,
+        [this] { setTime(accountId_, convUid_); },
+        Qt::UniqueConnection);
+
     connect(
         accInfo.callModel.get(),
         &lrc::api::NewCallModel::onParticipantsChanged,
@@ -573,9 +587,7 @@ void
 CallAdapter::updateCallOverlay(const lrc::api::conversation::Info& convInfo)
 {
     setTime(accountId_, convUid_);
-    QObject::disconnect(oneSecondTimer_);
-    QObject::connect(oneSecondTimer_, &QTimer::timeout, [this] { setTime(accountId_, convUid_); });
-    oneSecondTimer_->start(20);
+    oneSecondTimer_->start(1000);
     auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId_);
 
     auto* call = lrcInstance_->getCallInfoForConversation(convInfo);
diff --git a/src/lrcinstance.cpp b/src/lrcinstance.cpp
index e7c38fe5a..a3e951996 100644
--- a/src/lrcinstance.cpp
+++ b/src/lrcinstance.cpp
@@ -118,7 +118,7 @@ LRCInstance::getCurrentAccountInfo()
 }
 
 bool
-LRCInstance::hasVideoCall()
+LRCInstance::hasActiveCall(bool withVideo)
 {
     auto activeCalls = lrc_->activeCalls();
     auto accountList = accountModel().getAccountList();
@@ -126,9 +126,14 @@ LRCInstance::hasVideoCall()
     for (const auto& callId : activeCalls) {
         for (const auto& accountId : accountList) {
             auto& accountInfo = accountModel().getAccountInfo(accountId);
-            if (accountInfo.callModel->hasCall(callId)) {
-                auto call = accountInfo.callModel->getCall(callId);
-                result |= !(call.isAudioOnly || call.videoMuted);
+            if (withVideo) {
+                if (accountInfo.callModel->hasCall(callId))
+                    return true;
+            } else {
+                if (accountInfo.callModel->hasCall(callId)) {
+                    auto call = accountInfo.callModel->getCall(callId);
+                    result |= !(call.isAudioOnly || call.videoMuted);
+                }
             }
         }
     }
diff --git a/src/lrcinstance.h b/src/lrcinstance.h
index 0532263ff..332725a1a 100644
--- a/src/lrcinstance.h
+++ b/src/lrcinstance.h
@@ -110,7 +110,7 @@ public:
     QString getContentDraft(const QString& convUid, const QString& accountId);
     void setContentDraft(const QString& convUid, const QString& accountId, const QString& content);
 
-    bool hasVideoCall();
+    bool hasActiveCall(bool withVideo = false);
     void pushlastConference(const QString& confId, const QString& callId);
     QString poplastConference(const QString& confId);
     VectorString getConferenceSubcalls(const QString& callId);
diff --git a/src/mainview/components/AudioCallPage.qml b/src/mainview/components/AudioCallPage.qml
index b9fcbad00..2cbc0b148 100644
--- a/src/mainview/components/AudioCallPage.qml
+++ b/src/mainview/components/AudioCallPage.qml
@@ -134,6 +134,10 @@ Rectangle {
                             audioCallOverlay.showOnHoldImage(isPaused)
                             audioCallPageRectCentralRect.visible = !isPaused
                         }
+
+                        function onRemoteRecordingChanged(label, state) {
+                            audioCallOverlay.showRemoteRecording(label, state)
+                        }
                     }
 
                     onOverlayChatButtonClicked: {
diff --git a/src/mainview/components/VideoCallPage.qml b/src/mainview/components/VideoCallPage.qml
index f600f18fa..93617835d 100644
--- a/src/mainview/components/VideoCallPage.qml
+++ b/src/mainview/components/VideoCallPage.qml
@@ -179,7 +179,6 @@ Rectangle {
 
                         function onUpdateTimeText(time) {
                             videoCallOverlay.timeText = time
-                            videoCallOverlay.setRecording(CallAdapter.isRecordingThisCall())
                         }
 
                         function onUpdateOverlay(isPaused, isAudioOnly, isAudioMuted, isVideoMuted,
-- 
GitLab