From 770ed045e5c6b38704d1f5b0c2b3f81b62960af0 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Thu, 22 Jan 2026 17:08:25 +0100 Subject: [PATCH] Do not automatically select chat when it is added in list because of its Created state, only force selection when user is manually creating it --- Linphone/core/chat/ChatList.cpp | 14 ++++++++++---- Linphone/core/chat/ChatList.hpp | 2 +- Linphone/core/chat/ChatProxy.cpp | 2 +- Linphone/model/core/CoreModel.hpp | 3 +++ Linphone/model/tool/ToolModel.cpp | 2 ++ .../view/Control/Display/Chat/ChatListView.qml | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Linphone/core/chat/ChatList.cpp b/Linphone/core/chat/ChatList.cpp index 1a0129329..00e4bc416 100644 --- a/Linphone/core/chat/ChatList.cpp +++ b/Linphone/core/chat/ChatList.cpp @@ -150,7 +150,7 @@ void ChatList::setSelf(QSharedPointer me) { return; } auto chatCore = ChatCore::create(room); - mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore); }); + mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore, false); }); }; mModelConnection->makeConnectToModel(&CoreModel::messageReceived, [this, addChatToList](const std::shared_ptr &core, @@ -178,6 +178,11 @@ void ChatList::setSelf(QSharedPointer me) { [this, addChatToList](const std::shared_ptr &core, const std::shared_ptr &chatRoom, linphone::ChatRoom::State state) { if (state == linphone::ChatRoom::State::Created) { + bool sendAddSignal = false; + if (chatRoom == CoreModel::getInstance()->mChatRoomBeingCreated) { + sendAddSignal = true; + } + CoreModel::getInstance()->mChatRoomBeingCreated = nullptr; if (chatRoom->getConferenceInfo()) { qWarning() << log().arg("Chatroom created during a conference, return"); return; @@ -191,7 +196,8 @@ void ChatList::setSelf(QSharedPointer me) { return; } auto chatCore = ChatCore::create(chatRoom); - mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore); }); + mModelConnection->invokeToCore( + [this, chatCore, sendAddSignal] { addChatInList(chatCore, sendAddSignal); }); } }); @@ -212,7 +218,7 @@ int ChatList::findChatIndex(ChatGui *chatGui) { return it == chatList.end() ? -1 : std::distance(chatList.begin(), it); } -bool ChatList::addChatInList(QSharedPointer chatCore) { +bool ChatList::addChatInList(QSharedPointer chatCore, bool emitAddSignal) { mustBeInMainThread(log().arg(Q_FUNC_INFO)); if (chatCore->getIdentifier().isEmpty()) { qWarning() << "ChatRoom with invalid identifier cannot be added to the list, return"; @@ -225,7 +231,7 @@ bool ChatList::addChatInList(QSharedPointer chatCore) { if (it == chatList.end()) { connectItem(chatCore); add(chatCore); - emit chatAdded(chatCore); + if (emitAddSignal) emit chatAdded(chatCore); return true; } return false; diff --git a/Linphone/core/chat/ChatList.hpp b/Linphone/core/chat/ChatList.hpp index 8f67bbe02..66ccbead6 100644 --- a/Linphone/core/chat/ChatList.hpp +++ b/Linphone/core/chat/ChatList.hpp @@ -42,7 +42,7 @@ public: void connectItem(QSharedPointer chat); int findChatIndex(ChatGui *chat); - bool addChatInList(QSharedPointer chatCore); + bool addChatInList(QSharedPointer chatCore, bool emitAddSignal); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; signals: diff --git a/Linphone/core/chat/ChatProxy.cpp b/Linphone/core/chat/ChatProxy.cpp index 2042dc553..492008cf8 100644 --- a/Linphone/core/chat/ChatProxy.cpp +++ b/Linphone/core/chat/ChatProxy.cpp @@ -72,7 +72,7 @@ int ChatProxy::findChatIndex(ChatGui *chatGui) { bool ChatProxy::addChatInList(ChatGui *chatGui) { auto chatList = dynamic_cast(sourceModel()); if (chatList && chatGui) { - return chatList->addChatInList(chatGui->mCore); + return chatList->addChatInList(chatGui->mCore, true); } return false; } diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 139446df8..85eca27c2 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -79,6 +79,9 @@ public: bool mEnd = false; linphone::ConfiguringState mConfigStatus; QString mConfigMessage; + // Used to get a chatroom created by user when trying to add + // one to the chat room list, so we can automatically select it + std::shared_ptr mChatRoomBeingCreated; std::shared_ptr mCore; std::shared_ptr mLogger; diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index 831ef7dfb..18edeca7c 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -757,6 +757,7 @@ std::shared_ptr ToolModel::createChatForAddress(std::shared_ return nullptr; } auto chatRoom = core->createChatRoom(params, participants); + CoreModel::getInstance()->mChatRoomBeingCreated = chatRoom; return chatRoom; } @@ -784,6 +785,7 @@ ToolModel::createGroupChatRoom(QString subject, std::listcreateChatRoom(params, participantsAddresses); if (!chatRoom) lWarning() << ("[ToolModel] Failed to create group chat"); + CoreModel::getInstance()->mChatRoomBeingCreated = chatRoom; return chatRoom; } diff --git a/Linphone/view/Control/Display/Chat/ChatListView.qml b/Linphone/view/Control/Display/Chat/ChatListView.qml index 1151cb0d7..60b7bd217 100644 --- a/Linphone/view/Control/Display/Chat/ChatListView.qml +++ b/Linphone/view/Control/Display/Chat/ChatListView.qml @@ -60,7 +60,7 @@ ListView { } } onChatAdded: (chat) => { - // mainItem.chatToSelect = chat + mainItem.chatToSelect = chat } onRowsRemoved: { var index = mainItem.currentIndex