From 7cd96583fc95583ce6623f7ea8246c69219cec01 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Mon, 6 Jun 2022 13:32:53 +0200 Subject: [PATCH] Rework auto mark as read on deleted/terminated chats. These cases come from a bug when the user may leave the chat room on ack timeout and then, we got persistent unread notification (SDK bug). --- CHANGELOG.md | 5 ++++ .../src/components/core/CoreManager.cpp | 28 +++++++++++++++++++ .../src/components/core/CoreManager.hpp | 2 ++ .../AbstractEventCountNotifier.cpp | 5 ++-- .../settings/AccountSettingsModel.cpp | 18 ++++++++---- .../components/timeline/TimelineListModel.cpp | 5 +--- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d46c899..c4180f994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crash on exit. - Memory stability. +## 4.4.5 - 2022-06-06 + +### Fixed +- Chat rooms may be mark as read while hidden. + ## 4.4.4 - 2022-06-01 ### Fixed diff --git a/linphone-app/src/components/core/CoreManager.cpp b/linphone-app/src/components/core/CoreManager.cpp index 39611c6c0..d3ac48cc9 100644 --- a/linphone-app/src/components/core/CoreManager.cpp +++ b/linphone-app/src/components/core/CoreManager.cpp @@ -17,6 +17,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + + // VisualC++: Windows doesn't have to rewrite min max or else building std::max will fail +#define NOMINMAX #include #include @@ -374,6 +377,31 @@ int CoreManager::getMissedCallCount(const QString &peerAddress, const QString &l int CoreManager::getMissedCallCountFromLocal( const QString &localAddress)const{ return mEventCountNotifier ? mEventCountNotifier->getMissedCallCountFromLocal(localAddress) : 0; } +int CoreManager::getUnreadChatMessage(const std::shared_ptr& accountAddress)const{ +// Workaround : getUnreadMessagesCount(à doesn't check the sate of chat room so they can be left and still count in unread message (for example because of a bug on ack timeout). Remove these counts from the unread count. + std::list> allChatRooms = mCore->getChatRooms(); + std::list> accountsList; + int unreadChatMessageCount; + if( accountAddress) + unreadChatMessageCount = mCore->getUnreadChatMessageCountFromLocal(accountAddress); + else { + accountsList = mCore->getAccountList(); + unreadChatMessageCount = mCore->getUnreadChatMessageCountFromActiveLocals(); + } + for(auto chatRoom : allChatRooms){ + auto account = accountsList.begin(); + if(!accountAddress){ + while(account != accountsList.end() && !(*account)->getParams()->getIdentityAddress()->weakEqual(chatRoom->getLocalAddress())) + ++account; + } + if( ((!accountAddress && account != accountsList.end()) || (accountAddress && accountAddress->weakEqual(chatRoom->getLocalAddress()) )) + && (chatRoom->getState() == linphone::ChatRoom::State::Terminated || chatRoom->getState() == linphone::ChatRoom::State::Deleted)) + unreadChatMessageCount -= chatRoom->getUnreadMessagesCount(); + } + unreadChatMessageCount = std::max(0,unreadChatMessageCount); + + return unreadChatMessageCount; +} // ----------------------------------------------------------------------------- diff --git a/linphone-app/src/components/core/CoreManager.hpp b/linphone-app/src/components/core/CoreManager.hpp index 43ffaf06d..07addfbad 100644 --- a/linphone-app/src/components/core/CoreManager.hpp +++ b/linphone-app/src/components/core/CoreManager.hpp @@ -172,6 +172,8 @@ public: int getMissedCallCount(const QString &peerAddress, const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines) int getMissedCallCountFromLocal(const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines) + int getUnreadChatMessage(const std::shared_ptr& accountAddress = nullptr)const; + static bool isInstanciated(){return mInstance!=nullptr;} Q_INVOKABLE bool isLastRemoteProvisioningGood(); diff --git a/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp b/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp index fd2531aa1..2b8f5363d 100644 --- a/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp +++ b/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp @@ -67,8 +67,9 @@ AbstractEventCountNotifier::AbstractEventCountNotifier (QObject *parent) : QObje // ----------------------------------------------------------------------------- void AbstractEventCountNotifier::updateUnreadMessageCount () { - mUnreadMessageCount = CoreManager::getInstance()->getCore()->getUnreadChatMessageCountFromActiveLocals(); - internalnotifyEventCount(); + auto core = CoreManager::getInstance()->getCore(); + mUnreadMessageCount = CoreManager::getInstance()->getUnreadChatMessage(); + internalnotifyEventCount(); } void AbstractEventCountNotifier::internalnotifyEventCount () { diff --git a/linphone-app/src/components/settings/AccountSettingsModel.cpp b/linphone-app/src/components/settings/AccountSettingsModel.cpp index 176a67c49..d49efa9e1 100644 --- a/linphone-app/src/components/settings/AccountSettingsModel.cpp +++ b/linphone-app/src/components/settings/AccountSettingsModel.cpp @@ -478,9 +478,12 @@ QVariantList AccountSettingsModel::getAccounts () const { if(CoreManager::getInstance()->getSettingsModel()->getShowLocalSipAccount()) { QVariantMap account; - account["sipAddress"] = Utils::coreStringToAppString(core->createPrimaryContactParsed()->asStringUriOnly()); - account["fullSipAddress"] = Utils::coreStringToAppString(core->createPrimaryContactParsed()->asString()); - account["unreadMessageCount"] = core->getUnreadChatMessageCountFromLocal(core->createPrimaryContactParsed()); + auto address = core->createPrimaryContactParsed(); + int unreadChatMessageCount = CoreManager::getInstance()->getUnreadChatMessage(address); + + account["sipAddress"] = Utils::coreStringToAppString(address->asStringUriOnly()); + account["fullSipAddress"] = Utils::coreStringToAppString(address->asString()); + account["unreadMessageCount"] = unreadChatMessageCount; account["missedCallCount"] = CoreManager::getInstance()->getMissedCallCountFromLocal(account["sipAddress"].toString()); account["proxyConfig"].setValue(nullptr); accounts << account; @@ -488,10 +491,13 @@ QVariantList AccountSettingsModel::getAccounts () const { for (const auto &proxyConfig : core->getProxyConfigList()) { QVariantMap account; - account["sipAddress"] = Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asStringUriOnly()); - account["fullSipAddress"] = Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString()); + + auto proxyAddress = proxyConfig->getIdentityAddress(); + int unreadChatMessageCount = CoreManager::getInstance()->getUnreadChatMessage(proxyAddress); + account["sipAddress"] = Utils::coreStringToAppString(proxyAddress->asStringUriOnly()); + account["fullSipAddress"] = Utils::coreStringToAppString(proxyAddress->asString()); account["proxyConfig"].setValue(proxyConfig); - account["unreadMessageCount"] = proxyConfig->getUnreadChatMessageCount(); + account["unreadMessageCount"] = unreadChatMessageCount; account["missedCallCount"] = CoreManager::getInstance()->getMissedCallCountFromLocal(account["sipAddress"].toString()); accounts << account; } diff --git a/linphone-app/src/components/timeline/TimelineListModel.cpp b/linphone-app/src/components/timeline/TimelineListModel.cpp index 40cc9630b..8c701cb49 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.cpp +++ b/linphone-app/src/components/timeline/TimelineListModel.cpp @@ -244,10 +244,7 @@ void TimelineListModel::updateTimelines () { // Clean terminated chat rooms. allChatRooms.remove_if([](std::shared_ptr chatRoom){ - bool toRemove = chatRoom->getState() == linphone::ChatRoom::State::Terminated || chatRoom->getState() == linphone::ChatRoom::State::Deleted; - if( toRemove) - chatRoom->markAsRead(); - return toRemove; + return chatRoom->getState() == linphone::ChatRoom::State::Terminated || chatRoom->getState() == linphone::ChatRoom::State::Deleted; }); //Remove no more chat rooms