diff --git a/interfaces/conversationmessage.h b/interfaces/conversationmessage.h --- a/interfaces/conversationmessage.h +++ b/interfaces/conversationmessage.h @@ -32,6 +32,7 @@ : 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,23 +54,34 @@ }; 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 * * @param args mapping of field names to values as might be contained in a network packet containing a message */ 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); ~ConversationMessage(); 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 @@ 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 */ diff --git a/interfaces/conversationmessage.cpp b/interfaces/conversationmessage.cpp --- a/interfaces/conversationmessage.cpp +++ b/interfaces/conversationmessage.cpp @@ -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 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 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::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 @@ QVariantMap ConversationMessage::toVariant() const { return { + {"event", m_eventField}, {"body", m_body}, {"address", m_address}, {"date", m_date}, @@ -93,14 +100,21 @@ 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 @@ qint32 uID; argument.beginStructure(); + argument >> event; argument >> body; argument >> address; argument >> date; @@ -119,7 +134,7 @@ 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; } diff --git a/plugins/sms/smsplugin.h b/plugins/sms/smsplugin.h --- a/plugins/sms/smsplugin.h +++ b/plugins/sms/smsplugin.h @@ -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") diff --git a/plugins/sms/smsplugin.cpp b/plugins/sms/smsplugin.cpp --- a/plugins/sms/smsplugin.cpp +++ b/plugins/sms/smsplugin.cpp @@ -102,8 +102,10 @@ 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;