From 639a38d3083651a4312fa0f663d5e5d785e7f1e9 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Tue, 19 Nov 2019 15:48:52 -0500
Subject: [PATCH] Revert "callmodel: expose setCurrentCall"

This reverts commit 595720c4650729aeb9f438595055c70bade4b8f2.

Reason for revert: <INSERT REASONING HERE>

Change-Id: I3e31a71f417df6ba5dc776e18e239a2cb03b0f36
---
 src/api/lrc.h          |  6 -----
 src/api/newcallmodel.h |  8 +------
 src/lrc.cpp            |  3 ---
 src/newcallmodel.cpp   | 54 +++++++++++++++---------------------------
 4 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/src/api/lrc.h b/src/api/lrc.h
index fe57c119..f11c94d8 100644
--- a/src/api/lrc.h
+++ b/src/api/lrc.h
@@ -22,7 +22,6 @@
 #include <memory>
 #include <vector>
 #include <string>
-#include <atomic>
 
 // Lrc
 #include "typedefs.h"
@@ -111,11 +110,6 @@ public:
      */
     static std::vector<std::string> getConferenceSubcalls(const std::string& id);
 
-    /**
-     * Preference
-     */
-    static std::atomic_bool holdConferences;
-
   private:
     std::unique_ptr<LrcPimpl> lrcPimpl_;
 };
diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h
index 3f6f606c..349825b7 100644
--- a/src/api/newcallmodel.h
+++ b/src/api/newcallmodel.h
@@ -148,8 +148,7 @@ public:
     void playDTMF(const std::string& callId, const std::string& value) const;
 
     /**
-     * Toggle pause on a call.
-     * @warn only use this function for SIP calls
+     * Toggle pause on a call
      * @param callId
      */
     void togglePause(const std::string& callId) const;
@@ -226,11 +225,6 @@ public:
      */
     static std::string getSIPCallStatusString(const short& statusCode);
 
-    /**
-     * Set a call as the current call (hold other calls)
-     */
-    void setCurrentCall(const std::string& callId) const;
-
 Q_SIGNALS:
     /**
      * Emitted when a call state changes
diff --git a/src/lrc.cpp b/src/lrc.cpp
index 1b6ce5dd..213093e9 100644
--- a/src/lrc.cpp
+++ b/src/lrc.cpp
@@ -45,8 +45,6 @@ namespace lrc
 
 using namespace api;
 
-std::atomic_bool lrc::api::Lrc::holdConferences;
-
 // To judge whether the call is finished or not depending on callState
 bool isFinished(const QString& callState);
 
@@ -67,7 +65,6 @@ public:
 
 Lrc::Lrc(MigrationCb willDoMigrationCb, MigrationCb didDoMigrationCb)
 {
-    lrc::api::Lrc::holdConferences.store(true);
 #ifndef ENABLE_LIBWRAP
     // Replace locale for timestamps
     std::locale::global(std::locale(""));
diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp
index 84f81cdc..a4071bd2 100644
--- a/src/newcallmodel.cpp
+++ b/src/newcallmodel.cpp
@@ -139,8 +139,12 @@ public:
      * Retrieve active conferences from the daemon and init the model
      */
     void initConferencesFromDaemon();
+    /**
+     * Set a call as the current call (hold other calls)
+     */
+    void setCurrentCall(const std::string& callId);
     bool manageCurrentCall_ {true};
-    std::string currentCall_ {};
+    bool dontHoldConferences_ {false};
 
     std::map<std::string, std::string> pendingConferences_;
 public Q_SLOTS:
@@ -319,7 +323,7 @@ NewCallModel::togglePause(const std::string& callId) const
     if (call->status == call::Status::PAUSED) {
         if (call->type == call::Type::DIALOG) {
             CallManager::instance().unhold(callId.c_str());
-            setCurrentCall(callId);
+            pimpl_->setCurrentCall(callId);
         } else {
             CallManager::instance().unholdConference(callId.c_str());
         }
@@ -578,37 +582,19 @@ NewCallModelPimpl::initConferencesFromDaemon()
 }
 
 void
-NewCallModel::setCurrentCall(const std::string& callId) const
+NewCallModelPimpl::setCurrentCall(const std::string& callId)
 {
-    if (!pimpl_->manageCurrentCall_) return;
-    auto it = pimpl_->pendingConferences_.find(callId);
+    if (!manageCurrentCall_) return;
+    auto it = pendingConferences_.find(callId);
     // Set current call only if not adding this call
     // to a current conference
-    if (it != pimpl_->pendingConferences_.end()) return;
-    if (!hasCall(callId)) return;
-
-
-    // The client should be able to set the current call multiple times
-    if (pimpl_->currentCall_ == callId) return;
-    pimpl_->currentCall_ = callId;
-
-    // Unhold call
-    auto& call = pimpl_->calls[callId];
-    if (call->status == call::Status::PAUSED) {
-        auto& call = pimpl_->calls[callId];
-        if (call->type == call::Type::DIALOG) {
-            CallManager::instance().unhold(callId.c_str());
-        } else {
-            CallManager::instance().unholdConference(callId.c_str());
-        }
-    }
-
+    if (it != pendingConferences_.end()) return;
     std::vector<std::string> filterCalls;
     QStringList conferences = CallManager::instance().getConferenceList();
     for (const auto& confId : conferences) {
         QStringList callList = CallManager::instance().getParticipantList(confId);
-        foreach(const auto& cid, callList) {
-            filterCalls.emplace_back(cid.toStdString());
+        foreach(const auto& callId, callList) {
+            filterCalls.emplace_back(callId.toStdString());
         }
     }
     for (const auto& cid : Lrc::activeCalls()) {
@@ -617,12 +603,11 @@ NewCallModel::setCurrentCall(const std::string& callId) const
             CallManager::instance().hold(cid.c_str());
         }
     }
-    if (!lrc::api::Lrc::holdConferences) {
+    if (dontHoldConferences_) {
         return;
     }
     for (const auto& confId : conferences) {
-        if (callId != confId.toStdString())
-            CallManager::instance().holdConference(confId);
+        CallManager::instance().holdConference(confId);
     }
 }
 
@@ -710,18 +695,17 @@ NewCallModelPimpl::slotCallStateChanged(const std::string& callId, const std::st
     // NOTE: signal emission order matters, always emit CallStatusChanged before CallEnded
     emit linked.callStatusChanged(callId, code);
 
-    if (call->status == call::Status::OUTGOING_RINGING
-        && linked.owner.profileInfo.type != profile::Type::SIP) {
-        linked.setCurrentCall(callId);
+    if (call->status == call::Status::OUTGOING_RINGING) {
+        setCurrentCall(callId);
     } else if (call->status == call::Status::ENDED) {
         emit linked.callEnded(callId);
     } else if (call->status == call::Status::IN_PROGRESS) {
         if (previousStatus == call::Status::INCOMING_RINGING
                 || previousStatus == call::Status::OUTGOING_RINGING) {
 
-            if (previousStatus == call::Status::INCOMING_RINGING
-                && linked.owner.profileInfo.type != profile::Type::SIP)
-                linked.setCurrentCall(callId);
+            if (previousStatus == call::Status::INCOMING_RINGING)
+                    setCurrentCall(callId);
+
             call->startTime = std::chrono::steady_clock::now();
             emit linked.callStarted(callId);
             sendProfile(callId);
-- 
GitLab