From 8df5fb833c91b1573188c4aeaa63bddee39654e0 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Fri, 30 Jan 2026 16:17:21 +0100 Subject: [PATCH] check if safe connection is being destroyed before trying lock Add apply button and success/error toast for managing chatroom participants debug logs --- Linphone/core/chat/ChatCore.cpp | 13 +++++++--- Linphone/core/chat/ChatCore.hpp | 1 + Linphone/model/chat/ChatModel.cpp | 12 ++++++--- Linphone/model/chat/ChatModel.hpp | 3 ++- Linphone/tool/thread/SafeConnection.hpp | 3 ++- .../Page/Layout/Chat/ManageParticipants.qml | 25 ++++++++++++++++++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Linphone/core/chat/ChatCore.cpp b/Linphone/core/chat/ChatCore.cpp index 27e3ef7b4..cf2180e09 100644 --- a/Linphone/core/chat/ChatCore.cpp +++ b/Linphone/core/chat/ChatCore.cpp @@ -231,10 +231,8 @@ void ChatCore::setSelf(const QSharedPointer &me) { return; } if (mChatModel->getMonitor() != chatRoom) return; - lDebug() << log().arg("CHAT MESSAGE RECEIVED IN CHATROOM") << this << mChatModel->getTitle(); lInfo() << log().arg("Chat message received in chatroom") << this << mChatModel->getTitle(); - lInfo() << log().arg("Safe Connection =") << mChatModelConnection.get(); - lInfo() << log().arg("this =") << this; + lInfo() << log().arg("Connection =") << mChatModelConnection.get(); QList> list; for (auto &e : eventsLog) { if (!e) { @@ -391,6 +389,15 @@ void ChatCore::setSelf(const QSharedPointer &me) { setMeAdmin(meAdmin); }); }); + mChatModelConnection->makeConnectToModel( + &ChatModel::participantAddressesChanged, + [this](const std::shared_ptr &chatRoom, bool success) { + if (!success) { + auto participants = buildParticipants(chatRoom); + mChatModelConnection->invokeToCore([this, participants] { setParticipants(participants); }); + } + mChatModelConnection->invokeToCore([this, success] { emit participantAddressesChanged(success); }); + }); mChatModelConnection->makeConnectToCore(&ChatCore::lRemoveParticipantAtIndex, [this](int index) { mChatModelConnection->invokeToModel([this, index]() { mChatModel->removeParticipantAtIndex(index); }); }); diff --git a/Linphone/core/chat/ChatCore.hpp b/Linphone/core/chat/ChatCore.hpp index d8100cd79..992009cad 100644 --- a/Linphone/core/chat/ChatCore.hpp +++ b/Linphone/core/chat/ChatCore.hpp @@ -175,6 +175,7 @@ signals: void fileListChanged(); void isSecuredChanged(); void conferenceJoined(); + void participantAddressesChanged(bool success); void lDeleteMessage(ChatMessageGui *message); void lDelete(); diff --git a/Linphone/model/chat/ChatModel.cpp b/Linphone/model/chat/ChatModel.cpp index 1235e8c96..b21baea6d 100644 --- a/Linphone/model/chat/ChatModel.cpp +++ b/Linphone/model/chat/ChatModel.cpp @@ -237,17 +237,23 @@ void ChatModel::toggleParticipantAdminStatusAtIndex(int index) const { mMonitor->setParticipantAdminStatus(participant, !participant->isAdmin()); } -void ChatModel::setParticipantAddresses(const QStringList &addresses) const { +void ChatModel::setParticipantAddresses(const QStringList &addresses) { QSet s{addresses.cbegin(), addresses.cend()}; + bool soFarSoGood = true; for (auto p : mMonitor->getParticipants()) { auto address = Utils::coreStringToAppString(p->getAddress()->asStringUriOnly()); if (s.contains(address)) s.remove(address); - else mMonitor->removeParticipant(p); + else { + mMonitor->removeParticipants({p}); + } } for (const auto &a : s) { auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(a)); - if (address) mMonitor->addParticipant(address); + if (address) { + soFarSoGood &= mMonitor->addParticipants({address}); + } } + emit participantAddressesChanged(mMonitor, soFarSoGood); } //---------------------------------------------------------------// diff --git a/Linphone/model/chat/ChatModel.hpp b/Linphone/model/chat/ChatModel.hpp index e5df4b390..da65f07a4 100644 --- a/Linphone/model/chat/ChatModel.hpp +++ b/Linphone/model/chat/ChatModel.hpp @@ -84,7 +84,7 @@ public: void setEphemeralLifetime(int time); void setSubject(QString subject) const; void removeParticipantAtIndex(int index) const; - void setParticipantAddresses(const QStringList &addresses) const; + void setParticipantAddresses(const QStringList &addresses); void toggleParticipantAdminStatusAtIndex(int index) const; signals: @@ -94,6 +94,7 @@ signals: void mutedChanged(bool muted); void ephemeralEnableChanged(bool enable); void ephemeralLifetimeChanged(int time); + void participantAddressesChanged(const std::shared_ptr &chatRoom, bool success); private: DECLARE_ABSTRACT_OBJECT diff --git a/Linphone/tool/thread/SafeConnection.hpp b/Linphone/tool/thread/SafeConnection.hpp index 854c67934..e6b28e17f 100644 --- a/Linphone/tool/thread/SafeConnection.hpp +++ b/Linphone/tool/thread/SafeConnection.hpp @@ -66,7 +66,7 @@ template class SafeConnection : public QObject { // Use create functions. protected: - SafeConnection(const QSharedPointer &a, std::shared_ptr b) + SafeConnection(QSharedPointer a, std::shared_ptr b) : mCore(a), mModel(b), mCoreObject(a.get()), mModelObject(b.get()) { } SafeConnection(QSharedPointer a, QSharedPointer b) @@ -150,6 +150,7 @@ public: } bool tryLock() { + if (!this) return false; mLocker.lock(); auto coreLocked = mCore.lock(); auto modelLocked = mModel.lock(); diff --git a/Linphone/view/Page/Layout/Chat/ManageParticipants.qml b/Linphone/view/Page/Layout/Chat/ManageParticipants.qml index 9962e331d..6a37f6dbe 100644 --- a/Linphone/view/Page/Layout/Chat/ManageParticipants.qml +++ b/Linphone/view/Page/Layout/Chat/ManageParticipants.qml @@ -22,6 +22,22 @@ Rectangle { height: participantAddColumn.implicitHeight signal done() + Connections { + enabled: chatGui !== null + target: chatGui.core + function onParticipantAddressesChanged(success) { + if (!success) UtilsCpp.showInformationPopup(qsTr("info_popup_error_title"), + //: Error while setting participants ! + qsTr("info_popup_manage_participant_error_message"), false) + else { + mainItem.done() + UtilsCpp.showInformationPopup(qsTr("info_popup_success_title"), + //: Participants updated + qsTr("info_popup_manage_participant_updated_message"), true) + } + } + } + ColumnLayout { id: participantAddColumn anchors.fill: parent @@ -36,7 +52,6 @@ Rectangle { style: ButtonStyle.noBackground icon.source: AppIcons.leftArrow onClicked: { - mainItem.chatGui.core.lSetParticipantsAddresses(manageParticipantsLayout.selectedParticipants) mainItem.done() } } @@ -47,6 +62,14 @@ Rectangle { font: Typography.h4 Layout.fillWidth: true } + MediumButton { + id: manageParticipantsApplyButton + //: Apply + text: qsTr("apply_button_text") + onClicked: { + mainItem.chatGui.core.lSetParticipantsAddresses(manageParticipantsLayout.selectedParticipants) + } + } } AddParticipantsForm { id: manageParticipantsLayout