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 var chatGroupInformation;
property int chatOnlineMemberCount: 0; property int chatOnlineMemberCount: 0;
property var emojiProposals; property var emojiProposals;
property bool iterativeInitialization: false;
readonly property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized readonly property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized
(isBasicGroup || isSuperGroup) && ( (isBasicGroup || isSuperGroup) && (
(chatGroupInformation.status["@type"] === "chatMemberStatusMember") (chatGroupInformation.status["@type"] === "chatMemberStatusMember")
@ -349,11 +350,16 @@ Page {
target: chatModel target: chatModel
onMessagesReceived: { onMessagesReceived: {
console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex); 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) {
console.log("[ChatPage] actually, skipping that: No Messages in Chat."); if (chatPage.iterativeInitialization) {
chatView.positionViewAtEnd(); chatPage.iterativeInitialization = false;
chatPage.loading = false; console.log("[ChatPage] actually, skipping that: No Messages in Chat.");
return; chatView.positionViewAtEnd();
chatPage.loading = false;
return;
} else {
chatPage.iterativeInitialization = true;
}
} }
chatView.lastReadSentIndex = lastReadSentIndex; chatView.lastReadSentIndex = lastReadSentIndex;

View file

@ -197,7 +197,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
this->messagesMutex.unlock(); this->messagesMutex.unlock();
// First call only returns a few messages, we need to get a little more than that... // 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..."); LOG("Only a few messages received in first call, loading more...");
this->inReload = true; this->inReload = true;
this->tdLibWrapper->getChatHistory(this->chatId, this->messagesToBeAdded.first().toMap().value(ID).toLongLong()); this->tdLibWrapper->getChatHistory(this->chatId, this->messagesToBeAdded.first().toMap().value(ID).toLongLong());