diff options
| author | Linus Jahn <lnj@kaidan.im> | 2019-04-27 21:37:31 +0100 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2019-09-06 18:04:40 +0200 |
| commit | 8ab56c2cf1ff490b78def3f9799d4b8a99965d47 (patch) | |
| tree | 3b363feee85fd10a59b684c3e9067f1f1cde3eb4 | |
| parent | 499b6567a9b3f9838a0d0f082d8baabd05414ff9 (diff) | |
| download | qxmpp-8ab56c2cf1ff490b78def3f9799d4b8a99965d47.tar.gz | |
Implement XEP-0367: Message Attaching
This adds parsing and serialization for XEP-0367: Message Attaching in
version 0.3.0.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | doc/xep.doc | 1 | ||||
| -rw-r--r-- | src/base/QXmppConstants.cpp | 2 | ||||
| -rw-r--r-- | src/base/QXmppConstants_p.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppMessage.cpp | 33 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 15 | ||||
| -rw-r--r-- | tests/qxmppmessage/tst_qxmppmessage.cpp | 18 |
7 files changed, 65 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 147027e1..5b9b7a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ QXmpp 1.0.1 (UNRELEASED) New features: - Add support for SCRAM-SHA-1 and SCRAM-SHA-256 (#183, @jlaine) + - Add XEP-0367: Message Attaching (v0.3.0) (#196, @lnjX) - Add XEP-0382: Spoiler messages (v0.2.0) (#195, @lnjX) QXmpp 1.0.0 (Jan 8, 2019) diff --git a/doc/xep.doc b/doc/xep.doc index 8666277f..3daf0936 100644 --- a/doc/xep.doc +++ b/doc/xep.doc @@ -41,6 +41,7 @@ Complete: - XEP-0313: Message Archive Management - XEP-0319: Last User Interaction in Presence - XEP-0352: Client State Indication +- XEP-0367: Message Attaching (v0.3.0) - XEP-0382: Spoiler messages (v0.2.0) Ongoing: diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index 8c3295d5..05d29f55 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -134,6 +134,8 @@ const char* ns_chat_markers = "urn:xmpp:chat-markers:0"; const char* ns_csi = "urn:xmpp:csi:0"; // XEP-0363: HTTP File Upload const char* ns_http_upload = "urn:xmpp:http:upload:0"; +// XEP-0367: Message Attaching +const char* ns_message_attaching = "urn:xmpp:message-attaching:1"; // XEP-0369: Mediated Information eXchange (MIX) const char* ns_mix = "urn:xmpp:mix:core:1"; const char* ns_mix_create_channel = "urn:xmpp:mix:core:1#create-channel"; diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h index 35d92247..4f6eca53 100644 --- a/src/base/QXmppConstants_p.h +++ b/src/base/QXmppConstants_p.h @@ -146,6 +146,8 @@ extern const char* ns_chat_markers; extern const char* ns_csi; // XEP-0363: HTTP File Upload extern const char* ns_http_upload; +// XEP-0367: Message Attaching +extern const char* ns_message_attaching; // XEP-0369: Mediated Information eXchange (MIX) extern const char* ns_mix; extern const char* ns_mix_create_channel; diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index dae2308b..af4b2a6f 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -103,6 +103,9 @@ public: // XEP-0308: Last Message Correction QString replaceId; + // XEP-0367: Message Attaching + QString attachId; + // XEP-0369: Mediated Information eXchange (MIX) QString mixUserJid; QString mixUserNick; @@ -521,6 +524,25 @@ void QXmppMessage::setReplaceId(const QString &replaceId) d->replaceId = replaceId; } +/// Returns the message id this message is linked/attached to. See XEP-0367: +/// Message Attaching for details. + +QString QXmppMessage::attachId() const +{ + return d->attachId; +} + +/// Sets the id of the attached message as in XEP-0367: Message Attaching. This +/// can be used for a "reply to" or "reaction" function. +/// +/// The used message id depends on the message context, see the Business rules +/// section of the XEP for details about when to use which id. + +void QXmppMessage::setAttachId(const QString &attachId) +{ + d->attachId = attachId; +} + /// Returns the actual JID of a MIX channel participant. QString QXmppMessage::mixUserJid() const @@ -736,6 +758,9 @@ void QXmppMessage::parse(const QDomElement &element) else { extensions << QXmppElement(xElement); } + // XEP-0367: Message Attaching + } else if (xElement.tagName() == "attach-to" && xElement.namespaceURI() == ns_message_attaching) { + d->attachId = xElement.attribute("id"); // XEP-0369: Mediated Information eXchange (MIX) } else if (xElement.tagName() == "mix" && xElement.namespaceURI() == ns_mix) { d->mixUserJid = xElement.firstChildElement("jid").text(); @@ -881,6 +906,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0367: Message Attaching + if (!d->attachId.isEmpty()) { + xmlWriter->writeStartElement("attach-to"); + xmlWriter->writeAttribute("xmlns", ns_message_attaching); + xmlWriter->writeAttribute("id", d->attachId); + xmlWriter->writeEndElement(); + } + // XEP-0369: Mediated Information eXchange (MIX) if (!d->mixUserJid.isEmpty() || !d->mixUserNick.isEmpty()) { xmlWriter->writeStartElement("mix"); diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index 0101e211..330c70fe 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -21,7 +21,6 @@ * */ - #ifndef QXMPPMESSAGE_H #define QXMPPMESSAGE_H @@ -33,7 +32,6 @@ class QXmppMessagePrivate; /// \brief The QXmppMessage class represents an XMPP message. /// /// \ingroup Stanzas -/// class QXMPP_EXPORT QXmppMessage : public QXmppStanza { @@ -48,8 +46,8 @@ public: Headline }; - /// This enum describes a chat state as defined by - /// XEP-0085 : Chat State Notifications. + /// This enum describes a chat state as defined by XEP-0085: Chat State + /// Notifications. enum State { None = 0, ///< The message does not contain any chat state information. @@ -60,8 +58,7 @@ public: Paused ///< User had been composing but now has stopped. }; - /// This enum describes a chat marker as defined by - /// XEP-0333 : Char Markers + /// This enum describes a chat marker as defined by XEP-0333: Chat Markers. enum Marker { NoMarker = 0, Received, @@ -116,7 +113,7 @@ public: QString xhtml() const; void setXhtml(const QString &xhtml); - // XEP-0333 + // XEP-0333: Chat Markers bool isMarkable() const; void setMarkable(const bool); @@ -143,6 +140,10 @@ public: QString replaceId() const; void setReplaceId(const QString&); + // XEP-0367: Message Attaching + QString attachId() const; + void setAttachId(const QString&); + // XEP-0369: Mediated Information eXchange (MIX) QString mixUserJid() const; void setMixUserJid(const QString&); diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp index 49666168..9441acef 100644 --- a/tests/qxmppmessage/tst_qxmppmessage.cpp +++ b/tests/qxmppmessage/tst_qxmppmessage.cpp @@ -48,6 +48,7 @@ private slots: void testPrivateMessage(); void testOutOfBandUrl(); void testMessageCorrect(); + void testMessageAttaching(); void testMix(); void testSpoiler(); }; @@ -618,6 +619,23 @@ void tst_QXmppMessage::testMessageCorrect() QCOMPARE(message.replaceId(), QString("someotherid")); } +void tst_QXmppMessage::testMessageAttaching() +{ + const QByteArray xml( + "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" + "<body>This is the corrected version.</body>" + "<attach-to xmlns=\"urn:xmpp:message-attaching:1\" id=\"SD24VCzSYQ\"/>" + "</message>"); + + QXmppMessage message; + parsePacket(message, xml); + QCOMPARE(message.attachId(), QString("SD24VCzSYQ")); + serializePacket(message, xml); + + message.setAttachId("someotherid"); + QCOMPARE(message.attachId(), QString("someotherid")); +} + void tst_QXmppMessage::testMix() { const QByteArray xml( |
