From 3673b0646ccfda3492a9ff4d5abfd07d7b465ee3 Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Tue, 21 May 2024 16:56:52 -0400
Subject: [PATCH] conversations: hide call view when swarm call is finished.

In the current implementation, the chatViewContainer of callStackView
is not destroyed for a swarm conference call because there are no
signals for call changes.This patch ensures chatViewContainer is used
when there is no call.

GitLab: #1625
Change-Id: Iefc39b747d92543244d30aa987eda134ff0a03f3
---
 src/app/mainview/ConversationView.qml |  9 ++++++++-
 src/libclient/callmodel.cpp           | 11 ++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/app/mainview/ConversationView.qml b/src/app/mainview/ConversationView.qml
index 299602464..04414def7 100644
--- a/src/app/mainview/ConversationView.qml
+++ b/src/app/mainview/ConversationView.qml
@@ -65,8 +65,15 @@ ListSelectionView {
                 id: chatView
                 anchors.fill: parent
 
+                // Use callStackView.chatViewContainer only when hasCall is true
+                // and callStackView.chatViewContainer not null.
+                // Because after a swarm call ends, callStackView.chatViewContainer might not be null
+                // due to a lack of call state change signals for the swarm call.
+                readonly property bool hasCall: CurrentConversation.hasCall
+                readonly property var inCallChatContainer: hasCall ? callStackView.chatViewContainer : null
+
                 // Parent the chat view to the call stack view when in call.
-                parent: callStackView.chatViewContainer ? callStackView.chatViewContainer : chatViewContainer
+                parent: inCallChatContainer ? inCallChatContainer : chatViewContainer
                 inCallView: parent === callStackView.chatViewContainer
 
                 readonly property string currentConvId: CurrentConversation.id
diff --git a/src/libclient/callmodel.cpp b/src/libclient/callmodel.cpp
index 83513d500..373c0f3a5 100644
--- a/src/libclient/callmodel.cpp
+++ b/src/libclient/callmodel.cpp
@@ -186,6 +186,7 @@ public:
     Lrc& lrc;
 
     QList<call::PendingConferenceeInfo> pendingConferencees_;
+    QString waitForConference_ {};
 
 public Q_SLOTS:
     /**
@@ -398,7 +399,11 @@ CallModel::createCall(const QString& uri, bool isAudioOnly, VectorMapStringStrin
 #endif // ENABLE_LIBWRAP
 
     if (callId.isEmpty()) {
-        qDebug() << "no call placed between (account: " << owner.id << ", contact: " << uri << ")";
+        if (uri.startsWith("swarm:")) {
+            pimpl_->waitForConference_ = uri;
+            return {};
+        }
+        qWarning() << "no call placed between (account: " << owner.id << ", contact: " << uri << ")";
         return "";
     }
 
@@ -1735,6 +1740,10 @@ CallModelPimpl::slotConferenceCreated(const QString& accountId, const QString& c
     QString currentCallId = currentCall_;
     if (!conversationId.isEmpty()) {
         Q_EMIT linked.callAddedToConference("", conversationId, confId);
+        if (currentCall_ != confId && waitForConference_.contains(conversationId)) {
+            currentCall_ = confId;
+            Q_EMIT linked.currentCallChanged(confId);
+        }
     } else {
         QStringList callList = CallManager::instance().getParticipantList(linked.owner.id, confId);
         Q_FOREACH (const auto& call, callList) {
-- 
GitLab