From 6b1a6324b907d1d6e497bb77d39c5549510f0277 Mon Sep 17 00:00:00 2001
From: Pierre Lespagnol <pierre.lespagnol@savoirfairelinux.com>
Date: Thu, 8 Apr 2021 17:32:15 -0400
Subject: [PATCH] conference: fix update missing at the end of conference

Change-Id: I99eec91ed65ab5c2a6d2b0e021e1490d0d7b5df1
Gitlab: #505
---
 src/call.cpp       | 27 ++++++++++++++++++++++++++-
 src/call.h         |  2 ++
 src/conference.cpp | 14 +++-----------
 src/manager.cpp    |  9 +++++++--
 4 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/src/call.cpp b/src/call.cpp
index 18d5239d1a..5b568d5b9a 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -691,7 +691,32 @@ Call::sendConfOrder(const Json::Value& root)
     wbuilder["commentStyle"] = "None";
     wbuilder["indentation"] = "";
     messages["application/confOrder+json"] = Json::writeString(wbuilder, root);
-    sendTextMessage(messages, getPeerDisplayName());
+
+    auto w = getAccount();
+    auto account = w.lock();
+    if (account)
+        sendTextMessage(messages, account->getFromUri());
+}
+
+void
+Call::sendConfInfo(const std::string& json)
+{
+    std::map<std::string, std::string> messages;
+    Json::StreamWriterBuilder wbuilder;
+    wbuilder["commentStyle"] = "None";
+    wbuilder["indentation"] = "";
+    messages["application/confInfo+json"] = json;
+
+    auto w = getAccount();
+    auto account = w.lock();
+    if (account)
+        sendTextMessage(messages, account->getFromUri());
+}
+
+void
+Call::resetConfInfo()
+{
+    sendConfInfo("{}");
 }
 
 } // namespace jami
diff --git a/src/call.h b/src/call.h
index 9ddf1c6ac9..b4e5440d6d 100644
--- a/src/call.h
+++ b/src/call.h
@@ -347,6 +347,8 @@ public: // media management
 
     std::unique_ptr<AudioDeviceGuard> audioGuard;
     void sendConfOrder(const Json::Value& root);
+    void sendConfInfo(const std::string& json);
+    void resetConfInfo();
 
 protected:
     virtual void merge(Call& scall);
diff --git a/src/conference.cpp b/src/conference.cpp
index 4c527b684d..ffd65c338a 100644
--- a/src/conference.cpp
+++ b/src/conference.cpp
@@ -143,14 +143,7 @@ Conference::~Conference()
         if (auto call = getCall(participant_id)) {
             call->exitConference();
             // Reset distant callInfo
-            auto w = call->getAccount();
-            auto account = w.lock();
-            if (!account)
-                continue;
-            call->sendTextMessage(std::map<std::string, std::string> {{"application/confInfo+json",
-                                                                       "[]"}},
-                                  account->getFromUri());
-
+            call->resetConfInfo();
             // Trigger the SIP negotiation to update the resolution for the remaining call
             // ideally this sould be done without renegotiation
             call->switchInput(
@@ -398,9 +391,8 @@ Conference::sendConferenceInfos()
             dht::ThreadPool::io().run([call,
                                        confInfo = getConfInfoHostUri(account->getUsername()
                                                                          + "@ring.dht",
-                                                                     call->getPeerNumber()),
-                                       from = account->getFromUri()] {
-                call->sendTextMessage({{"application/confInfo+json", confInfo.toString()}}, from);
+                                                                     call->getPeerNumber())] {
+                call->sendConfInfo(confInfo.toString());
             });
         }
     }
diff --git a/src/manager.cpp b/src/manager.cpp
index 1a28aec0ae..da43df0206 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -1098,8 +1098,13 @@ Manager::hangupConference(const std::string& id)
     JAMI_DBG("Hangup conference %s", id.c_str());
     if (auto conf = getConferenceFromID(id)) {
         ParticipantSet participants(conf->getParticipantList());
-        for (const auto& item : participants)
-            hangupCall(item);
+        for (const auto& callId : participants) {
+            if (auto call = getCallFromCallID(callId)) {
+                call->resetConfInfo();
+                call->exitConference();
+            }
+            hangupCall(callId);
+        }
         pimpl_->unsetCurrentCall();
         return true;
     }
-- 
GitLab