New chat positioning method: Faster, but less exact

This commit is contained in:
Sebastian J. Wolf 2020-09-13 23:25:48 +02:00
parent 386c4c871f
commit 8f3f7cfa9b
2 changed files with 5 additions and 10 deletions

View file

@ -183,10 +183,9 @@ Page {
target: chatModel target: chatModel
onMessagesReceived: { onMessagesReceived: {
console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex); console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
chatView.currentIndex = modelIndex;
chatView.lastReadSentIndex = lastReadSentIndex; chatView.lastReadSentIndex = lastReadSentIndex;
chatViewLoadingTimer.stop(); chatView.positionViewAtIndex(modelIndex, ListView.Contain);
chatViewLoadingTimer.start(); chatPage.loading = false;
} }
onNewMessageReceived: { onNewMessageReceived: {
// Notify user about new messages... // Notify user about new messages...
@ -308,7 +307,6 @@ Page {
Behavior on opacity { NumberAnimation {} } Behavior on opacity { NumberAnimation {} }
clip: true clip: true
highlightFollowsCurrentItem: true
property int lastReadSentIndex: 0 property int lastReadSentIndex: 0
@ -318,8 +316,6 @@ Page {
} }
onContentYChanged: { onContentYChanged: {
chatViewLoadingTimer.stop();
chatViewLoadingTimer.start();
if (!chatPage.loading) { if (!chatPage.loading) {
if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) { if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) {
console.log("Trying to get older history items..."); console.log("Trying to get older history items...");

View file

@ -256,10 +256,9 @@ int ChatModel::calculateLastKnownMessageId()
qDebug() << "[ChatModel] lastKnownMessageId" << lastKnownMessageId; qDebug() << "[ChatModel] lastKnownMessageId" << lastKnownMessageId;
qDebug() << "[ChatModel] size messageIndexMap" << this->messageIndexMap.size(); qDebug() << "[ChatModel] size messageIndexMap" << this->messageIndexMap.size();
qDebug() << "[ChatModel] contains ID?" << this->messageIndexMap.contains(lastKnownMessageId); qDebug() << "[ChatModel] contains ID?" << this->messageIndexMap.contains(lastKnownMessageId);
// TODO: List sometimes crashes if index is set to the last item. Trying with the second last for now. int listInboxPosition = this->messageIndexMap.value(lastKnownMessageId, this->messages.size() - 1).toInt();
int listInboxPosition = this->messageIndexMap.value(lastKnownMessageId, this->messages.size() - 2).toInt(); if (listInboxPosition > this->messages.size() - 1 ) {
if (listInboxPosition > this->messages.size() - 2 ) { listInboxPosition = this->messages.size() - 1;
listInboxPosition = this->messages.size() - 2;
} }
qDebug() << "[ChatModel] Last known message is at position" << listInboxPosition; qDebug() << "[ChatModel] Last known message is at position" << listInboxPosition;
return listInboxPosition; return listInboxPosition;