From 55977e748de79bdfaacd974af902784ca67fa89a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 3 Mar 2023 15:07:57 -0500
Subject: [PATCH] currentcall: setCurrentCall only on active calls

Change-Id: I9f16e8a3633981d41429343885a3130b0496288d
GitLab: #1007
---
 src/app/calladapter.cpp |  9 ++++++---
 src/app/currentcall.cpp | 11 +++++++++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/app/calladapter.cpp b/src/app/calladapter.cpp
index 5388e2d2e..cbb99d173 100644
--- a/src/app/calladapter.cpp
+++ b/src/app/calladapter.cpp
@@ -416,8 +416,6 @@ CallAdapter::acceptACall(const QString& accountId, const QString& convUid)
         return;
 
     lrcInstance_->getAccountInfo(accountId).callModel->accept(convInfo.callId);
-    auto& accInfo = lrcInstance_->getAccountInfo(convInfo.accountId);
-    accInfo.callModel->setCurrentCall(convInfo.callId);
 }
 
 void
@@ -518,7 +516,12 @@ CallAdapter::updateCall(const QString& convUid, const QString& accountId, bool f
     if (convInfo.uid == lrcInstance_->get_selectedConvUid()) {
         auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId_);
         if (accInfo.profileInfo.type != lrc::api::profile::Type::SIP) {
-            accInfo.callModel->setCurrentCall(call->id);
+            // Only setCurrentCall if call is actually answered
+            try {
+                if (call->status == call::Status::IN_PROGRESS
+                    || call->status == call::Status::PAUSED)
+                    accInfo.callModel->setCurrentCall(call->id);
+            } catch (...) {}
         }
     }
 
diff --git a/src/app/currentcall.cpp b/src/app/currentcall.cpp
index 00485dc12..a3f99e753 100644
--- a/src/app/currentcall.cpp
+++ b/src/app/currentcall.cpp
@@ -61,8 +61,15 @@ CurrentCall::updateId(QString callId)
     }
 
     auto& accInfo = lrcInstance_->getCurrentAccountInfo();
-    if (accInfo.profileInfo.type != lrc::api::profile::Type::SIP)
-        accInfo.callModel->setCurrentCall(callId);
+    if (accInfo.profileInfo.type != lrc::api::profile::Type::SIP) {
+        // Only setCurrentCall if call is actually answered
+        try {
+            auto callInfo = accInfo.callModel->getCall(callId);
+            if (callInfo.status == call::Status::IN_PROGRESS
+                || callInfo.status == call::Status::PAUSED)
+                accInfo.callModel->setCurrentCall(callId);
+        } catch (...) {}
+    }
     // Set the current id_ if there is a call.
     set_id((accInfo.callModel->hasCall(callId) ? callId : QString()));
 }
-- 
GitLab