Fix crash on NULL chat rooms when building ChatRoomModel

This commit is contained in:
Julien Wadel 2022-01-13 18:33:21 +01:00
parent f961f6106f
commit dcc651a336
2 changed files with 20 additions and 17 deletions

View file

@ -233,17 +233,18 @@ ChatRoomModel::ChatRoomModel (std::shared_ptr<linphone::ChatRoom> 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){

View file

@ -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<TimelineModel> model = TimelineModel::create(dbChatRoom);
if( model){