Fix crash when forwarding to some chats, introduce iterative init

This commit is contained in:
Sebastian Wolf 2020-11-16 16:52:48 +01:00
parent 6e6396eac4
commit 9141b8e68b
2 changed files with 12 additions and 6 deletions

View file

@ -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) {
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;

View file

@ -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());