From c84a5a9048b89d07cecc2c3924f78fbf511b0e0d Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 23 May 2023 12:17:45 +0200 Subject: [PATCH] - Fix hidden time on chat message after the deletion of a notice (like unread messages). Seems to be a Qt bug : If layoutChanged() is not send, some delegates after notice will be wrong (their $chatEntry will be updated with undefined while not being really updated on next check) Reproduce case with a ChatMessage after a Notice: On Notice deletion, this chatMessage will update its text with an undefined $chatEntry. But when checking the value of its $chatEntry after this event(make a MouseArea with a click event), it will be the correct one (and not the undefined). - Stabilize sorted message on loading more entries by checking receving time. (cherry picked from commit 89ad42e1a62b15b39eea987db70bfa99891a9e9c) --- .../components/chat-room/ChatRoomModel.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 6f9475d7c..42de335af 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -853,25 +853,27 @@ public: void ChatRoomModel::updateNewMessageNotice(const int& count){ if( mChatRoom ) { if(mUnreadMessageNotice ) { - removeEntry(mUnreadMessageNotice.get()); + remove(mUnreadMessageNotice); mUnreadMessageNotice = nullptr; } if(count > 0){ QDateTime lastUnreadMessage = QDateTime::currentDateTime(); + QDateTime lastReceivedMessage = lastUnreadMessage; enableMarkAsRead(false); // Get chat messages for (auto &message : mChatRoom->getHistory(mLastEntriesStep)) { if( !message->isRead()) { lastUnreadMessage = min(lastUnreadMessage, QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000 - 1 )); //-1 to be sure that event will be before the message + lastReceivedMessage = min(lastReceivedMessage, ChatMessageModel::initReceivedTimestamp(message, false).addMSecs(-1)); } } - mUnreadMessageNotice = ChatNoticeModel::create(ChatNoticeModel::NoticeType::NoticeUnreadMessages, lastUnreadMessage,lastUnreadMessage, QString::number(count)); - beginInsertRows(QModelIndex(), 0, 0); - mList.prepend(mUnreadMessageNotice); - endInsertRows(); - qDebug() << "New message notice timestamp to :" << lastUnreadMessage.toString(); + mUnreadMessageNotice = ChatNoticeModel::create(ChatNoticeModel::NoticeType::NoticeUnreadMessages, lastUnreadMessage,lastReceivedMessage, QString::number(count)); + prepend(mUnreadMessageNotice); + qDebug() << "New message notice timestamp to :" << lastUnreadMessage.toString() << " recv at " << lastReceivedMessage.toString(); } - //emit layoutChanged(); +// Seems to be a Qt bug : If layoutChanged() is not send, some delegates after notice will be wrong (their $chatEntry will be updated with undefined while not being really updated on next check) +// Reproduce case with a ChatMessage after a Notice: On Notice deletion, this chatMessage will update its text with an undefined $chatEntry. But when checking the value of its $chatEntry after this event(make a MouseArea with a click event), it will be the correct one (and not the undefined). + emit layoutChanged(); } } @@ -957,7 +959,7 @@ void ChatRoomModel::initEntries(){ QList prepareEntries; // Get chat messages for (auto &message : mChatRoom->getHistory(mFirstLastEntriesStep)) { - prepareEntries << EntrySorterHelper(message->getTime() ,MessageEntry, message); + prepareEntries << EntrySorterHelper(ChatMessageModel::initReceivedTimestamp(message, false).toTime_t() ,MessageEntry, message); } // Get events for(auto &eventLog : mChatRoom->getHistoryEvents(mFirstLastEntriesStep)) @@ -1034,7 +1036,7 @@ int ChatRoomModel::loadMoreEntries(){ ++itEntries; } if(!haveEntry) - prepareEntries << EntrySorterHelper(message->getTime() ,MessageEntry, message); + prepareEntries << EntrySorterHelper(ChatMessageModel::initReceivedTimestamp(message, false).toTime_t() ,MessageEntry, message); } // Calls