check if safe connection is being destroyed before trying lock

Add apply button and success/error toast for managing chatroom participants

debug logs
This commit is contained in:
Gaelle Braud 2026-01-30 16:17:21 +01:00
parent d9b879fac7
commit 8df5fb833c
6 changed files with 48 additions and 9 deletions

View file

@ -231,10 +231,8 @@ void ChatCore::setSelf(const QSharedPointer<ChatCore> &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<QSharedPointer<EventLogCore>> list;
for (auto &e : eventsLog) {
if (!e) {
@ -391,6 +389,15 @@ void ChatCore::setSelf(const QSharedPointer<ChatCore> &me) {
setMeAdmin(meAdmin);
});
});
mChatModelConnection->makeConnectToModel(
&ChatModel::participantAddressesChanged,
[this](const std::shared_ptr<linphone::ChatRoom> &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); });
});

View file

@ -175,6 +175,7 @@ signals:
void fileListChanged();
void isSecuredChanged();
void conferenceJoined();
void participantAddressesChanged(bool success);
void lDeleteMessage(ChatMessageGui *message);
void lDelete();

View file

@ -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<QString> 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);
}
//---------------------------------------------------------------//

View file

@ -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<linphone::ChatRoom> &chatRoom, bool success);
private:
DECLARE_ABSTRACT_OBJECT

View file

@ -66,7 +66,7 @@ template <class A, class B>
class SafeConnection : public QObject {
// Use create functions.
protected:
SafeConnection(const QSharedPointer<A> &a, std::shared_ptr<B> b)
SafeConnection(QSharedPointer<A> a, std::shared_ptr<B> b)
: mCore(a), mModel(b), mCoreObject(a.get()), mModelObject(b.get()) {
}
SafeConnection(QSharedPointer<A> a, QSharedPointer<B> b)
@ -150,6 +150,7 @@ public:
}
bool tryLock() {
if (!this) return false;
mLocker.lock();
auto coreLocked = mCore.lock();
auto modelLocked = mModel.lock();

View file

@ -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