connectionmanager: do not cancel all waiting channel if first is declined

backport of 22d5417da3023095695d3b9655403b5632f528db in jami-daemon

Change-Id: I1ccf2edfad8b0d69be08e64ab894bb52027088a7
diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp
index fc104ed..03e4c65 100644
--- a/src/connectionmanager.cpp
+++ b/src/connectionmanager.cpp
@@ -329,7 +329,7 @@
 
     std::map<DeviceId, PendingOperations> pendingOperations_ {};
 
-    void executePendingOperations(const DeviceId& deviceId, const dht::Value::Id& vid, const std::shared_ptr<ChannelSocket>& sock)
+    void executePendingOperations(const DeviceId& deviceId, const dht::Value::Id& vid, const std::shared_ptr<ChannelSocket>& sock, bool accepted = true)
     {
         std::vector<PendingCb> ret;
         std::unique_lock<std::mutex> lk(connectCbsMtx_);
@@ -351,7 +351,8 @@
         } else if (auto n = pendingOperations.connecting.extract(vid)) {
             ret.emplace_back(std::move(n.mapped()));
             // If sock is nullptr, execute if it's the last connecting operation
-            if (!sock && pendingOperations.connecting.empty()) {
+            // If accepted is false, it means that underlying socket is ok, but channel is declined
+            if (!sock && pendingOperations.connecting.empty() && accepted) {
                 for (auto& [vid, cb] : pendingOperations.waiting)
                     ret.emplace_back(std::move(cb));
                 pendingOperations.waiting.clear();
@@ -799,11 +800,11 @@
             shared->executePendingOperations(deviceId, vid, nullptr);
     });
     channelSock->onReady(
-        [wSock = std::weak_ptr<ChannelSocket>(channelSock), name, deviceId, vid, w = weak()]() {
+        [wSock = std::weak_ptr<ChannelSocket>(channelSock), name, deviceId, vid, w = weak()](bool accepted) {
             auto shared = w.lock();
             auto channelSock = wSock.lock();
             if (shared)
-                shared->executePendingOperations(deviceId, vid, channelSock);
+                shared->executePendingOperations(deviceId, vid, accepted ? channelSock : nullptr, accepted);
         });
 
     ChannelRequest val;