diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index ace6181..b5d89d1 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -42,6 +42,7 @@ Page { property var chatGroupInformation; property int chatOnlineMemberCount: 0; property var emojiProposals; + property bool iterativeInitialization: false; readonly property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized (isBasicGroup || isSuperGroup) && ( (chatGroupInformation.status["@type"] === "chatMemberStatusMember") @@ -349,11 +350,16 @@ 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); - if(totalCount === 0) { - console.log("[ChatPage] actually, skipping that: No Messages in Chat."); - chatView.positionViewAtEnd(); - chatPage.loading = false; - return; + if (totalCount === 0) { + if (chatPage.iterativeInitialization) { + chatPage.iterativeInitialization = false; + console.log("[ChatPage] actually, skipping that: No Messages in Chat."); + chatView.positionViewAtEnd(); + chatPage.loading = false; + return; + } else { + chatPage.iterativeInitialization = true; + } } chatView.lastReadSentIndex = lastReadSentIndex; diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 02d448f..e85c726 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -197,7 +197,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo this->messagesMutex.unlock(); // First call only returns a few messages, we need to get a little more than that... - if ((this->messagesToBeAdded.size() + this->messages.size()) < 10 && !this->inReload) { + if (!this->messagesToBeAdded.isEmpty() && (this->messagesToBeAdded.size() + this->messages.size()) < 10 && !this->inReload) { LOG("Only a few messages received in first call, loading more..."); this->inReload = true; this->tdLibWrapper->getChatHistory(this->chatId, this->messagesToBeAdded.first().toMap().value(ID).toLongLong());