From d3062cafd41460113911c13c40fa6d4b67dcbcf0 Mon Sep 17 00:00:00 2001 From: Abdel-Rahman Abdel-Rahman Date: Fri, 20 Mar 2020 04:16:55 +0200 Subject: [PATCH] Receive SMS subscription ID and reply using it This interprets the "sub_id" field to use it later for replying in order to reply to SMS messages from the same SIM. --- interfaces/conversationmessage.cpp | 9 ++++++++- interfaces/conversationmessage.h | 15 ++++++++++++--- plugins/sms/conversationsdbusinterface.cpp | 2 +- plugins/sms/smsplugin.cpp | 8 ++++++-- plugins/sms/smsplugin.h | 5 +++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/interfaces/conversationmessage.cpp b/interfaces/conversationmessage.cpp index 2aaebef17..34e5b25d9 100644 --- a/interfaces/conversationmessage.cpp +++ b/interfaces/conversationmessage.cpp @@ -40,13 +40,16 @@ ConversationMessage::ConversationMessage(const QVariantMap& args) const auto& rawAddress = addressField.toMap(); m_addresses.append(ConversationAddress(rawAddress[QStringLiteral("address")].value())); } + QVariantMap::const_iterator subID_it = args.find(QStringLiteral("sub_id")); + m_subID = subID_it == args.end() ? -1 : subID_it->toLongLong(); } ConversationMessage::ConversationMessage (const qint32& eventField, const QString& body, const QList& addresses, const qint64& date, const qint32& type, const qint32& read, const qint64& threadID, - const qint32& uID) + const qint32& uID, + const qint64& subID) : m_eventField(eventField) , m_body(body) , m_addresses(addresses) @@ -55,6 +58,7 @@ ConversationMessage::ConversationMessage (const qint32& eventField, const QStrin , m_read(read) , m_threadID(threadID) , m_uID(uID) + , m_subID(subID) { } @@ -67,6 +71,7 @@ ConversationMessage::ConversationMessage(const ConversationMessage& other) , m_read(other.m_read) , m_threadID(other.m_threadID) , m_uID(other.m_uID) + , m_subID(other.m_subID) { } @@ -82,6 +87,7 @@ ConversationMessage& ConversationMessage::operator=(const ConversationMessage& o this->m_read = other.m_read; this->m_threadID = other.m_threadID; this->m_uID = other.m_uID; + this->m_subID = other.m_subID; return *this; } @@ -109,6 +115,7 @@ QVariantMap ConversationMessage::toVariant() const {QStringLiteral("read"), m_read}, {QStringLiteral("thread_id"), m_threadID}, {QStringLiteral("_id"), m_uID}, + {QStringLiteral("sub_id"), m_subID} }; } diff --git a/interfaces/conversationmessage.h b/interfaces/conversationmessage.h index 80d117422..d0ce78521 100644 --- a/interfaces/conversationmessage.h +++ b/interfaces/conversationmessage.h @@ -64,7 +64,7 @@ public: ConversationMessage(const qint32& eventField, const QString& body, const QList& addresses, const qint64& date, const qint32& type, const qint32& read, - const qint64& threadID, const qint32& uID); + const qint64& threadID, const qint32& uID, const qint64& subID); ConversationMessage(const ConversationMessage& other); ~ConversationMessage(); @@ -80,6 +80,7 @@ public: qint32 read() const { return m_read; } qint64 threadID() const { return m_threadID; } qint32 uID() const { return m_uID; } + qint64 subID() const { return m_subID; } QVariantMap toVariant() const; @@ -137,6 +138,11 @@ protected: * Value which uniquely identifies a message */ qint32 m_uID; + + /** + * Value which determines SIM id (optional) + */ + qint64 m_subID; }; class KDECONNECTINTERFACES_EXPORT ConversationAddress @@ -164,7 +170,8 @@ inline QDBusArgument &operator<<(QDBusArgument &argument, const ConversationMess << message.type() << message.read() << message.threadID() - << message.uID(); + << message.uID() + << message.subID(); argument.endStructure(); return argument; } @@ -179,6 +186,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, Conversati qint32 read; qint64 threadID; qint32 uID; + qint64 m_subID; argument.beginStructure(); argument >> event; @@ -189,9 +197,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, Conversati argument >> read; argument >> threadID; argument >> uID; + argument >> m_subID; argument.endStructure(); - message = ConversationMessage(event, body, addresses, date, type, read, threadID, uID); + message = ConversationMessage(event, body, addresses, date, type, read, threadID, uID, m_subID); return argument; } diff --git a/plugins/sms/conversationsdbusinterface.cpp b/plugins/sms/conversationsdbusinterface.cpp index 187d43b3f..909703040 100644 --- a/plugins/sms/conversationsdbusinterface.cpp +++ b/plugins/sms/conversationsdbusinterface.cpp @@ -205,7 +205,7 @@ void ConversationsDbusInterface::replyToConversation(const qint64& conversationI qCWarning(KDECONNECT_CONVERSATIONS) << "Sending replies to multiple recipients is not supported"; return; } - m_smsInterface.sendSms(addresses[0].address(), message); + m_smsInterface.sendSms(addresses[0].address(), message, messagesList.first().subID()); } void ConversationsDbusInterface::sendWithoutConversation(const QString& address, const QString& message) { diff --git a/plugins/sms/smsplugin.cpp b/plugins/sms/smsplugin.cpp index 52da9c440..5c926de95 100644 --- a/plugins/sms/smsplugin.cpp +++ b/plugins/sms/smsplugin.cpp @@ -59,13 +59,17 @@ bool SmsPlugin::receivePacket(const NetworkPacket& np) return true; } -void SmsPlugin::sendSms(const QString& phoneNumber, const QString& messageBody) +void SmsPlugin::sendSms(const QString& phoneNumber, const QString& messageBody, const qint64 subID) { - NetworkPacket np(PACKET_TYPE_SMS_REQUEST, { + QVariantMap packetMap({ {QStringLiteral("sendSms"), true}, {QStringLiteral("phoneNumber"), phoneNumber}, {QStringLiteral("messageBody"), messageBody} }); + if (subID != -1) { + packetMap[QStringLiteral("subID")] = subID; + } + NetworkPacket np(PACKET_TYPE_SMS_REQUEST, packetMap); qCDebug(KDECONNECT_PLUGIN_SMS) << "Dispatching SMS send request to remote"; sendPacket(np); } diff --git a/plugins/sms/smsplugin.h b/plugins/sms/smsplugin.h index c89b245c5..14804060a 100644 --- a/plugins/sms/smsplugin.h +++ b/plugins/sms/smsplugin.h @@ -87,7 +87,8 @@ * The body should look like so: * { "sendSms": true, * "phoneNumber": "542904563213", - * "messageBody": "Hi mom!" + * "messageBody": "Hi mom!", + * "sub_id": "3859358340534" * } */ #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request") @@ -126,7 +127,7 @@ public: QString dbusPath() const override; public Q_SLOTS: - Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody); + Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody, const qint64 subID = -1); /** * Send a request to the remote for all of its conversations