diff --git a/plugins/sms/conversationsdbusinterface.h b/plugins/sms/conversationsdbusinterface.h --- a/plugins/sms/conversationsdbusinterface.h +++ b/plugins/sms/conversationsdbusinterface.h @@ -53,9 +53,12 @@ public Q_SLOTS: /** - * Return a list of the threadID for all valid conversations + * Return a list of the first message in every conversation + * + * Note that the return value is a list of QVariants, which in turn have a value of + * QVariantMap created from each message */ - QStringList activeConversations(); + QVariantList activeConversations(); void requestConversation(const QString &conversationID, int start, int end); @@ -70,7 +73,7 @@ void requestAllConversationThreads(); Q_SIGNALS: - Q_SCRIPTABLE void conversationCreated(const QString& threadID); + Q_SCRIPTABLE void conversationCreated(const QVariantMap& msg); Q_SCRIPTABLE void conversationRemoved(const QString& threadID); Q_SCRIPTABLE void conversationUpdated(const QVariantMap& msg) const; Q_SCRIPTABLE void conversationMessageReceived(const QVariantMap& msg, int pos) const; diff --git a/plugins/sms/conversationsdbusinterface.cpp b/plugins/sms/conversationsdbusinterface.cpp --- a/plugins/sms/conversationsdbusinterface.cpp +++ b/plugins/sms/conversationsdbusinterface.cpp @@ -43,9 +43,18 @@ { } -QStringList ConversationsDbusInterface::activeConversations() +QVariantList ConversationsDbusInterface::activeConversations() { - return m_conversations.keys(); + QList toReturn; + toReturn.reserve(m_conversations.size()); + + for (const auto& conversation : m_conversations) + { + const QVariantMap& message = (*conversation.cbegin()).toVariant(); + toReturn.append(QVariant(message)); + } + + return toReturn; } void ConversationsDbusInterface::requestConversation(const QString& conversationID, int start, int end) @@ -58,12 +67,15 @@ qCWarning(KDECONNECT_CONVERSATIONS) << "Got a conversationID for a conversation with no messages!" << conversationID; } + // TODO: Check local cache before requesting new messages + // TODO: Make Android interface capable of requesting small window of messages m_smsInterface.requestConversation(conversationID); // Messages are sorted in ascending order of keys, meaning the front of the list has the oldest // messages (smallest timestamp number) // Therefore, return the end of the list first (most recent messages) int i = start; + // TODO: BUG: What if the caller asked for start != 0? for(auto it = messagesList.crbegin(); it != messagesList.crend(); ++it) { Q_EMIT conversationMessageReceived(it->toVariant(), i); @@ -93,7 +105,7 @@ // Tell the world about what just happened if (newConversation) { - Q_EMIT conversationCreated(threadId); + Q_EMIT conversationCreated(message.toVariant()); } else { Q_EMIT conversationUpdated(message.toVariant()); diff --git a/smsapp/conversationlistmodel.h b/smsapp/conversationlistmodel.h --- a/smsapp/conversationlistmodel.h +++ b/smsapp/conversationlistmodel.h @@ -86,8 +86,9 @@ void setDeviceId(const QString &/*deviceId*/); public Q_SLOTS: - void handleCreatedConversation(const QString& conversationId); - void createRowFromMessage(const QVariantMap& message, int row); + void handleCreatedConversation(const QVariantMap& msg); + void handleConversationUpdated(const QVariantMap& msg); + void createRowFromMessage(const QVariantMap& message); void printDBusError(const QDBusError& error); private: diff --git a/smsapp/conversationlistmodel.cpp b/smsapp/conversationlistmodel.cpp --- a/smsapp/conversationlistmodel.cpp +++ b/smsapp/conversationlistmodel.cpp @@ -52,35 +52,50 @@ return; if (m_conversationsInterface) { - disconnect(m_conversationsInterface, SIGNAL(conversationCreated(QString)), this, SLOT(handleCreatedConversation(QString))); + disconnect(m_conversationsInterface, SIGNAL(conversationCreated(QVariantMap)), this, SLOT(handleCreatedConversation(QVariantMap))); + disconnect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdated(QVariantMap))); delete m_conversationsInterface; + m_conversationsInterface = nullptr; } m_deviceId = deviceId; + + if (deviceId == "") { + // When the device is first connecting we get junk + return; + } + m_conversationsInterface = new DeviceConversationsDbusInterface(deviceId, this); - connect(m_conversationsInterface, SIGNAL(conversationCreated(QString)), this, SLOT(handleCreatedConversation(QString))); - connect(m_conversationsInterface, SIGNAL(conversationMessageReceived(QVariantMap, int)), this, SLOT(createRowFromMessage(QVariantMap, int))); + connect(m_conversationsInterface, SIGNAL(conversationCreated(QVariantMap)), this, SLOT(handleCreatedConversation(QVariantMap))); + connect(m_conversationsInterface, SIGNAL(conversationUpdated(QVariantMap)), this, SLOT(handleConversationUpdated(QVariantMap))); prepareConversationsList(); m_conversationsInterface->requestAllConversationThreads(); } void ConversationListModel::prepareConversationsList() { - - QDBusPendingReply validThreadIDsReply = m_conversationsInterface->activeConversations(); - - setWhenAvailable(validThreadIDsReply, [this](const QStringList& convs) { - clear(); - for (const QString& conversationId : convs) { - handleCreatedConversation(conversationId); + clear(); + QDBusPendingReply validThreadIDsReply = m_conversationsInterface->activeConversations(); + + setWhenAvailable(validThreadIDsReply, [this](const QVariantList& convs) { + for (const QVariant& headMessage : convs) { + QDBusArgument data = headMessage.value(); + QVariantMap message; + data >> message; + handleCreatedConversation(message); } }, this); } -void ConversationListModel::handleCreatedConversation(const QString& conversationId) +void ConversationListModel::handleCreatedConversation(const QVariantMap& msg) { - m_conversationsInterface->requestConversation(conversationId, 0, 1); + createRowFromMessage(msg); +} + +void ConversationListModel::handleConversationUpdated(const QVariantMap& msg) +{ + return; } void ConversationListModel::printDBusError(const QDBusError& error) @@ -98,11 +113,8 @@ return nullptr; } -void ConversationListModel::createRowFromMessage(const QVariantMap& msg, int row) +void ConversationListModel::createRowFromMessage(const QVariantMap& msg) { - if (row != 0) - return; - const ConversationMessage message(msg); if (message.type() == -1) {