From 59c8a75cc3882b1f1fb462ff17eb7e912aad6180 Mon Sep 17 00:00:00 2001
From: ababi <albert.babi@savoirfairelinux.com>
Date: Wed, 20 Jan 2021 14:40:05 +0100
Subject: [PATCH] callview: fix conversation selection when call ends

- avoid using smartlist index change for conversation selection
when call ends (instead it can be triggered from calladapter)
- break long lines

Gitlab: #260

Change-Id: Iaa1f9269d9ba6889fb1a7e466cd586fa86263bc7
---
 src/calladapter.cpp                               |  6 ++----
 src/conversationsadapter.cpp                      |  3 +--
 .../components/ConversationSmartListView.qml      |  2 ++
 .../ConversationSmartListViewItemDelegate.qml     | 15 ++++++++-------
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/calladapter.cpp b/src/calladapter.cpp
index 0174a9cc6..6686cc5f0 100644
--- a/src/calladapter.cpp
+++ b/src/calladapter.cpp
@@ -392,6 +392,7 @@ CallAdapter::connectCallModel(const QString& accountId)
             case lrc::api::call::Status::TIMEOUT:
             case lrc::api::call::Status::TERMINATING: {
                 lrcInstance_->renderer()->removeDistantRenderer(callId);
+                emit callSetupMainViewRequired(accountId, convInfo.uid);
                 if (convInfo.uid.isEmpty()) {
                     break;
                 }
@@ -424,9 +425,8 @@ CallAdapter::connectCallModel(const QString& accountId)
                                 /*
                                  * Reset the call view corresponding accountId, uid.
                                  */
+                                lrcInstance_->setSelectedConvId(otherConv.uid);
                                 updateCall(otherConv.uid, otherConv.accountId, forceCallOnly);
-
-                                emit callSetupMainViewRequired(accountId, convInfo.uid);
                             }
                         }
                     }
@@ -451,8 +451,6 @@ CallAdapter::connectCallModel(const QString& accountId)
             default:
                 break;
             }
-
-            emit lrcInstance_->updateSmartList();
         });
 
     remoteRecordingChangedConnection_ = QObject::connect(
diff --git a/src/conversationsadapter.cpp b/src/conversationsadapter.cpp
index 8d4510ddb..228f3f18f 100644
--- a/src/conversationsadapter.cpp
+++ b/src/conversationsadapter.cpp
@@ -192,7 +192,6 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
         currentConversationModel, &lrc::api::ConversationModel::modelChanged, [this]() {
             conversationSmartListModel_->fillConversationsList();
             updateConversationsFilterWidget();
-            emit updateListViewRequested();
 
             auto* convModel = lrcInstance_->getCurrentConversationModel();
             const auto& convInfo = lrcInstance_->getConversationFromConvUid(
@@ -257,7 +256,7 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
                            &lrc::api::ConversationModel::conversationCleared,
                            [this](const QString& convUid) {
                                // If currently selected, switch to welcome screen (deselecting
-                               // current smartlist item ).
+                               // current smartlist item).
                                if (convUid != lrcInstance_->getCurrentConvUid()) {
                                    return;
                                }
diff --git a/src/mainview/components/ConversationSmartListView.qml b/src/mainview/components/ConversationSmartListView.qml
index 7fe91f767..7fc6dad12 100644
--- a/src/mainview/components/ConversationSmartListView.qml
+++ b/src/mainview/components/ConversationSmartListView.qml
@@ -42,6 +42,8 @@ ListView {
     }
 
     function repositionIndex(uid = "") {
+        // Only update index if it has changed
+        var currentI = root.currentIndex
         if (uid === "")
             uid = mainView.currentConvUID
         root.currentIndex = -1
diff --git a/src/mainview/components/ConversationSmartListViewItemDelegate.qml b/src/mainview/components/ConversationSmartListViewItemDelegate.qml
index a7a4bc164..d1c00efb9 100644
--- a/src/mainview/components/ConversationSmartListViewItemDelegate.qml
+++ b/src/mainview/components/ConversationSmartListViewItemDelegate.qml
@@ -41,12 +41,11 @@ ItemDelegate {
     Connections {
         target: conversationSmartListView
 
-
         // Hack, make sure that smartListItemDelegate does not show extra item
         // when searching new contacts.
         function onForceUpdatePotentialInvalidItem() {
-            smartListItemDelegate.visible = conversationSmartListView.model.rowCount(
-                        ) <= index ? false : true
+            smartListItemDelegate.visible =
+                    conversationSmartListView.model.rowCount() <= index ? false : true
         }
 
 
@@ -123,8 +122,9 @@ ItemDelegate {
                 id: textMetricsConversationSmartListUserName
                 font: conversationSmartListUserName.font
                 elide: Text.ElideRight
-                elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth - conversationSmartListUserImage.width-32) :
-                                                  smartListItemDelegate.width - lastInteractionPreferredWidth
+                elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth
+                                                   - conversationSmartListUserImage.width-32)
+                                                : smartListItemDelegate.width - lastInteractionPreferredWidth
                 text: DisplayName === undefined ? "" : DisplayName
             }
             text: textMetricsConversationSmartListUserName.elidedText
@@ -161,8 +161,9 @@ ItemDelegate {
             id: textMetricsConversationSmartListUserLastInteractionMessage
             font: conversationSmartListUserLastInteractionMessage.font
             elide: Text.ElideRight
-            elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth - conversationSmartListUserImage.width-32) :
-                                              smartListItemDelegate.width - lastInteractionPreferredWidth
+            elideWidth: LastInteractionDate ? (smartListItemDelegate.width - lastInteractionPreferredWidth
+                                               - conversationSmartListUserImage.width-32)
+                                            : smartListItemDelegate.width - lastInteractionPreferredWidth
             text: InCall ? UtilsAdapter.getCallStatusStr(CallState) : (Draft ? Draft : LastInteraction)
         }
 
-- 
GitLab