diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index 026a7899e..d676df8a4 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -32,6 +32,11 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) } void ChatProxyModel::loadMoreEntries () { + // Do not increase `m_n_max_displayed_entries` if it's not necessary... + // Limit qml calls. + if (m_chat_model_filter.rowCount() <= m_n_max_displayed_entries) + return; + int count = rowCount(); m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE; @@ -41,6 +46,13 @@ void ChatProxyModel::loadMoreEntries () { emit moreEntriesLoaded(); } +void ChatProxyModel::setEntryTypeFilter (ChatModel::EntryType type) { + if (m_chat_model_filter.m_entry_type_filter != type) { + m_chat_model_filter.setEntryTypeFilter(type); + emit entryTypeFilterChanged(type); + } +} + void ChatProxyModel::removeEntry (int id) { QModelIndex source_index = mapToSource(index(id, 0)); static_cast(m_chat_model_filter.sourceModel())->removeEntry( diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index e936e35f0..c1d3951f7 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -43,6 +43,7 @@ class ChatProxyModel : public QSortFilterProxyModel { signals: void sipAddressChanged (const QString &sipAddress); void moreEntriesLoaded (); + void entryTypeFilterChanged (ChatModel::EntryType type); public: ChatProxyModel (QObject *parent = Q_NULLPTR); @@ -50,9 +51,7 @@ public: public slots: void loadMoreEntries (); - void setEntryTypeFilter (ChatModel::EntryType type) { - m_chat_model_filter.setEntryTypeFilter(type); - } + void setEntryTypeFilter (ChatModel::EntryType type); void removeEntry (int id); diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index 7503d5a4f..f2052e9e8 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3 import Common 1.0 import Linphone 1.0 import Linphone.Styles 1.0 +import Utils 1.0 // =================================================================== @@ -16,7 +17,7 @@ ColumnLayout { // Set the offset position to load more entries. // Not a style property. - property int _loadMoreEntriesAtPosition: 1 + property int _loadMoreEntriesAtPosition: 25 // ----------------------------------------------------------------- @@ -27,11 +28,11 @@ ColumnLayout { property bool _tryToLoadMoreEntries: true - function _loadMoreEntries () { - if ( + function _loadMoreEntries (force) { + if (( chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition && - !_tryToLoadMoreEntries - ) { + !_tryToLoadMoreEntries + ) || force) { _tryToLoadMoreEntries = true proxyModel.loadMoreEntries() } @@ -181,16 +182,35 @@ ColumnLayout { } } - onContentYChanged: _loadMoreEntries() - Component.onCompleted: { - positionViewAtEnd() - _tryToLoadMoreEntries = false - - proxyModel.moreEntriesLoaded.connect(function () { + var initView = function () { + positionViewAtEnd() _tryToLoadMoreEntries = false + } + + // Received only if more entries was loaded. + proxyModel.moreEntriesLoaded.connect(function () { + if (ScrollBar.vertical.pressed && atYBeginning) { + // Use a timeout to not increase call stack. + Utils.setTimeout(chat, 0, function () { + _loadMoreEntries(true) + positionViewAtIndex(1, ListView.Beginning) + }) + } else { + _tryToLoadMoreEntries = false + } }) + + // When the view is changed (for example `Calls` -> `Messages`), + // the position is set at end and it can be possible to load + // more entries. + proxyModel.entryTypeFilterChanged.connect(initView) + + // First render. + initView() } + + onContentYChanged: _loadMoreEntries() } // -----------------------------------------------------------------