React properly if no messages are there...

This commit is contained in:
Sebastian J. Wolf 2020-08-23 17:24:05 +02:00
parent cc266aa58b
commit 63966f052a
3 changed files with 11 additions and 5 deletions

View file

@ -316,7 +316,7 @@ Page {
id: messageDateText id: messageDateText
text: Functions.getDateTimeElapsed(display.date) text: Functions.getDateTimeElapsed(display.date)
font.pixelSize: Theme.fontSizeTiny 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 horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft
} }

View file

@ -64,9 +64,14 @@ bool compareMessages(const QVariant &message1, const QVariant &message2)
void ChatModel::handleMessagesReceived(const QVariantList &messages) void ChatModel::handleMessagesReceived(const QVariantList &messages)
{ {
qDebug() << "[ChatModel] Receiving new messages :)"; qDebug() << "[ChatModel] Receiving new messages :)" << messages.size();
this->messagesMutex.lock();
if (messages.size() == 0) {
emit noMessagesAvailable();
return;
}
this->messagesMutex.lock();
this->messagesToBeAdded.clear(); this->messagesToBeAdded.clear();
QListIterator<QVariant> messagesIterator(messages); QListIterator<QVariant> messagesIterator(messages);
while (messagesIterator.hasNext()) { while (messagesIterator.hasNext()) {
@ -80,8 +85,8 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages)
this->insertMessages(); this->insertMessages();
this->messagesMutex.unlock(); this->messagesMutex.unlock();
// First call only returns one message, 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() == 1 && !this->inReload) { if (this->messagesToBeAdded.size() < 10 && !this->inReload) {
qDebug() << "[ChatModel] Only one message received in first call, loading more..."; qDebug() << "[ChatModel] Only one message 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());

View file

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