From 5fcca3c405094999e37347f5a7012272f62f9dfe Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sat, 29 Aug 2020 23:06:14 +0200 Subject: [PATCH] Try it again with loading more messages automatically --- qml/pages/ChatPage.qml | 13 +++++++++---- src/tdlibreceiver.cpp | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 9a4eb68..fadb77f 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -249,7 +249,7 @@ Page { Timer { id: chatViewLoadingTimer - interval: 500 + interval: 100 repeat: false running: false onTriggered: { @@ -269,13 +269,18 @@ Page { highlightFollowsCurrentItem: true function handleScrollPositionChanged() { + console.log("Current position: " + chatView.contentY); tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id); -// if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) { -// chatModel.triggerLoadMoreHistory(); -// } + var indexAtCursor = chatView.indexAt(chatView.contentX, chatView.contentY); + // If the list is at the top or close to the top, the index jumps to the top of the new list + // Before we find a solution, we don't reload at the top... TODO ;) + if (indexAtCursor > 5 && indexAtCursor < 25) { + chatModel.triggerLoadMoreHistory(); + } } onContentYChanged: { + chatViewLoadingTimer.stop(); chatViewLoadingTimer.start(); } diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index dfe762a..d8c51f5 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -42,7 +42,7 @@ void TDLibReceiver::receiverLoop() const char *result = td_json_client_receive(this->tdLibClient, WAIT_TIMEOUT); if (result) { QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result)); - // qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented); + qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented); processReceivedDocument(receivedJsonDocument); } }