From d1027f401d9d3f96dd6ed40eae0f21bd5c7f0dae Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 6 Dec 2022 17:31:53 +0100 Subject: [PATCH] Fix reply message shortcut: - move to a better location where the message is supposed to be. - avoid to refresh view when loading chat items. --- .../components/chat-room/ChatRoomModel.cpp | 21 ++++++++++++++----- .../components/chat-room/ChatRoomModel.hpp | 1 + .../ui/modules/Linphone/Chat/Chat.qml | 11 ++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 725ca62d0..02a52440b 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -858,23 +858,31 @@ int ChatRoomModel::loadTillMessage(ChatMessageModel * message){ }); // if not find, load more entries and find it in new entries. if( entry == mList.end()){ + mPostModelChangedEvents = false; + beginResetModel(); int newEntries = loadMoreEntries(); while( newEntries > 0){// no more new entries int entryCount = 0; entry = mList.begin(); - auto chatEventEntry = entry->objectCast(); + auto chatEventEntry = entry->objectCast(); while(entryCount < newEntries && (chatEventEntry->mType != ChatRoomModel::EntryType::MessageEntry || chatEventEntry.objectCast()->getChatMessage() != linphoneMessage) ){ ++entryCount; ++entry; + if( entry != mList.end()) + chatEventEntry = entry->objectCast(); } if( entryCount < newEntries){// We got it qDebug() << "Find message at " << entryCount << " after loading new entries"; + mPostModelChangedEvents = true; + endResetModel(); return entryCount; }else newEntries = loadMoreEntries();// continue } + mPostModelChangedEvents = true; + endResetModel(); }else{ int entryCount = entry - mList.begin(); qDebug() << "Find message at " << entryCount; @@ -1029,18 +1037,21 @@ int ChatRoomModel::loadMoreEntries(){ EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mLastEntriesStep, this); if(entries.size() >0){ - beginInsertRows(QModelIndex(), 0, entries.size()-1); + if(mPostModelChangedEvents) + beginInsertRows(QModelIndex(), 0, entries.size()-1); for(auto entry : entries) mList.prepend(entry); - endInsertRows(); + if(mPostModelChangedEvents) + endInsertRows(); //emit layoutChanged(); updateLastUpdateTime(); } newEntries = entries.size(); }while( newEntries>0 && currentRowCount == rowCount()); - currentRowCount = rowCount() - currentRowCount + 1; + currentRowCount = rowCount() - currentRowCount; setEntriesLoading(false); - emit moreEntriesLoaded(currentRowCount); + if(mPostModelChangedEvents) + emit moreEntriesLoaded(currentRowCount); return currentRowCount; } diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp index 962054cc4..4c25d05e6 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.hpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp @@ -311,6 +311,7 @@ private: QSharedPointer mReplyModel; QSharedPointer mUnreadMessageNotice; int mBindingCalls = 0; + bool mPostModelChangedEvents = true; QWeakPointer mSelf; }; diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index 6637251d6..3e8c4a35e 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -33,10 +33,17 @@ Rectangle { color: ChatStyle.color clip: true - + Timer{// Let some time to have a better cell sizes + id: repositionerDelay + property int indexToMove + interval: 100 + onTriggered: chat.positionViewAtIndex(indexToMove, ListView.Center) + } function positionViewAtIndex(index){ chat.bindToEnd = false - chat.positionViewAtIndex(index, ListView.Beginning) + chat.positionViewAtIndex(index, ListView.Center) + repositionerDelay.indexToMove = index + repositionerDelay.restart() } function goToMessage(message){