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.
This commit is contained in:
Abdel-Rahman Abdel-Rahman 2020-03-20 04:16:55 +02:00
parent 0e04769a43
commit d3062cafd4
5 changed files with 30 additions and 9 deletions

View file

@ -40,13 +40,16 @@ ConversationMessage::ConversationMessage(const QVariantMap& args)
const auto& rawAddress = addressField.toMap(); const auto& rawAddress = addressField.toMap();
m_addresses.append(ConversationAddress(rawAddress[QStringLiteral("address")].value<QString>())); m_addresses.append(ConversationAddress(rawAddress[QStringLiteral("address")].value<QString>()));
} }
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, ConversationMessage::ConversationMessage (const qint32& eventField, const QString& body,
const QList<ConversationAddress>& addresses, const qint64& date, const QList<ConversationAddress>& addresses, const qint64& date,
const qint32& type, const qint32& read, const qint32& type, const qint32& read,
const qint64& threadID, const qint64& threadID,
const qint32& uID) const qint32& uID,
const qint64& subID)
: m_eventField(eventField) : m_eventField(eventField)
, m_body(body) , m_body(body)
, m_addresses(addresses) , m_addresses(addresses)
@ -55,6 +58,7 @@ ConversationMessage::ConversationMessage (const qint32& eventField, const QStrin
, m_read(read) , m_read(read)
, m_threadID(threadID) , m_threadID(threadID)
, m_uID(uID) , m_uID(uID)
, m_subID(subID)
{ {
} }
@ -67,6 +71,7 @@ ConversationMessage::ConversationMessage(const ConversationMessage& other)
, m_read(other.m_read) , m_read(other.m_read)
, m_threadID(other.m_threadID) , m_threadID(other.m_threadID)
, m_uID(other.m_uID) , 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_read = other.m_read;
this->m_threadID = other.m_threadID; this->m_threadID = other.m_threadID;
this->m_uID = other.m_uID; this->m_uID = other.m_uID;
this->m_subID = other.m_subID;
return *this; return *this;
} }
@ -109,6 +115,7 @@ QVariantMap ConversationMessage::toVariant() const
{QStringLiteral("read"), m_read}, {QStringLiteral("read"), m_read},
{QStringLiteral("thread_id"), m_threadID}, {QStringLiteral("thread_id"), m_threadID},
{QStringLiteral("_id"), m_uID}, {QStringLiteral("_id"), m_uID},
{QStringLiteral("sub_id"), m_subID}
}; };
} }

View file

@ -64,7 +64,7 @@ public:
ConversationMessage(const qint32& eventField, const QString& body, const QList<ConversationAddress>& addresses, ConversationMessage(const qint32& eventField, const QString& body, const QList<ConversationAddress>& addresses,
const qint64& date, const qint32& type, const qint32& read, 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(const ConversationMessage& other);
~ConversationMessage(); ~ConversationMessage();
@ -80,6 +80,7 @@ public:
qint32 read() const { return m_read; } qint32 read() const { return m_read; }
qint64 threadID() const { return m_threadID; } qint64 threadID() const { return m_threadID; }
qint32 uID() const { return m_uID; } qint32 uID() const { return m_uID; }
qint64 subID() const { return m_subID; }
QVariantMap toVariant() const; QVariantMap toVariant() const;
@ -137,6 +138,11 @@ protected:
* Value which uniquely identifies a message * Value which uniquely identifies a message
*/ */
qint32 m_uID; qint32 m_uID;
/**
* Value which determines SIM id (optional)
*/
qint64 m_subID;
}; };
class KDECONNECTINTERFACES_EXPORT ConversationAddress class KDECONNECTINTERFACES_EXPORT ConversationAddress
@ -164,7 +170,8 @@ inline QDBusArgument &operator<<(QDBusArgument &argument, const ConversationMess
<< message.type() << message.type()
<< message.read() << message.read()
<< message.threadID() << message.threadID()
<< message.uID(); << message.uID()
<< message.subID();
argument.endStructure(); argument.endStructure();
return argument; return argument;
} }
@ -179,6 +186,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, Conversati
qint32 read; qint32 read;
qint64 threadID; qint64 threadID;
qint32 uID; qint32 uID;
qint64 m_subID;
argument.beginStructure(); argument.beginStructure();
argument >> event; argument >> event;
@ -189,9 +197,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &argument, Conversati
argument >> read; argument >> read;
argument >> threadID; argument >> threadID;
argument >> uID; argument >> uID;
argument >> m_subID;
argument.endStructure(); 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; return argument;
} }

View file

@ -205,7 +205,7 @@ void ConversationsDbusInterface::replyToConversation(const qint64& conversationI
qCWarning(KDECONNECT_CONVERSATIONS) << "Sending replies to multiple recipients is not supported"; qCWarning(KDECONNECT_CONVERSATIONS) << "Sending replies to multiple recipients is not supported";
return; 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) { void ConversationsDbusInterface::sendWithoutConversation(const QString& address, const QString& message) {

View file

@ -59,13 +59,17 @@ bool SmsPlugin::receivePacket(const NetworkPacket& np)
return true; 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("sendSms"), true},
{QStringLiteral("phoneNumber"), phoneNumber}, {QStringLiteral("phoneNumber"), phoneNumber},
{QStringLiteral("messageBody"), messageBody} {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"; qCDebug(KDECONNECT_PLUGIN_SMS) << "Dispatching SMS send request to remote";
sendPacket(np); sendPacket(np);
} }

View file

@ -87,7 +87,8 @@
* The body should look like so: * The body should look like so:
* { "sendSms": true, * { "sendSms": true,
* "phoneNumber": "542904563213", * "phoneNumber": "542904563213",
* "messageBody": "Hi mom!" * "messageBody": "Hi mom!",
* "sub_id": "3859358340534"
* } * }
*/ */
#define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request") #define PACKET_TYPE_SMS_REQUEST QStringLiteral("kdeconnect.sms.request")
@ -126,7 +127,7 @@ public:
QString dbusPath() const override; QString dbusPath() const override;
public Q_SLOTS: 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 * Send a request to the remote for all of its conversations