From 2e04adf99ce6bf6b6c50376497115b4e0efec4e4 Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Mon, 29 Jul 2019 22:12:32 +0200 Subject: [PATCH] Fix never-ending loading by adding a new signal indicating the SMS plugin has received a reply (so is presumably done loading) This may need to be reworked at some point for more advanced usecases (multiple apps listening to SMS, variable-length message requests, etc.) but it's fine for now BUG 410095 --- plugins/sms/conversationsdbusinterface.cpp | 7 +++++++ plugins/sms/conversationsdbusinterface.h | 6 ++++++ smsapp/conversationmodel.cpp | 12 ++++++++++++ smsapp/conversationmodel.h | 4 ++++ smsapp/qml/ConversationDisplay.qml | 4 ++++ 5 files changed, 33 insertions(+) diff --git a/plugins/sms/conversationsdbusinterface.cpp b/plugins/sms/conversationsdbusinterface.cpp index 0a6fed99e..cc5c86fbe 100644 --- a/plugins/sms/conversationsdbusinterface.cpp +++ b/plugins/sms/conversationsdbusinterface.cpp @@ -143,6 +143,13 @@ void ConversationsDbusInterface::addMessages(const QList &m } } + // It feels bad to go through the set of updated conversations again, + // but also there are not many times that updatedConversationIDs will be more than one + for (qint64 conversationID : updatedConversationIDs) { + quint64 numMessages = m_known_messages[conversationID].size(); + Q_EMIT conversationLoaded(conversationID, numMessages); + } + waitingForMessagesLock.lock(); // Remove the waiting flag for all conversations which we just processed conversationsWaitingForMessages.subtract(updatedConversationIDs); diff --git a/plugins/sms/conversationsdbusinterface.h b/plugins/sms/conversationsdbusinterface.h index 3dbb34f6b..03d2782be 100644 --- a/plugins/sms/conversationsdbusinterface.h +++ b/plugins/sms/conversationsdbusinterface.h @@ -110,6 +110,12 @@ Q_SIGNALS: */ Q_SCRIPTABLE void conversationUpdated(const QDBusVariant& msg); + /** + * Emitted whenever we have handled a response from the phone indicating the total number of + * (locally-known) messages in the given conversation + */ + Q_SCRIPTABLE void conversationLoaded(qint64 conversationID, quint64 messageCount); + private /*methods*/: QString newId(); //Generates successive identifitiers to use as public ids diff --git a/smsapp/conversationmodel.cpp b/smsapp/conversationmodel.cpp index ad2c9ca16..0d3ea79fb 100644 --- a/smsapp/conversationmodel.cpp +++ b/smsapp/conversationmodel.cpp @@ -74,6 +74,7 @@ void ConversationModel::setDeviceId(const QString& deviceId) qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL) << "setDeviceId" << "of" << this; if (m_conversationsInterface) { disconnect(m_conversationsInterface, SIGNAL(conversationUpdated(QDBusVariant)), this, SLOT(handleConversationUpdate(QDBusVariant))); + disconnect(m_conversationsInterface, SIGNAL(conversationLoaded(qint64, quint64)), this, SLOT(handleConversationLoaded(qint64, quint64))); delete m_conversationsInterface; } @@ -81,6 +82,7 @@ void ConversationModel::setDeviceId(const QString& deviceId) m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); connect(m_conversationsInterface, SIGNAL(conversationUpdated(QDBusVariant)), this, SLOT(handleConversationUpdate(QDBusVariant))); + connect(m_conversationsInterface, SIGNAL(conversationLoaded(qint64, quint64)), this, SLOT(handleConversationLoaded(qint64, quint64))); } void ConversationModel::sendReplyToConversation(const QString& message) @@ -158,3 +160,13 @@ void ConversationModel::handleConversationUpdate(const QDBusVariant& msg) createRowFromMessage(message, 0); } + +void ConversationModel::handleConversationLoaded(qint64 threadID, quint64 numMessages) +{ + if (threadID != m_threadId) { + return; + } + // If we get this flag, it means that the phone will not be responding with any more messages + // so we should not be showing a loading indicator + Q_EMIT loadingFinished(); +} diff --git a/smsapp/conversationmodel.h b/smsapp/conversationmodel.h index caf682bfd..85d2e0c67 100644 --- a/smsapp/conversationmodel.h +++ b/smsapp/conversationmodel.h @@ -74,8 +74,12 @@ public: */ Q_INVOKABLE void copyToClipboard(const QString& message) const; +Q_SIGNALS: + void loadingFinished(); + private Q_SLOTS: void handleConversationUpdate(const QDBusVariant &message); + void handleConversationLoaded(qint64 threadID, quint64 numMessages); private: void createRowFromMessage(const ConversationMessage &message, int pos); diff --git a/smsapp/qml/ConversationDisplay.qml b/smsapp/qml/ConversationDisplay.qml index 571b81e01..9721f9fd7 100644 --- a/smsapp/qml/ConversationDisplay.qml +++ b/smsapp/qml/ConversationDisplay.qml @@ -44,6 +44,10 @@ Kirigami.ScrollablePage property var conversationModel: ConversationModel { deviceId: page.deviceId threadId: page.conversationId + + onLoadingFinished: { + page.isInitalized = true + } } property var addresses