Commit c1e36895 authored by Simon Redman's avatar Simon Redman

[Desktop] Make message syncronization interface capable of handling future changes

Summary:
Add "event" field to ConversationMessage

Update packet type with proper field names and commenting

Future "proof" SmsPlugin against new event types

Test Plan:
 - Install the corresponding Android-side patch D16600
 - Verify that it is possible to synchronize messages the same as it was before

Reviewers: #kde_connect, apol

Reviewed By: #kde_connect, apol

Subscribers: apol, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D16599
parent 4bd509df
......@@ -26,6 +26,7 @@
ConversationMessage::ConversationMessage(const QVariantMap& args, QObject* parent)
: QObject(parent),
m_eventField(args["event"].toInt()),
m_body(args["body"].toString()),
m_address(args["address"].toString()),
m_date(args["date"].toLongLong()),
......@@ -36,11 +37,14 @@ ConversationMessage::ConversationMessage(const QVariantMap& args, QObject* paren
{
}
ConversationMessage::ConversationMessage (const QString& body, const QString& address, const qint64& date,
const qint32& type, const qint32& read, const qint32& threadID,
ConversationMessage::ConversationMessage (const qint32& eventField, const QString& body,
const QString& address, const qint64& date,
const qint32& type, const qint32& read,
const qint32& threadID,
const qint32& uID,
QObject* parent)
: QObject(parent)
, m_eventField(eventField)
, m_body(body)
, m_address(address)
, m_date(date)
......@@ -53,6 +57,7 @@ ConversationMessage::ConversationMessage (const QString& body, const QString& ad
ConversationMessage::ConversationMessage(const ConversationMessage& other, QObject* parent)
: QObject(parent)
, m_eventField(other.m_eventField)
, m_body(other.m_body)
, m_address(other.m_address)
, m_date(other.m_date)
......@@ -67,6 +72,7 @@ ConversationMessage::~ConversationMessage() { }
ConversationMessage& ConversationMessage::operator=(const ConversationMessage& other)
{
this->m_eventField = other.m_eventField;
this->m_body = other.m_body;
this->m_address = other.m_address;
this->m_date = other.m_date;
......@@ -80,6 +86,7 @@ ConversationMessage& ConversationMessage::operator=(const ConversationMessage& o
QVariantMap ConversationMessage::toVariant() const
{
return {
{"event", m_eventField},
{"body", m_body},
{"address", m_address},
{"date", m_date},
......@@ -93,14 +100,21 @@ QVariantMap ConversationMessage::toVariant() const
QDBusArgument &operator<<(QDBusArgument &argument, const ConversationMessage &message)
{
argument.beginStructure();
argument << message.body() << message.address() << message.date() << message.type()
<< message.read() << message.threadID() << message.uID();
argument << message.eventField()
<< message.body()
<< message.address()
<< message.date()
<< message.type()
<< message.read()
<< message.threadID()
<< message.uID();
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, ConversationMessage &message)
{
qint32 event;
QString body;
QString address;
qint64 date;
......@@ -110,6 +124,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, ConversationMessa
qint32 uID;
argument.beginStructure();
argument >> event;
argument >> body;
argument >> address;
argument >> date;
......@@ -119,7 +134,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, ConversationMessa
argument >> uID;
argument.endStructure();
message = ConversationMessage(body, address, date, type, read, threadID, uID);
message = ConversationMessage(event, body, address, date, type, read, threadID, uID);
return argument;
}
......
......@@ -32,6 +32,7 @@ class KDECONNECTINTERFACES_EXPORT ConversationMessage
: public QObject {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.telephony.messages")
Q_PROPERTY(qint32 eventField READ eventField)
Q_PROPERTY(QString body READ body)
Q_PROPERTY(QString address READ address)
Q_PROPERTY(qint64 date READ date)
......@@ -53,6 +54,16 @@ public:
};
Q_ENUM(Types);
/**
* Values describing the possible type of events contained in a message
* A message's eventField is constructed as a bitwise-OR of events
* Any events which are unsupported should be ignored
*/
enum Events {
EventTextMessage = 0x1, // This message has a body field which contains pure, human-readable text
};
Q_ENUM(Events)
/**
* Build a new message from a keyword argument dictionary
*
......@@ -60,9 +71,9 @@ public:
*/
ConversationMessage(const QVariantMap& args = QVariantMap(), QObject* parent = Q_NULLPTR);
ConversationMessage(const QString& body, const QString& address, const qint64& date,
const qint32& type, const qint32& read, const qint32& threadID,
const qint32& uID,
ConversationMessage(const qint32& eventField, const QString& body, const QString& address,
const qint64& date, const qint32& type, const qint32& read,
const qint32& threadID, const qint32& uID,
QObject* parent = Q_NULLPTR);
ConversationMessage(const ConversationMessage& other, QObject* parent = Q_NULLPTR);
......@@ -70,6 +81,7 @@ public:
ConversationMessage& operator=(const ConversationMessage& other);
static void registerDbusType();
qint32 eventField() const { return m_eventField; }
QString body() const { return m_body; }
QString address() const { return m_address; }
qint64 date() const { return m_date; }
......@@ -80,7 +92,15 @@ public:
QVariantMap toVariant() const;
bool containsTextBody() const { return (eventField() & ConversationMessage::EventTextMessage); }
protected:
/**
* Bitwise OR of event flags
* Unsupported flags shall cause the message to be ignored
*/
qint32 m_eventField;
/**
* Body of the message
*/
......
......@@ -102,8 +102,10 @@ bool SmsPlugin::handleBatchMessages(const NetworkPacket& np)
for (const QVariant& body : messages) {
ConversationMessage message(body.toMap());
forwardToTelepathy(message);
m_conversationInterface->addMessage(message);
if (message.containsTextBody()) {
forwardToTelepathy(message);
m_conversationInterface->addMessage(message);
}
}
return true;
......
......@@ -38,17 +38,20 @@
*
* For example:
* { "messages" : [
* { "event" : "sms",
* "messageBody" : "Hello",
* "phoneNumber" : "2021234567",
* "messageDate" : "1518846484880",
* "messageType" : "2",
* "threadID" : "132"
* },
* { ... },
* ...
* ]
* }
* { "event" : 1, // 32-bit field containing a bitwise-or of event flags
* // See constants declared in SMSHelper.Message for defined
* // values and explanations
* "body" : "Hello", // Text message body
* "address" : "2021234567", // Sending or receiving address of the message
* "date" : "1518846484880", // Timestamp of the message
* "type" : "2", // Compare with Android's
* // Telephony.TextBasedSmsColumns.MESSAGE_TYPE_*
* "thread_id" : "132" // Thread to which the message belongs
* "read" : true // Boolean representing whether a message is read or unread
* },
* { ... },
* ...
* ]
*/
#define PACKET_TYPE_SMS_MESSAGES QStringLiteral("kdeconnect.sms.messages")
......
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