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
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
}

View file

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

View file

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