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
onMessagesReceived: {
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;
chatViewLoadingTimer.stop();
chatViewLoadingTimer.start();
chatView.positionViewAtIndex(modelIndex, ListView.Contain);
chatPage.loading = false;
}
onNewMessageReceived: {
// Notify user about new messages...
@ -308,7 +307,6 @@ Page {
Behavior on opacity { NumberAnimation {} }
clip: true
highlightFollowsCurrentItem: true
property int lastReadSentIndex: 0
@ -318,8 +316,6 @@ Page {
}
onContentYChanged: {
chatViewLoadingTimer.stop();
chatViewLoadingTimer.start();
if (!chatPage.loading) {
if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) {
console.log("Trying to get older history items...");

View file

@ -256,10 +256,9 @@ int ChatModel::calculateLastKnownMessageId()
qDebug() << "[ChatModel] lastKnownMessageId" << lastKnownMessageId;
qDebug() << "[ChatModel] size messageIndexMap" << this->messageIndexMap.size();
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() - 2).toInt();
if (listInboxPosition > this->messages.size() - 2 ) {
listInboxPosition = this->messages.size() - 2;
int listInboxPosition = this->messageIndexMap.value(lastKnownMessageId, this->messages.size() - 1).toInt();
if (listInboxPosition > this->messages.size() - 1 ) {
listInboxPosition = this->messages.size() - 1;
}
qDebug() << "[ChatModel] Last known message is at position" << listInboxPosition;
return listInboxPosition;