Fix infinite loading for small amount of messages

This commit is contained in:
Sebastian J. Wolf 2020-08-29 18:28:57 +02:00
parent 63833b3c5c
commit cca241ed9a
3 changed files with 35 additions and 30 deletions

View file

@ -152,7 +152,6 @@ Page {
target: chatModel target: chatModel
onMessagesReceived: { onMessagesReceived: {
chatPage.loading = false; chatPage.loading = false;
chatView.positionViewAtEnd();
} }
onNewMessageReceived: { onNewMessageReceived: {
// Notify user about new messages... // Notify user about new messages...
@ -253,9 +252,9 @@ Page {
function handleScrollPositionChanged() { function handleScrollPositionChanged() {
tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id); tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id);
if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) { // if (chatView.indexAt(chatView.contentX, chatView.contentY) < 10) {
chatModel.triggerLoadMoreHistory(); // chatModel.triggerLoadMoreHistory();
} // }
} }
onMovementEnded: { onMovementEnded: {

View file

@ -80,10 +80,15 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages)
qDebug() << "[ChatModel] Receiving new messages :)" << messages.size(); qDebug() << "[ChatModel] Receiving new messages :)" << messages.size();
if (messages.size() == 0) { if (messages.size() == 0) {
emit noMessagesAvailable(); qDebug() << "[ChatModel] No additional messages loaded, notifying chat UI...";
return; this->inReload = false;
if (this->inIncrementalUpdate) {
this->inIncrementalUpdate = false;
emit messagesIncrementalUpdate();
} else {
emit messagesReceived();
} }
} else {
this->messagesMutex.lock(); this->messagesMutex.lock();
this->messagesToBeAdded.clear(); this->messagesToBeAdded.clear();
QListIterator<QVariant> messagesIterator(messages); QListIterator<QVariant> messagesIterator(messages);
@ -100,7 +105,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages)
// 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() < 10 && !this->inReload) { if (this->messagesToBeAdded.size() < 10 && !this->inReload) {
qDebug() << "[ChatModel] Only one message received in first call, loading more..."; qDebug() << "[ChatModel] 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());
} else { } else {
@ -113,6 +118,8 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages)
emit messagesReceived(); emit messagesReceived();
} }
} }
}
} }
void ChatModel::handleNewMessageReceived(const QString &chatId, const QVariantMap &message) void ChatModel::handleNewMessageReceived(const QString &chatId, const QVariantMap &message)

View file

@ -23,7 +23,6 @@ public:
signals: signals:
void messagesReceived(); void messagesReceived();
void messagesIncrementalUpdate(); void messagesIncrementalUpdate();
void noMessagesAvailable();
void newMessageReceived(); void newMessageReceived();
public slots: public slots: