From a05f5b938ad3e9f92c6dc8d2ac939d56c8f9400d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 23 Jul 2020 13:26:49 -0400
Subject: [PATCH] callmodel: avoid to hold detached calls

Change-Id: I79f48e08e62e8a9dfdc28b2f2e4f89ea4b6f4ba0
---
 src/api/account.h       |  1 +
 src/newaccountmodel.cpp |  2 ++
 src/newcallmodel.cpp    | 17 ++++++++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/api/account.h b/src/api/account.h
index 0d11630a..7eeb6189 100644
--- a/src/api/account.h
+++ b/src/api/account.h
@@ -96,6 +96,7 @@ struct ConfProperties_t {
     QString                                           mailbox;
     QString                                           dtmfType;
     bool                                              autoAnswer;
+    bool                                              isRendezVous;
     int                                               activeCallLimit;
     QString                                           hostname;
     QString                                           username;
diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp
index c511a844..053b6f6f 100644
--- a/src/newaccountmodel.cpp
+++ b/src/newaccountmodel.cpp
@@ -738,6 +738,7 @@ account::Info::fromDetails(const MapStringString& details)
     confProperties.mailbox                              = details[ConfProperties::MAILBOX];
     confProperties.dtmfType                             = details[ConfProperties::DTMF_TYPE];
     confProperties.autoAnswer                           = toBool(details[ConfProperties::AUTOANSWER]);
+    confProperties.isRendezVous                         = toBool(details[ConfProperties::ISRENDEZVOUS]);
     confProperties.activeCallLimit                      = toInt(details[ConfProperties::ACTIVE_CALL_LIMIT]);
     confProperties.hostname                             = details[ConfProperties::HOSTNAME];
     profileInfo.uri                                     = (profileInfo.type == profile::Type::RING and details[ConfProperties::USERNAME].contains("ring:"))
@@ -844,6 +845,7 @@ account::ConfProperties_t::toDetails() const
     details[ConfProperties::MAILBOX]                    = this->mailbox;
     details[ConfProperties::DTMF_TYPE]                  = this->dtmfType;
     details[ConfProperties::AUTOANSWER]                 = toQString(this->autoAnswer);
+    details[ConfProperties::ISRENDEZVOUS]               = toQString(this->isRendezVous);
     details[ConfProperties::ACTIVE_CALL_LIMIT]          = toQString(this->activeCallLimit);
     details[ConfProperties::HOSTNAME]                   = this->hostname;
     details[ConfProperties::ROUTE]                      = this->routeset;
diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp
index f669ef4c..05e8ef60 100644
--- a/src/newcallmodel.cpp
+++ b/src/newcallmodel.cpp
@@ -39,6 +39,7 @@
 
 // Ring daemon
 #include <media_const.h>
+#include <account_const.h>
 
 // Qt
 #include <QObject>
@@ -614,7 +615,12 @@ NewCallModel::setCurrentCall(const QString& callId) const
     for (const auto& cid : Lrc::activeCalls()) {
         auto filtered = std::find(filterCalls.begin(), filterCalls.end(), cid) != filterCalls.end();
         if (cid != callId && !filtered) {
-            CallManager::instance().hold(cid);
+            // Only hold calls for a non rendez-vous point
+            MapStringString callDetails = CallManager::instance().getCallDetails(callId);
+            auto accountId = callDetails["ACCOUNTID"];
+            MapStringString detailsMap = ConfigurationManager::instance().getAccountDetails(accountId);
+            if (detailsMap[DRing::Account::ConfProperties::ISRENDEZVOUS] == "FALSE")
+                CallManager::instance().hold(cid);
         }
     }
     if (!lrc::api::Lrc::holdConferences) {
@@ -622,6 +628,10 @@ NewCallModel::setCurrentCall(const QString& callId) const
     }
     for (const auto& confId : conferences) {
         if (callId != confId) {
+            MapStringString confDetails = CallManager::instance().getConferenceDetails(confId);
+            // Only hold conference if attached
+            if (confDetails["CALL_STATE"] == "ACTIVE_DETACHED")
+                continue;
             QStringList callList = CallManager::instance().getParticipantList(confId);
             if (callList.indexOf(callId) == -1)
                 CallManager::instance().holdConference(confId);
@@ -684,6 +694,11 @@ NewCallModelPimpl::slotIncomingCall(const QString& accountId, const QString& cal
     if (linked.owner.id != accountId) {
         return;
     }
+    if (linked.owner.confProperties.isRendezVous) {
+        // Do not notify for calls if rendez vous because it's in a detached
+        // mode and auto answer is managed by the daemon
+        return;
+    }
 
     // do not use auto here (QDBusPendingReply<MapStringString>)
     MapStringString callDetails = CallManager::instance().getCallDetails(callId);
-- 
GitLab