From 21e8e2aaba7a20f5d88b26362b267e580543a411 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Tue, 2 Dec 2025 14:26:07 +0100 Subject: [PATCH] ChatCore: wait for deleted state before emitting deleted signal fix chats selection and remove useless signal --- Linphone/core/chat/ChatCore.cpp | 3 +- Linphone/core/chat/ChatList.cpp | 43 +++++-------------- Linphone/core/chat/ChatList.hpp | 3 -- Linphone/core/chat/ChatProxy.cpp | 4 -- Linphone/core/chat/ChatProxy.hpp | 2 - Linphone/data/languages/de.ts | 28 ++++++------ Linphone/data/languages/en.ts | 28 ++++++------ Linphone/data/languages/fr.ts | 28 ++++++------ Linphone/model/chat/ChatModel.cpp | 3 +- .../Control/Display/Chat/ChatListView.qml | 11 ----- 10 files changed, 54 insertions(+), 99 deletions(-) diff --git a/Linphone/core/chat/ChatCore.cpp b/Linphone/core/chat/ChatCore.cpp index c60cc6dce..149b8262f 100644 --- a/Linphone/core/chat/ChatCore.cpp +++ b/Linphone/core/chat/ChatCore.cpp @@ -163,14 +163,13 @@ void ChatCore::setSelf(QSharedPointer me) { mChatModelConnection->makeConnectToCore(&ChatCore::lDelete, [this]() { mChatModelConnection->invokeToModel([this]() { mChatModel->deleteChatRoom(); }); }); - mChatModelConnection->makeConnectToModel( - &ChatModel::deleted, [this]() { mChatModelConnection->invokeToCore([this]() { emit deleted(); }); }); mChatModelConnection->makeConnectToModel( &ChatModel::stateChanged, [this](const std::shared_ptr &chatRoom, linphone::ChatRoom::State newState) { auto state = LinphoneEnums::fromLinphone(newState); bool isReadOnly = chatRoom->isReadOnly(); + if (newState == linphone::ChatRoom::State::Deleted) emit deleted(); mChatModelConnection->invokeToCore([this, state, isReadOnly]() { setChatRoomState(state); setIsReadOnly(isReadOnly); diff --git a/Linphone/core/chat/ChatList.cpp b/Linphone/core/chat/ChatList.cpp index 94e1f7fc2..8061f19b6 100644 --- a/Linphone/core/chat/ChatList.cpp +++ b/Linphone/core/chat/ChatList.cpp @@ -54,13 +54,15 @@ ChatList::~ChatList() { } void ChatList::connectItem(QSharedPointer chat) { - connect(chat.get(), &ChatCore::deleted, this, [this, chat] { - disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr); - disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr); - disconnect(chat.get(), &ChatCore::lastMessageChanged, this, nullptr); - disconnect(chat.get(), &ChatCore::deleted, this, nullptr); - remove(chat); - }); + connect( + chat.get(), &ChatCore::deleted, this, + [this, chat] { + disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr); + disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr); + disconnect(chat.get(), &ChatCore::lastMessageChanged, this, nullptr); + remove(chat); + }, + Qt::SingleShotConnection); auto dataChange = [this, chat] { int i = -1; get(chat.get(), &i); @@ -167,30 +169,6 @@ void ChatList::setSelf(QSharedPointer me) { addChatToList(core, room, message); }); - mModelConnection->makeConnectToModel( - &CoreModel::chatRoomStateChanged, - [this](const std::shared_ptr &core, const std::shared_ptr &chatRoom, - linphone::ChatRoom::State state) { - auto chatRoomAccount = chatRoom->getAccount(); - auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); - if (!chatRoomAccount || !currentAccount || !chatRoomAccount->getParams() || !currentAccount->getParams() || - !chatRoomAccount->getParams()->getIdentityAddress()->weakEqual( - currentAccount->getParams()->getIdentityAddress())) { - lInfo() << "ChatRoom state of another account changed, return"; - return; - } - if (chatRoom->getState() == linphone::ChatRoom::State::Created) { - lInfo() << "ChatRoom created, add it to the list" << chatRoom.get(); - auto chatCore = ChatCore::create(chatRoom); - if (chatCore) { - mModelConnection->invokeToCore([this, chatCore] { - bool added = addChatInList(chatCore); - if (added) emit chatCreated(new ChatGui(chatCore)); - }); - } - } - }); - connect(this, &ChatList::filterChanged, [this](QString filter) { mFilter = filter; lUpdate(); @@ -212,8 +190,7 @@ bool ChatList::addChatInList(QSharedPointer chatCore) { mustBeInMainThread(log().arg(Q_FUNC_INFO)); auto chatList = getSharedList(); auto it = std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer item) { - return item && chatCore && item->getModel() && chatCore->getModel() && - item->getModel()->getMonitor() == chatCore->getModel()->getMonitor(); + return item && chatCore && item->getIdentifier() == chatCore->getIdentifier(); }); if (it == chatList.end()) { connectItem(chatCore); diff --git a/Linphone/core/chat/ChatList.hpp b/Linphone/core/chat/ChatList.hpp index 6757e615f..0ec7ab87a 100644 --- a/Linphone/core/chat/ChatList.hpp +++ b/Linphone/core/chat/ChatList.hpp @@ -50,9 +50,6 @@ signals: void filterChanged(QString filter); void chatAdded(); void chatUpdated(); - // emit this signal to force selection when - // newly created chat added to the list - void chatCreated(ChatGui *chatGui); private: QString mFilter; diff --git a/Linphone/core/chat/ChatProxy.cpp b/Linphone/core/chat/ChatProxy.cpp index 84198c24c..fd30a71a6 100644 --- a/Linphone/core/chat/ChatProxy.cpp +++ b/Linphone/core/chat/ChatProxy.cpp @@ -46,10 +46,6 @@ void ChatProxy::setSourceModel(QAbstractItemModel *model) { connect(this, &ChatProxy::filterTextChanged, newChatList, [this, newChatList] { emit newChatList->filterChanged(getFilterText()); }); connect(newChatList, &ChatList::chatAdded, this, [this] { invalidate(); }); - connect(newChatList, &ChatList::chatCreated, this, [this](ChatGui *chatGui) { - invalidate(); - emit chatCreated(chatGui); - }); connect(newChatList, &ChatList::dataChanged, this, [this] { invalidate(); }); } QSortFilterProxyModel::setSourceModel(newChatList); diff --git a/Linphone/core/chat/ChatProxy.hpp b/Linphone/core/chat/ChatProxy.hpp index 1a40e1fb4..f9e6c48cf 100644 --- a/Linphone/core/chat/ChatProxy.hpp +++ b/Linphone/core/chat/ChatProxy.hpp @@ -41,8 +41,6 @@ public: Q_INVOKABLE int findChatIndex(ChatGui *chatGui); Q_INVOKABLE bool addChatInList(ChatGui *chatGui); -signals: - void chatCreated(ChatGui *chatGui); protected: QSharedPointer mList; diff --git a/Linphone/data/languages/de.ts b/Linphone/data/languages/de.ts index 3f20dbe60..e8980d8fb 100644 --- a/Linphone/data/languages/de.ts +++ b/Linphone/data/languages/de.ts @@ -2099,65 +2099,65 @@ ChatListView - + chat_message_is_writing_info %1 is writing… - + chat_message_draft_sending_text - + chat_room_delete "Delete" Löschen - + chat_room_mute - + chat_room_unmute "Mute" - + chat_room_mark_as_read "Mark as read" - + chat_room_leave "leave" - + chat_list_leave_chat_popup_title leave the conversation ? - + chat_list_leave_chat_popup_message You will not be able to send or receive messages in this conversation anymore. Do You want to continue ? - + chat_list_delete_chat_popup_title Delete the conversation ? - + chat_list_delete_chat_popup_message This conversation and all its messages will be deleted. Do You want to continue ? @@ -2723,19 +2723,19 @@ Error Fehler - + information_popup_error_title Erreur Fehler - + information_popup_voicemail_address_undefined_message L'URI de messagerie vocale n'est pas définie. Die Voicemail-URI ist nicht definiert. - + account_settings_name_accessible_name Account settings of %1 diff --git a/Linphone/data/languages/en.ts b/Linphone/data/languages/en.ts index 9dd57e667..e7566ce3d 100644 --- a/Linphone/data/languages/en.ts +++ b/Linphone/data/languages/en.ts @@ -2086,65 +2086,65 @@ ChatListView - + chat_message_is_writing_info %1 is writing… %1 is writing… - + chat_message_draft_sending_text Draft : %1 - + chat_room_delete "Delete" Delete - + chat_room_mute Mute - + chat_room_unmute "Mute" Unmute - + chat_room_mark_as_read "Mark as read" Mark as read - + chat_room_leave "leave" Leave - + chat_list_leave_chat_popup_title leave the conversation ? Leave the conversation ? - + chat_list_leave_chat_popup_message You will not be able to send or receive messages in this conversation anymore. Do You want to continue ? You will not be able to send or receive messages in this conversation anymore. Do You want to continue ? - + chat_list_delete_chat_popup_title Delete the conversation ? Delete the conversation ? - + chat_list_delete_chat_popup_message This conversation and all its messages will be deleted. Do You want to continue ? This conversation and all its messages will be deleted. Do You want to continue ? @@ -2682,19 +2682,19 @@ Only your correspondent can decrypt them. Contact - + information_popup_error_title Erreur Error - + information_popup_voicemail_address_undefined_message L'URI de messagerie vocale n'est pas définie. The voicemail URI is not defined. - + account_settings_name_accessible_name Account settings of %1 Account settings of %1 diff --git a/Linphone/data/languages/fr.ts b/Linphone/data/languages/fr.ts index 40482360d..4387486c5 100644 --- a/Linphone/data/languages/fr.ts +++ b/Linphone/data/languages/fr.ts @@ -2086,65 +2086,65 @@ ChatListView - + chat_message_is_writing_info %1 is writing… %1 est en train d'écrire… - + chat_message_draft_sending_text Brouillon : %1 - + chat_room_delete "Delete" Supprimer - + chat_room_mute Mettre en sourdine - + chat_room_unmute "Mute" Enlever la sourdine - + chat_room_mark_as_read "Mark as read" Marquer comme lu - + chat_room_leave "leave" Quitter la conversation - + chat_list_leave_chat_popup_title leave the conversation ? Quitter la conversation ? - + chat_list_leave_chat_popup_message You will not be able to send or receive messages in this conversation anymore. Do You want to continue ? Vous ne pourrez plus envoyer ou recevoir de messages dans cette conversation. Souhaitez-vous continuer ? - + chat_list_delete_chat_popup_title Delete the conversation ? Supprimer la conversation ? - + chat_list_delete_chat_popup_message This conversation and all its messages will be deleted. Do You want to continue ? La conversation et tous ses messages seront supprimés. Souhaitez-vous continuer ? @@ -2682,19 +2682,19 @@ en bout. Seul votre correspondant peut les déchiffrer. Contact - + information_popup_error_title Erreur Erreur - + information_popup_voicemail_address_undefined_message L'URI de messagerie vocale n'est pas définie. L'URI de messagerie vocale n'est pas définie. - + account_settings_name_accessible_name Account settings of %1 Paramaètres de compte de %1 diff --git a/Linphone/model/chat/ChatModel.cpp b/Linphone/model/chat/ChatModel.cpp index a8d9a52fb..88bd69e07 100644 --- a/Linphone/model/chat/ChatModel.cpp +++ b/Linphone/model/chat/ChatModel.cpp @@ -44,7 +44,7 @@ ChatModel::ChatModel(const std::shared_ptr &chatroom, QObjec ChatModel::~ChatModel() { mustBeInLinphoneThread("~" + getClassName()); - disconnect(CoreModel::getInstance().get(), &CoreModel::messageReadInChatRoom, this, nullptr); + disconnect(CoreModel::getInstance().get(), &CoreModel::chatRoomRead, this, nullptr); } QDateTime ChatModel::getLastUpdateTime() { @@ -173,7 +173,6 @@ void ChatModel::leave() { void ChatModel::deleteChatRoom() { CoreModel::getInstance()->getCore()->deleteChatRoom(mMonitor); - emit deleted(); } std::shared_ptr diff --git a/Linphone/view/Control/Display/Chat/ChatListView.qml b/Linphone/view/Control/Display/Chat/ChatListView.qml index 7037c1987..1291b6d5e 100644 --- a/Linphone/view/Control/Display/Chat/ChatListView.qml +++ b/Linphone/view/Control/Display/Chat/ChatListView.qml @@ -18,13 +18,11 @@ ListView { property real busyIndicatorSize: Utils.getSizeWithScreenRatio(60) property ChatGui currentChatGui: model.getAt(currentIndex) || null - onCurrentIndexChanged: console.log("current index changed", currentIndex) onCurrentChatGuiChanged: positionViewAtIndex(currentIndex, ListView.Center) property ChatGui chatToSelect: null property ChatGui chatToSelectLater: null onChatToSelectChanged: { if (chatToSelect) { - console.log("chat to select changed, select", (chatToSelect ? chatToSelect.core.title : "NULL")) // first clear the chatToSelect property in case we need to // force adding the chat to the list and the layout changes var toselect = chatToSelect @@ -72,9 +70,6 @@ ListView { selectChat(mainItem.currentChatGui) } } - onChatCreated: (chat) => { - selectChat(chat) - } } // flickDeceleration: 10000 spacing: Utils.getSizeWithScreenRatio(10) @@ -100,12 +95,6 @@ ListView { onActiveFocusChanged: if (activeFocus && currentIndex < 0 && count > 0) currentIndex = 0 - onAtYEndChanged: { - if (atYEnd && count > 0) { - chatProxy.displayMore() - } - } - //---------------------------------------------------------------- function moveToCurrentItem() { if (mainItem.currentIndex >= 0)