Workaround for chat listview crashes (no last item, why?)

This commit is contained in:
Sebastian J. Wolf 2020-08-31 23:50:39 +02:00
parent a04332d4b6
commit 1a3768b79b

View file

@ -237,7 +237,11 @@ 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);
int listInboxPosition = this->messageIndexMap.value(lastKnownMessageId, this->messages.size() - 1).toInt(); // 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;
}
qDebug() << "[ChatModel] Last known message is at position" << listInboxPosition; qDebug() << "[ChatModel] Last known message is at position" << listInboxPosition;
return listInboxPosition; return listInboxPosition;
} }