From 63966f052a9f0662321e52a127cc5cbe1c930dd0 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sun, 23 Aug 2020 17:24:05 +0200 Subject: [PATCH] React properly if no messages are there... --- qml/pages/ChatPage.qml | 2 +- src/chatmodel.cpp | 13 +++++++++---- src/chatmodel.h | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index cf636b4..cedbf24 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -316,7 +316,7 @@ Page { id: messageDateText text: Functions.getDateTimeElapsed(display.date) font.pixelSize: Theme.fontSizeTiny - color: chatPage.myUserId === display.sender_user_id ? Theme.highlightColor : Theme.primaryColor + color: chatPage.myUserId === display.sender_user_id ? Theme.secondaryHighlightColor : Theme.secondaryColor horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft } diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 9750d30..22289d9 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -64,9 +64,14 @@ bool compareMessages(const QVariant &message1, const QVariant &message2) void ChatModel::handleMessagesReceived(const QVariantList &messages) { - qDebug() << "[ChatModel] Receiving new messages :)"; - this->messagesMutex.lock(); + qDebug() << "[ChatModel] Receiving new messages :)" << messages.size(); + if (messages.size() == 0) { + emit noMessagesAvailable(); + return; + } + + this->messagesMutex.lock(); this->messagesToBeAdded.clear(); QListIterator messagesIterator(messages); while (messagesIterator.hasNext()) { @@ -80,8 +85,8 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages) this->insertMessages(); this->messagesMutex.unlock(); - // First call only returns one message, we need to get a little more than that... - if (this->messagesToBeAdded.size() == 1 && !this->inReload) { + // First call only returns a few messages, we need to get a little more than that... + if (this->messagesToBeAdded.size() < 10 && !this->inReload) { qDebug() << "[ChatModel] Only one message received in first call, loading more..."; this->inReload = true; this->tdLibWrapper->getChatHistory(this->chatId, this->messagesToBeAdded.first().toMap().value("id").toLongLong()); diff --git a/src/chatmodel.h b/src/chatmodel.h index 8f89f9e..41cbd9a 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -21,6 +21,7 @@ public: signals: void messagesReceived(); + void noMessagesAvailable(); void newMessageReceived(); public slots: