Commit 2e04adf9 authored by Simon Redman's avatar Simon Redman

Fix never-ending loading by adding a new signal indicating the SMS plugin has...

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
parent 5b733486
......@@ -143,6 +143,13 @@ void ConversationsDbusInterface::addMessages(const QList<ConversationMessage> &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);
......
......@@ -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
......
......@@ -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();
}
......@@ -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);
......
......@@ -44,6 +44,10 @@ Kirigami.ScrollablePage
property var conversationModel: ConversationModel {
deviceId: page.deviceId
threadId: page.conversationId
onLoadingFinished: {
page.isInitalized = true
}
}
property var addresses
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment