From 1a3768b79bd83415e47540511e6b98dda664c6b4 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Mon, 31 Aug 2020 23:50:39 +0200 Subject: [PATCH] Workaround for chat listview crashes (no last item, why?) --- src/chatmodel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 86ca4ef..6731305 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -237,7 +237,11 @@ int ChatModel::calculateLastKnownMessageId() qDebug() << "[ChatModel] lastKnownMessageId" << lastKnownMessageId; qDebug() << "[ChatModel] size messageIndexMap" << this->messageIndexMap.size(); 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; return listInboxPosition; }