From dcc651a33606387c5522e5da3acaf68bdadba015 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 13 Jan 2022 18:33:21 +0100 Subject: [PATCH] Fix crash on NULL chat rooms when building ChatRoomModel --- .../components/chat-room/ChatRoomModel.cpp | 35 ++++++++++--------- .../components/timeline/TimelineListModel.cpp | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 59d03f1bc..2f53bb3ef 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -233,17 +233,18 @@ 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; - // 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)); + } ChatRoomModel::~ChatRoomModel () { @@ -562,13 +563,15 @@ void ChatRoomModel::setLastUpdateTime(const QDateTime& lastUpdateDate) { } void ChatRoomModel::updateLastUpdateTime(){ - QDateTime lastDateTime = QDateTime::fromMSecsSinceEpoch(mChatRoom->getLastUpdateTime()*1000); - QDateTime lastCallTime = lastDateTime; - for(auto e : mEntries){ - if(e->mType == CallEntry && e->mTimestamp > lastCallTime) - lastCallTime = e->mTimestamp; - } - setLastUpdateTime(lastCallTime); + if( mChatRoom ){ + QDateTime lastDateTime = QDateTime::fromMSecsSinceEpoch(mChatRoom->getLastUpdateTime()*1000); + QDateTime lastCallTime = lastDateTime; + for(auto e : mEntries){ + if(e->mType == CallEntry && e->mTimestamp > lastCallTime) + lastCallTime = e->mTimestamp; + } + setLastUpdateTime(lastCallTime); + } } void ChatRoomModel::setUnreadMessagesCount(const int& count){ diff --git a/linphone-app/src/components/timeline/TimelineListModel.cpp b/linphone-app/src/components/timeline/TimelineListModel.cpp index 62964e68d..16251c63e 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.cpp +++ b/linphone-app/src/components/timeline/TimelineListModel.cpp @@ -275,7 +275,7 @@ void TimelineListModel::updateTimelines () { // Add new for(auto dbChatRoom : allChatRooms){ auto haveTimeline = getTimeline(dbChatRoom, false); - if(!haveTimeline){// Create a new Timeline if needed + if(!haveTimeline && dbChatRoom){// Create a new Timeline if needed std::shared_ptr model = TimelineModel::create(dbChatRoom); if( model){