diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 22e7c2efc..975351d85 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -233,15 +233,7 @@ ChatRoomModel::ChatRoomModel (std::shared_ptr chatRoom, QObj connect(contact, &ContactModel::contactUpdated, this, &ChatRoomModel::fullPeerAddressChanged); } } - // Get Max updatetime from chat room and last call event - auto callHistory = CallsListModel::getCallHistory(getParticipantAddress(), Utils::coreStringToAppString(mChatRoom->getLocalAddress()->asStringUriOnly())); - if(callHistory.size() > 0){ - auto callDate = callHistory.front()->getStartDate(); - if( callHistory.front()->getStatus() == linphone::Call::Status::Success ) - callDate += callHistory.front()->getDuration(); - setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(max(mChatRoom->getLastUpdateTime(), callDate )*1000)); - }else - setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(mChatRoom->getLastUpdateTime()*1000)); + }else mParticipantListModel = nullptr; @@ -941,11 +933,11 @@ void ChatRoomModel::initEntries(){ QList > entries; QList prepareEntries; // Get chat messages - for (auto &message : mChatRoom->getHistory(mLastEntriesStep)) { + for (auto &message : mChatRoom->getHistory(mFirstLastEntriesStep)) { prepareEntries << EntrySorterHelper(message->getTime() ,MessageEntry, message); } // Get events - for(auto &eventLog : mChatRoom->getHistoryEvents(mLastEntriesStep)) + for(auto &eventLog : mChatRoom->getHistoryEvents(mFirstLastEntriesStep)) prepareEntries << EntrySorterHelper(eventLog->getCreationTime() , NoticeEntry, eventLog); // Get calls. bool secureChatEnabled = CoreManager::getInstance()->getSettingsModel()->getSecureChatEnabled(); @@ -956,11 +948,11 @@ void ChatRoomModel::initEntries(){ auto callHistory = CallsListModel::getCallHistory(getParticipantAddress(), Utils::coreStringToAppString(mChatRoom->getLocalAddress()->asStringUriOnly())); // callhistory is sorted from newest to oldest int count = 0; - for (auto callLog = callHistory.begin() ; count < mLastEntriesStep && callLog != callHistory.end() ; ++callLog, ++count ){ + for (auto callLog = callHistory.begin() ; count < mFirstLastEntriesStep && callLog != callHistory.end() ; ++callLog, ++count ){ prepareEntries << EntrySorterHelper((*callLog)->getStartDate(), CallEntry, *callLog); } } - EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mLastEntriesStep, this); + EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mFirstLastEntriesStep, this); qDebug() << "Internal Entries : Built"; mIsInitialized = true; if(entries.size() >0){ diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp index 86b2e4f29..9079da4a3 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.hpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp @@ -243,6 +243,7 @@ public: bool mDeleteChatRoom = false; // Use as workaround because of core->deleteChatRoom() that call destructor without takking account of count ref : call it in ChatRoomModel destructor int mLastEntriesStep = 50; // Retrieve a part of the history to avoid too much processing + int mFirstLastEntriesStep = 10; // Retrieve a part of the history to avoid too much processing at the init bool mMarkAsReadEnabled = true; bool mEntriesLoading = false; diff --git a/linphone-app/src/components/ldap/LdapModel.cpp b/linphone-app/src/components/ldap/LdapModel.cpp index 309f86090..eaf8d35ad 100644 --- a/linphone-app/src/components/ldap/LdapModel.cpp +++ b/linphone-app/src/components/ldap/LdapModel.cpp @@ -85,7 +85,7 @@ void LdapModel::save(){ void LdapModel::unsave(){ if(mLdap) - mLdap->removeFromConfigFile(); + CoreManager::getInstance()->getCore()->removeLdap(mLdap); } QVariantMap LdapModel::getConfig(){ //return mConfig; diff --git a/linphone-app/src/components/timeline/TimelineListModel.cpp b/linphone-app/src/components/timeline/TimelineListModel.cpp index 16251c63e..235f4a6c1 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.cpp +++ b/linphone-app/src/components/timeline/TimelineListModel.cpp @@ -272,12 +272,15 @@ void TimelineListModel::updateTimelines () { }else ++itTimeline; } - // Add new + // Add new. +// Call logs optimization : store all the list and check on it for each chat room instead of loading call logs on each chat room. See TimelineModel() + std::list> callLogs = coreManager->getCore()->getCallLogs(); +// for(auto dbChatRoom : allChatRooms){ auto haveTimeline = getTimeline(dbChatRoom, false); if(!haveTimeline && dbChatRoom){// Create a new Timeline if needed - std::shared_ptr model = TimelineModel::create(dbChatRoom); + std::shared_ptr model = TimelineModel::create(dbChatRoom, callLogs); if( model){ connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool))); connect(model->getChatRoomModel(), &ChatRoomModel::allEntriesRemoved, this, &TimelineListModel::removeChatRoomModel); diff --git a/linphone-app/src/components/timeline/TimelineModel.cpp b/linphone-app/src/components/timeline/TimelineModel.cpp index 29e3cb1ac..1c8db2f91 100644 --- a/linphone-app/src/components/timeline/TimelineModel.cpp +++ b/linphone-app/src/components/timeline/TimelineModel.cpp @@ -28,18 +28,49 @@ #include "TimelineModel.hpp" #include "TimelineListModel.hpp" +#include "../calls/CallsListModel.hpp" + #include #include #include // ============================================================================= -std::shared_ptr TimelineModel::create(std::shared_ptr chatRoom, QObject *parent){ +std::shared_ptr TimelineModel::create(std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent){ if(!CoreManager::getInstance()->getTimelineListModel() || !CoreManager::getInstance()->getTimelineListModel()->getTimeline(chatRoom, false)) { std::shared_ptr model = std::make_shared(chatRoom, parent); if(model && model->getChatRoomModel()){ model->mSelf = model; chatRoom->addListener(model); + // Get Max updatetime from chat room and last call event + auto timelineChatRoom = model->getChatRoomModel(); + std::shared_ptr lastCall = nullptr; + QString peerAddress = timelineChatRoom->getParticipantAddress(); + std::shared_ptr lLocalAddress = chatRoom->getLocalAddress(); + QString localAddress = Utils::coreStringToAppString(lLocalAddress->asStringUriOnly()); + + if(callLogs.size() == 0) { + auto callHistory = CallsListModel::getCallHistory(peerAddress, localAddress); + if(callHistory.size() > 0) + lastCall = callHistory.front(); + }else{// Find the last call in list + std::shared_ptr lPeerAddress = Utils::interpretUrl(peerAddress); + if( lPeerAddress && lLocalAddress){ + auto itCallLog = std::find_if(callLogs.begin(), callLogs.end(), [lPeerAddress, lLocalAddress](std::shared_ptr c){ + return c->getLocalAddress()->weakEqual(lLocalAddress) && c->getRemoteAddress()->weakEqual(lPeerAddress); + }); + if( itCallLog != callLogs.end()) + lastCall = *itCallLog; + } + } + + if(lastCall){ + auto callDate = lastCall->getStartDate(); + if( lastCall->getStatus() == linphone::Call::Status::Success ) + callDate += lastCall->getDuration(); + timelineChatRoom->setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(std::max(chatRoom->getLastUpdateTime(), callDate )*1000)); + }else + timelineChatRoom->setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(chatRoom->getLastUpdateTime()*1000)); return model; } } diff --git a/linphone-app/src/components/timeline/TimelineModel.hpp b/linphone-app/src/components/timeline/TimelineModel.hpp index eb6b4a576..c8e29cd1b 100644 --- a/linphone-app/src/components/timeline/TimelineModel.hpp +++ b/linphone-app/src/components/timeline/TimelineModel.hpp @@ -36,7 +36,7 @@ class TimelineModel : public QObject, public linphone::ChatRoomListener { Q_OBJECT public: - static std::shared_ptr create(std::shared_ptr chatRoom, QObject *parent = Q_NULLPTR); + static std::shared_ptr create(std::shared_ptr chatRoom, const std::list>& callLogs = std::list>(), QObject *parent = Q_NULLPTR); TimelineModel (std::shared_ptr chatRoom, QObject *parent = Q_NULLPTR); virtual ~TimelineModel(); diff --git a/linphone-sdk b/linphone-sdk index 2b0c68e42..b2a3ebaff 160000 --- a/linphone-sdk +++ b/linphone-sdk @@ -1 +1 @@ -Subproject commit 2b0c68e4234dd35dd99fdea96eed71f4a394008f +Subproject commit b2a3ebaffde438fb23c7b7d91327a35fa3a0f23d