From 092a6b3185efa6e170e051595c62d3c999edbddf Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Fri, 23 Sep 2022 16:39:38 +0200 Subject: [PATCH] Load optimization (call logs). Select new call only if it is connected. --- linphone-app/src/components/camera/Camera.cpp | 5 ++- .../components/chat-room/ChatRoomModel.cpp | 45 ++++++++++++++----- .../components/chat-room/ChatRoomModel.hpp | 5 ++- .../src/components/timeline/TimelineModel.cpp | 39 +++------------- .../src/components/timeline/TimelineModel.hpp | 1 + .../ui/modules/Linphone/Calls/Calls.js | 11 +++-- .../ui/modules/Linphone/Calls/Calls.qml | 9 +++- .../ui/views/App/Calls/CallsWindow.js | 4 +- 8 files changed, 63 insertions(+), 56 deletions(-) diff --git a/linphone-app/src/components/camera/Camera.cpp b/linphone-app/src/components/camera/Camera.cpp index b5935ebef..5f58d7046 100644 --- a/linphone-app/src/components/camera/Camera.cpp +++ b/linphone-app/src/components/camera/Camera.cpp @@ -166,6 +166,7 @@ QQuickFramebufferObject::Renderer *Camera::createRenderer () const { if(renderer) CoreManager::getInstance()->getCore()->setNativePreviewWindowId(renderer); }else if(mWindowIdLocation == Call){ + if(mCallModel){ auto call = mCallModel->getCall(); if(call){ qDebug() << "[Camera] Setting Camera to CallModel"; @@ -173,6 +174,7 @@ QQuickFramebufferObject::Renderer *Camera::createRenderer () const { if(renderer) call->setNativeVideoWindowId(renderer); } + } }else if( mWindowIdLocation == Device) { auto participantDevice = mParticipantDeviceModel->getDevice(); if(participantDevice){ @@ -291,8 +293,9 @@ void Camera::deactivatePreview(){ } void Camera::onCallStateChanged(){ - if( mCallModel->getStatus() == CallModel::CallStatusEnded){ + if( mCallModel && mCallModel->getStatus() == CallModel::CallStatusEnded){ resetWindowId(); + disconnect(mCallModel, &CallModel::statusChanged, this, &Camera::onCallStateChanged); mCallModel = nullptr; } } \ No newline at end of file diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 43c885547..c34117802 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -107,8 +107,8 @@ void ChatRoomModel::connectTo(ChatRoomListener * listener){ } // ----------------------------------------------------------------------------- -QSharedPointer ChatRoomModel::create(std::shared_ptr chatRoom){ - QSharedPointer model = QSharedPointer::create(chatRoom); +QSharedPointer ChatRoomModel::create(std::shared_ptr chatRoom, const std::list>& callLogs){ + QSharedPointer model = QSharedPointer::create(chatRoom, callLogs); if(model){ model->mSelf = model; //chatRoom->addListener(model); @@ -117,7 +117,7 @@ QSharedPointer ChatRoomModel::create(std::shared_ptr chatRoom, QObject * parent) : ProxyListModel(parent){ +ChatRoomModel::ChatRoomModel (std::shared_ptr chatRoom, const std::list>& callLogs, QObject * parent) : ProxyListModel(parent){ App::getInstance()->getEngine()->setObjectOwnership(this, QQmlEngine::CppOwnership);// Avoid QML to destroy it when passing by Q_INVOKABLE CoreManager *coreManager = CoreManager::getInstance(); mCoreHandlers = coreManager->getHandlers(); @@ -160,13 +160,32 @@ ChatRoomModel::ChatRoomModel (std::shared_ptr chatRoom, QObj connect(contact.get(), &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)); + + std::shared_ptr lastCall = nullptr; + QString peerAddress = getParticipantAddress(); + std::shared_ptr lLocalAddress = mChatRoom->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(); + setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(std::max(mChatRoom->getLastUpdateTime(), callDate )*1000)); }else setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(mChatRoom->getLastUpdateTime()*1000)); }else @@ -600,8 +619,10 @@ void ChatRoomModel::markAsToDelete(){ void ChatRoomModel::deleteChatRoom(){ qInfo() << "Deleting ChatRoom : " << getSubject() << ", address=" << getFullPeerAddress(); - CoreManager::getInstance()->getCore()->deleteChatRoom(mChatRoom); - mChatRoom->removeListener(mChatRoomListener); + if(mChatRoom){ + mChatRoom->removeListener(mChatRoomListener); + CoreManager::getInstance()->getCore()->deleteChatRoom(mChatRoom); + } emit chatRoomDeleted(); } diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp index 6ea58f155..bd4208382 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.hpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp @@ -93,8 +93,9 @@ public: Q_PROPERTY(bool entriesLoading READ isEntriesLoading WRITE setEntriesLoading NOTIFY entriesLoadingChanged) - static QSharedPointer create(std::shared_ptr chatRoom); - ChatRoomModel (std::shared_ptr chatRoom, QObject * parent = nullptr); + static QSharedPointer create(std::shared_ptr chatRoom, const std::list>& callLogs = std::list>()); + ChatRoomModel (std::shared_ptr chatRoom, const std::list>& callLogs = std::list>(), QObject * parent = nullptr); + ~ChatRoomModel (); QHash roleNames () const override; diff --git a/linphone-app/src/components/timeline/TimelineModel.cpp b/linphone-app/src/components/timeline/TimelineModel.cpp index 9e3d92a6e..01322861d 100644 --- a/linphone-app/src/components/timeline/TimelineModel.cpp +++ b/linphone-app/src/components/timeline/TimelineModel.cpp @@ -68,38 +68,8 @@ void TimelineModel::connectTo(ChatRoomListener * listener){ // ============================================================================= QSharedPointer TimelineModel::create(TimelineListModel * mainList, std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent){ if((!chatRoom || chatRoom->getState() != linphone::ChatRoom::State::Deleted) && (!mainList || !mainList->getTimeline(chatRoom, false)) ) { - QSharedPointer model = QSharedPointer::create(chatRoom, parent); + QSharedPointer model = QSharedPointer::create(chatRoom,callLogs, parent); if(model && model->getChatRoomModel()){ - - // 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; } } @@ -107,8 +77,11 @@ QSharedPointer TimelineModel::create(TimelineListModel * mainList } TimelineModel::TimelineModel (std::shared_ptr chatRoom, QObject *parent) : QObject(parent) { + TimelineModel(chatRoom, std::list>(), parent); +} +TimelineModel::TimelineModel (std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent) : QObject(parent) { App::getInstance()->getEngine()->setObjectOwnership(this, QQmlEngine::CppOwnership);// Avoid QML to destroy it when passing by Q_INVOKABLE - mChatRoomModel = ChatRoomModel::create(chatRoom); + mChatRoomModel = ChatRoomModel::create(chatRoom, callLogs); if( mChatRoomModel ){ CoreManager::getInstance()->handleChatRoomCreated(mChatRoomModel); QObject::connect(this, &TimelineModel::selectedChanged, this, &TimelineModel::updateUnreadCount); @@ -144,7 +117,7 @@ QSharedPointer TimelineModel::clone()const{ } TimelineModel::~TimelineModel(){ - if( mChatRoomModel->getChatRoom()) + if(mChatRoomModel && mChatRoomModel->getChatRoom()) mChatRoomModel->getChatRoom()->removeListener(mChatRoomListener); } diff --git a/linphone-app/src/components/timeline/TimelineModel.hpp b/linphone-app/src/components/timeline/TimelineModel.hpp index 492ff8f02..1c33560e1 100644 --- a/linphone-app/src/components/timeline/TimelineModel.hpp +++ b/linphone-app/src/components/timeline/TimelineModel.hpp @@ -41,6 +41,7 @@ class TimelineModel : public QObject { public: static QSharedPointer create(TimelineListModel * mainList, std::shared_ptr chatRoom, const std::list>& callLogs = std::list>(), QObject *parent = Q_NULLPTR); TimelineModel (std::shared_ptr chatRoom, QObject *parent = Q_NULLPTR); + TimelineModel (std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent = Q_NULLPTR); TimelineModel(const TimelineModel * model); virtual ~TimelineModel(); diff --git a/linphone-app/ui/modules/Linphone/Calls/Calls.js b/linphone-app/ui/modules/Linphone/Calls/Calls.js index 32a275ec5..3a2cff9a1 100644 --- a/linphone-app/ui/modules/Linphone/Calls/Calls.js +++ b/linphone-app/ui/modules/Linphone/Calls/Calls.js @@ -157,9 +157,11 @@ function getParams (call) { } function updateSelectedCall (call, index) { - calls._selectedCall = call ? call : null - if (index != null) { - calls.currentIndex = index + if(index != undefined){ + calls._selectedCall = call ? call : null + if (index != null) { + calls.currentIndex = index + } } } @@ -199,7 +201,8 @@ function handleCountChanged (count) { var model = calls.model var index = count - 1 - updateSelectedCall(model.data(model.index(index, 0)), index) + if(model && model.status === CallModel.CallStatusConnected) + updateSelectedCall(model.data(model.index(index, 0)), index) } else { setIndexWithCall(call) } diff --git a/linphone-app/ui/modules/Linphone/Calls/Calls.qml b/linphone-app/ui/modules/Linphone/Calls/Calls.qml index 1cbe6d84b..c99e02614 100644 --- a/linphone-app/ui/modules/Linphone/Calls/Calls.qml +++ b/linphone-app/ui/modules/Linphone/Calls/Calls.qml @@ -36,8 +36,13 @@ ListView { if(lastCall && lastCall.status === CallModel.CallStatusConnected) Logic.setIndexWithCall(lastCall) else{ - var call = model.data(model.index(0, 0)) - Logic.updateSelectedCall(model.data(model.index(0, 0))) + for(var i = 0 ; i < model.length() ; ++i){ + var call = model.data(model.index(i, 0)) + if( call && call.status === CallModel.CallStatusConnected){ + Logic.updateSelectedCall(call, i) + return; + } + } } } onCountChanged: Logic.handleCountChanged(count) diff --git a/linphone-app/ui/views/App/Calls/CallsWindow.js b/linphone-app/ui/views/App/Calls/CallsWindow.js index c06e26ae4..66e6dc51a 100644 --- a/linphone-app/ui/views/App/Calls/CallsWindow.js +++ b/linphone-app/ui/views/App/Calls/CallsWindow.js @@ -86,8 +86,8 @@ function getContent (call, conferenceInfoModel) { } var CallModel = Linphone.CallModel if (status === CallModel.CallStatusIncoming) { - console.log("waitingRoom") - return waitingRoom + console.log("null") + return null; } if( window.conferenceInfoModel != call.conferenceInfoModel) { Qt.callLater(function(){window.conferenceInfoModel = call.conferenceInfoModel})