From c41f337907c029e4ccf958437011495f9f666204 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 28 May 2020 17:23:48 +0200 Subject: [PATCH] Feature : Adding missing call count with the unread messages in timeline Fix : Force refresh Registers when clicking on Account status, without testing registration state. - add a timer synchronization to show the registration status by proxy --- .../src/components/chat/ChatModel.cpp | 2 +- .../src/components/core/CoreManager.cpp | 4 +- .../src/components/core/CoreManager.hpp | 2 + .../AbstractEventCountNotifier.cpp | 8 ++++ .../AbstractEventCountNotifier.hpp | 1 + .../sip-addresses/SipAddressesModel.cpp | 41 ++++++++++--------- .../sip-addresses/SipAddressesModel.hpp | 3 +- .../src/components/timeline/TimelineModel.cpp | 1 + .../ui/modules/Linphone/Contact/Contact.qml | 2 +- .../views/App/Main/Dialogs/ManageAccounts.qml | 12 ++++-- linphone-app/ui/views/App/Main/MainWindow.qml | 4 +- 11 files changed, 51 insertions(+), 29 deletions(-) diff --git a/linphone-app/src/components/chat/ChatModel.cpp b/linphone-app/src/components/chat/ChatModel.cpp index f7672cca2..db3a713c4 100644 --- a/linphone-app/src/components/chat/ChatModel.cpp +++ b/linphone-app/src/components/chat/ChatModel.cpp @@ -628,7 +628,7 @@ void ChatModel::compose () { } void ChatModel::resetMessageCount () { - if (mChatRoom->getUnreadMessagesCount() > 0) { + if (mChatRoom->getUnreadMessagesCount() > 0 || CoreManager::getInstance()->getMissedCallCount(getPeerAddress(), getLocalAddress())>0) { mChatRoom->markAsRead(); emit messageCountReset(); } diff --git a/linphone-app/src/components/core/CoreManager.cpp b/linphone-app/src/components/core/CoreManager.cpp index f05286cbb..679cd4048 100644 --- a/linphone-app/src/components/core/CoreManager.cpp +++ b/linphone-app/src/components/core/CoreManager.cpp @@ -307,7 +307,9 @@ QString CoreManager::getVersion () const { int CoreManager::getEventCount () const { return mEventCountNotifier ? mEventCountNotifier->getEventCount() : 0; } - +int CoreManager::getMissedCallCount(const QString &peerAddress, const QString &localAddress)const{ + return mEventCountNotifier ? mEventCountNotifier->getMissedCallCount(peerAddress, localAddress) : 0; +} // ----------------------------------------------------------------------------- void CoreManager::iterate () { diff --git a/linphone-app/src/components/core/CoreManager.hpp b/linphone-app/src/components/core/CoreManager.hpp index 0b405355e..6235307ee 100644 --- a/linphone-app/src/components/core/CoreManager.hpp +++ b/linphone-app/src/components/core/CoreManager.hpp @@ -130,6 +130,8 @@ public: Q_INVOKABLE void sendLogs () const; Q_INVOKABLE void cleanLogs () const; + int getMissedCallCount(const QString &peerAddress, const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines) + signals: void coreCreated (); void coreStarted (); 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 c971ef91c..06c8365d9 100644 --- a/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp +++ b/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.cpp @@ -69,6 +69,14 @@ void AbstractEventCountNotifier::internalnotifyEventCount () { emit eventCountChanged(n); } +// Get missed call from a chat (useful for showing bubbles on Timelines) +int AbstractEventCountNotifier::getMissedCallCount(const QString &peerAddress, const QString &localAddress) const{ + auto it = mMissedCalls.find({ peerAddress, localAddress }); + if (it != mMissedCalls.cend()) + return *it; + else + return 0; +} // ----------------------------------------------------------------------------- void AbstractEventCountNotifier::handleChatModelCreated (const shared_ptr &chatModel) { diff --git a/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp b/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp index 09a84ceb4..4797fa227 100644 --- a/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp +++ b/linphone-app/src/components/core/event-count-notifier/AbstractEventCountNotifier.hpp @@ -52,6 +52,7 @@ public: } int getEventCount () const { return mUnreadMessageCount + getMissedCallCount(); } + int getMissedCallCount(const QString &peerAddress, const QString &localAddress) const;// Get missed call count from a chat (useful for showing bubbles on Timelines) signals: void eventCountChanged (int count); diff --git a/linphone-app/src/components/sip-addresses/SipAddressesModel.cpp b/linphone-app/src/components/sip-addresses/SipAddressesModel.cpp index 683f6a1dc..822db8783 100644 --- a/linphone-app/src/components/sip-addresses/SipAddressesModel.cpp +++ b/linphone-app/src/components/sip-addresses/SipAddressesModel.cpp @@ -128,7 +128,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &pee auto it2 = it->localAddressToConferenceEntry.find(cleanedLocalAddress); if (it2 != it->localAddressToConferenceEntry.end()) - model->setUnreadMessageCount(it2->unreadMessageCount); + model->setUnreadMessageCount(it2->unreadMessageCount+it2->missedCallCount); } mObservers.insert(cleanedPeerAddress, model); @@ -399,12 +399,13 @@ void SipAddressesModel::handleMessageCountReset (ChatModel *chatModel) { return; it2->unreadMessageCount = 0; + it2->missedCallCount = 0; int row = mRefs.indexOf(&(*it)); Q_ASSERT(row != -1); emit dataChanged(index(row, 0), index(row, 0)); - updateObservers(peerAddress, localAddress, 0); + updateObservers(peerAddress, localAddress, 0, 0); } void SipAddressesModel::handleMessageSent (const shared_ptr &message) { @@ -447,19 +448,19 @@ void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, const shared_ptr &call) { const shared_ptr callLog = call->getCallLog(); - sipAddressEntry.localAddressToConferenceEntry[ - Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly()) - ].timestamp = callLog->getStatus() == linphone::Call::Status::Success + QString localAddress(Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly())); + QString peerAddress(Utils::coreStringToAppString(callLog->getRemoteAddress()->asStringUriOnly())); + ConferenceEntry &conferenceEntry = sipAddressEntry.localAddressToConferenceEntry[ + localAddress + ]; + + qInfo() << QStringLiteral("Update (`%1`, `%2`) from chat call.").arg(sipAddressEntry.sipAddress, localAddress); + + conferenceEntry.timestamp = callLog->getStatus() == linphone::Call::Status::Success ? QDateTime::fromMSecsSinceEpoch((callLog->getStartDate() + callLog->getDuration()) * 1000) : QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000); - - if (callLog->getStatus() == linphone::Call::Status::Missed) { - for (auto &observer : mObservers.values(Utils::coreStringToAppString((callLog->getRemoteAddress()->asStringUriOnly())))) { - if (observer->getLocalAddress() == Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly())) { - observer->setUnreadMessageCount(1); - } - } - } + conferenceEntry.missedCallCount = CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress); + updateObservers(sipAddressEntry.sipAddress, localAddress, conferenceEntry.unreadMessageCount,conferenceEntry.missedCallCount); } void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, const shared_ptr &message) { @@ -467,13 +468,14 @@ void SipAddressesModel::addOrUpdateSipAddress (SipAddressEntry &sipAddressEntry, int count = chatRoom->getUnreadMessagesCount(); QString localAddress(Utils::coreStringToAppString(chatRoom->getLocalAddress()->asStringUriOnly())); + QString peerAddress(Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly())); qInfo() << QStringLiteral("Update (`%1`, `%2`) from chat message.").arg(sipAddressEntry.sipAddress, localAddress); ConferenceEntry &conferenceEntry = sipAddressEntry.localAddressToConferenceEntry[localAddress]; conferenceEntry.timestamp = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000); - conferenceEntry.unreadMessageCount = count; - - updateObservers(sipAddressEntry.sipAddress, localAddress, count); + conferenceEntry.unreadMessageCount = count ; + conferenceEntry.missedCallCount = CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress); + updateObservers(sipAddressEntry.sipAddress, localAddress, count,conferenceEntry.missedCallCount); } template @@ -556,6 +558,7 @@ void SipAddressesModel::initSipAddressesFromChat () { getSipAddressEntry(peerAddress)->localAddressToConferenceEntry[localAddress] = { chatRoom->getUnreadMessagesCount(), + CoreManager::getInstance()->getMissedCallCount(peerAddress, localAddress), false, QDateTime::fromMSecsSinceEpoch(history.back()->getTime() * 1000) }; @@ -596,7 +599,7 @@ void SipAddressesModel::initSipAddressesFromCalls () { auto &localToConferenceEntry = getSipAddressEntry(peerAddress)->localAddressToConferenceEntry; auto it = localToConferenceEntry.find(localAddress); if (it == localToConferenceEntry.end()) - localToConferenceEntry[localAddress] = { 0, false, move(timestamp) }; + localToConferenceEntry[localAddress] = { 0,0, false, move(timestamp) }; else if (it->timestamp.isNull() || timestamp > it->timestamp) it->timestamp = move(timestamp); } @@ -624,10 +627,10 @@ void SipAddressesModel::updateObservers (const QString &sipAddress, const Presen observer->setPresenceStatus(presenceStatus); } -void SipAddressesModel::updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount) { +void SipAddressesModel::updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount, int missedCallCount) { for (auto &observer : mObservers.values(peerAddress)) { if (observer->getLocalAddress() == localAddress) { - observer->setUnreadMessageCount(messageCount); + observer->setUnreadMessageCount(messageCount+missedCallCount); return; } } diff --git a/linphone-app/src/components/sip-addresses/SipAddressesModel.hpp b/linphone-app/src/components/sip-addresses/SipAddressesModel.hpp index 6684aed2c..bd66688ce 100644 --- a/linphone-app/src/components/sip-addresses/SipAddressesModel.hpp +++ b/linphone-app/src/components/sip-addresses/SipAddressesModel.hpp @@ -39,6 +39,7 @@ class SipAddressesModel : public QAbstractListModel { public: struct ConferenceEntry { int unreadMessageCount; + int missedCallCount; bool isComposing; QDateTime timestamp; }; @@ -132,7 +133,7 @@ private: void updateObservers (const QString &sipAddress, ContactModel *contact); void updateObservers (const QString &sipAddress, const Presence::PresenceStatus &presenceStatus); - void updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount); + void updateObservers (const QString &peerAddress, const QString &localAddress, int messageCount, int missedCallCount); // --------------------------------------------------------------------------- diff --git a/linphone-app/src/components/timeline/TimelineModel.cpp b/linphone-app/src/components/timeline/TimelineModel.cpp index 0f372bd93..c24881b19 100644 --- a/linphone-app/src/components/timeline/TimelineModel.cpp +++ b/linphone-app/src/components/timeline/TimelineModel.cpp @@ -60,6 +60,7 @@ QVariant TimelineModel::data (const QModelIndex &index, int role) const { map["timestamp"] = it->timestamp; map["isComposing"] = it->isComposing; map["unreadMessageCount"] = it->unreadMessageCount; + map["missedCallCount"] = it->missedCallCount; } return map; diff --git a/linphone-app/ui/modules/Linphone/Contact/Contact.qml b/linphone-app/ui/modules/Linphone/Contact/Contact.qml index e12312924..2139eec6f 100644 --- a/linphone-app/ui/modules/Linphone/Contact/Contact.qml +++ b/linphone-app/ui/modules/Linphone/Contact/Contact.qml @@ -64,7 +64,7 @@ Rectangle { ContactMessageCounter { Layout.alignment: Qt.AlignTop - count: Number(entry.unreadMessageCount) + count: Number(entry.unreadMessageCount) + Number(entry.missedCallCount) isComposing: Boolean(entry.isComposing) visible: item.displayUnreadMessageCount diff --git a/linphone-app/ui/views/App/Main/Dialogs/ManageAccounts.qml b/linphone-app/ui/views/App/Main/Dialogs/ManageAccounts.qml index be4575cfe..74a59dcd5 100644 --- a/linphone-app/ui/views/App/Main/Dialogs/ManageAccounts.qml +++ b/linphone-app/ui/views/App/Main/Dialogs/ManageAccounts.qml @@ -75,19 +75,23 @@ DialogPlus { delegate: CommonItemDelegate { id: item - container: view flattenedModel: modelData - itemIcon: Logic.getItemIcon(flattenedModel) + itemIcon: ''//Start with no error and let some time before getting status with the below timer width: parent.width - ActionButton { + Timer{// This timer is used to synchronize registration state by proxy, without having to deal with change signals + interval: 1000; running: item.visible; repeat: true + onTriggered:itemIcon= Logic.getItemIcon(flattenedModel) + } + + ActionButton { icon: 'options' iconSize: 30 anchors.fill: parent visible:false //TODO handle click and jump to proxy config settings - } + } onClicked: { container.currentIndex = index diff --git a/linphone-app/ui/views/App/Main/MainWindow.qml b/linphone-app/ui/views/App/Main/MainWindow.qml index 3525ef389..e69f6b8d6 100644 --- a/linphone-app/ui/views/App/Main/MainWindow.qml +++ b/linphone-app/ui/views/App/Main/MainWindow.qml @@ -112,8 +112,8 @@ ApplicationWindow { text: AccountSettingsModel.sipAddress } - onClicked: {if(AccountSettingsModel.registrationState !== AccountSettingsModel.RegistrationStateRegistered && AccountSettingsModel.registrationState !== AccountSettingsModel.RegistrationStateNoProxy) - CoreManager.forceRefreshRegisters() + onClicked: { + CoreManager.forceRefreshRegisters() Logic.manageAccounts() } }