Load optimization (call logs).

Select new call only if it is connected.
This commit is contained in:
Julien Wadel 2022-09-23 16:39:38 +02:00
parent 325992c6f6
commit 092a6b3185
8 changed files with 63 additions and 56 deletions

View file

@ -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;
}
}

View file

@ -107,8 +107,8 @@ void ChatRoomModel::connectTo(ChatRoomListener * listener){
}
// -----------------------------------------------------------------------------
QSharedPointer<ChatRoomModel> ChatRoomModel::create(std::shared_ptr<linphone::ChatRoom> chatRoom){
QSharedPointer<ChatRoomModel> model = QSharedPointer<ChatRoomModel>::create(chatRoom);
QSharedPointer<ChatRoomModel> ChatRoomModel::create(std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs){
QSharedPointer<ChatRoomModel> model = QSharedPointer<ChatRoomModel>::create(chatRoom, callLogs);
if(model){
model->mSelf = model;
//chatRoom->addListener(model);
@ -117,7 +117,7 @@ QSharedPointer<ChatRoomModel> ChatRoomModel::create(std::shared_ptr<linphone::Ch
return nullptr;
}
ChatRoomModel::ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, QObject * parent) : ProxyListModel(parent){
ChatRoomModel::ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& 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<linphone::ChatRoom> 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<linphone::CallLog> lastCall = nullptr;
QString peerAddress = getParticipantAddress();
std::shared_ptr<const linphone::Address> 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<linphone::Address> lPeerAddress = Utils::interpretUrl(peerAddress);
if( lPeerAddress && lLocalAddress){
auto itCallLog = std::find_if(callLogs.begin(), callLogs.end(), [lPeerAddress, lLocalAddress](std::shared_ptr<linphone::CallLog> 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();
}

View file

@ -93,8 +93,9 @@ public:
Q_PROPERTY(bool entriesLoading READ isEntriesLoading WRITE setEntriesLoading NOTIFY entriesLoadingChanged)
static QSharedPointer<ChatRoomModel> create(std::shared_ptr<linphone::ChatRoom> chatRoom);
ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, QObject * parent = nullptr);
static QSharedPointer<ChatRoomModel> create(std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs = std::list<std::shared_ptr<linphone::CallLog>>());
ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs = std::list<std::shared_ptr<linphone::CallLog>>(), QObject * parent = nullptr);
~ChatRoomModel ();
QHash<int, QByteArray> roleNames () const override;

View file

@ -68,38 +68,8 @@ void TimelineModel::connectTo(ChatRoomListener * listener){
// =============================================================================
QSharedPointer<TimelineModel> TimelineModel::create(TimelineListModel * mainList, std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs, QObject *parent){
if((!chatRoom || chatRoom->getState() != linphone::ChatRoom::State::Deleted) && (!mainList || !mainList->getTimeline(chatRoom, false)) ) {
QSharedPointer<TimelineModel> model = QSharedPointer<TimelineModel>::create(chatRoom, parent);
QSharedPointer<TimelineModel> model = QSharedPointer<TimelineModel>::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<linphone::CallLog> lastCall = nullptr;
QString peerAddress = timelineChatRoom->getParticipantAddress();
std::shared_ptr<const linphone::Address> 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<linphone::Address> lPeerAddress = Utils::interpretUrl(peerAddress);
if( lPeerAddress && lLocalAddress){
auto itCallLog = std::find_if(callLogs.begin(), callLogs.end(), [lPeerAddress, lLocalAddress](std::shared_ptr<linphone::CallLog> 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> TimelineModel::create(TimelineListModel * mainList
}
TimelineModel::TimelineModel (std::shared_ptr<linphone::ChatRoom> chatRoom, QObject *parent) : QObject(parent) {
TimelineModel(chatRoom, std::list<std::shared_ptr<linphone::CallLog>>(), parent);
}
TimelineModel::TimelineModel (std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& 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> TimelineModel::clone()const{
}
TimelineModel::~TimelineModel(){
if( mChatRoomModel->getChatRoom())
if(mChatRoomModel && mChatRoomModel->getChatRoom())
mChatRoomModel->getChatRoom()->removeListener(mChatRoomListener);
}

View file

@ -41,6 +41,7 @@ class TimelineModel : public QObject {
public:
static QSharedPointer<TimelineModel> create(TimelineListModel * mainList, std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs = std::list<std::shared_ptr<linphone::CallLog>>(), QObject *parent = Q_NULLPTR);
TimelineModel (std::shared_ptr<linphone::ChatRoom> chatRoom, QObject *parent = Q_NULLPTR);
TimelineModel (std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs, QObject *parent = Q_NULLPTR);
TimelineModel(const TimelineModel * model);
virtual ~TimelineModel();

View file

@ -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)
}

View file

@ -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)

View file

@ -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})