aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2018-12-29 23:54:06 +0100
committerJeremy Lainé <jeremy.laine@m4x.org>2018-12-30 13:50:27 +0100
commit1d838fb55fc7f4be8c96f8a02dfa9d1a82af2c05 (patch)
treec7ee7fb6957a724728d4db8b2aa601da32ce743e
parentfc389736df1107245ca91ecbe0bca0526a42288a (diff)
downloadqxmpp-1d838fb55fc7f4be8c96f8a02dfa9d1a82af2c05.tar.gz
Implement XEP-0308: Last Message Correction
-rw-r--r--src/base/QXmppConstants.cpp2
-rw-r--r--src/base/QXmppConstants_p.h2
-rw-r--r--src/base/QXmppMessage.cpp34
-rw-r--r--src/base/QXmppMessage.h4
-rw-r--r--tests/qxmppmessage/tst_qxmppmessage.cpp18
5 files changed, 60 insertions, 0 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index 03260018..3254dd61 100644
--- a/src/base/QXmppConstants.cpp
+++ b/src/base/QXmppConstants.cpp
@@ -122,6 +122,8 @@ const char* ns_conference = "jabber:x:conference";
const char* ns_carbons = "urn:xmpp:carbons:2";
// XEP-0297: Stanza Forwarding
const char* ns_forwarding = "urn:xmpp:forward:0";
+// XEP-0308: Last Message Correction
+const char* ns_message_correct = "urn:xmpp:message-correct:0";
// XEP-0313: Message Archive Management
const char* ns_mam = "urn:xmpp:mam:1";
// XEP-0333: Chat Markers
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index 8846145c..17495b33 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -134,6 +134,8 @@ extern const char* ns_conference;
extern const char* ns_carbons;
// XEP-0297: Stanza Forwarding
extern const char* ns_forwarding;
+// XEP-0308: Last Message Correction
+extern const char* ns_message_correct;
// XEP-0313: Message Archive Management
extern const char* ns_mam;
// XEP-0333: Char Markers
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index 3c62bd42..24a5d4eb 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -99,6 +99,9 @@ public:
// XEP-0066: Out of Band Data
QString outOfBandUrl;
+
+ // XEP-0308: Last Message Correction
+ QString replaceId;
};
/// Constructs a QXmppMessage.
@@ -377,6 +380,7 @@ namespace
<< qMakePair(QString("thread"), QString())
<< qMakePair(QString("html"), QString())
<< qMakePair(QString("received"), QString(ns_message_receipts))
+ << qMakePair(QString("replace"), QString(ns_message_correct))
<< qMakePair(QString("request"), QString())
<< qMakePair(QString("delay"), QString())
<< qMakePair(QString("attention"), QString())
@@ -492,6 +496,23 @@ void QXmppMessage::setOutOfBandUrl(const QString &url)
d->outOfBandUrl = url;
}
+/// Returns the message id to replace with this message as used in XEP-0308:
+/// Last Message Correction. If the returned string is empty, this message is
+/// not replacing another.
+
+QString QXmppMessage::replaceId() const
+{
+ return d->replaceId;
+}
+
+/// Sets the message id to replace with this message as in XEP-0308: Last
+/// Message Correction.
+
+void QXmppMessage::setReplaceId(const QString &replaceId)
+{
+ d->replaceId = replaceId;
+}
+
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
@@ -597,6 +618,11 @@ void QXmppMessage::parse(const QDomElement &element)
if (!privateElement.isNull())
d->privatemsg = true;
+ // XEP-0308: Last Message Correction
+ QDomElement replaceElement = element.firstChildElement("replace");
+ if (!replaceElement.isNull() && replaceElement.namespaceURI() == ns_message_correct)
+ d->replaceId = replaceElement.attribute("id");
+
const QList<QPair<QString, QString> > &knownElems = knownMessageSubelems();
QXmppElementList extensions;
@@ -757,6 +783,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
+ // XEP-0308: Last Message Correction
+ if (!d->replaceId.isEmpty()) {
+ xmlWriter->writeStartElement("replace");
+ xmlWriter->writeAttribute("xmlns", ns_message_correct);
+ xmlWriter->writeAttribute("id", d->replaceId);
+ xmlWriter->writeEndElement();
+ }
+
// other extensions
QXmppStanza::extensionsToXml(xmlWriter);
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index 4ecd0d19..be5d2885 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -139,6 +139,10 @@ public:
QString outOfBandUrl() const;
void setOutOfBandUrl(const QString&);
+ // XEP-0308: Last Message Correction
+ QString replaceId() const;
+ void setReplaceId(const QString&);
+
/// \cond
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp
index 25c110c6..6b39e8b0 100644
--- a/tests/qxmppmessage/tst_qxmppmessage.cpp
+++ b/tests/qxmppmessage/tst_qxmppmessage.cpp
@@ -47,6 +47,7 @@ private slots:
void testChatMarkers();
void testPrivateMessage();
void testOutOfBandUrl();
+ void testMessageCorrect();
};
void tst_QXmppMessage::testBasic_data()
@@ -597,5 +598,22 @@ void tst_QXmppMessage::testOutOfBandUrl()
serializePacket(oobMessage, oobXml);
}
+void tst_QXmppMessage::testMessageCorrect()
+{
+ const QByteArray xml(
+ "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">"
+ "<body>This is the corrected version.</body>"
+ "<replace xmlns=\"urn:xmpp:message-correct:0\" id=\"badmessage\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.replaceId(), QString("badmessage"));
+ serializePacket(message, xml);
+
+ message.setReplaceId("someotherid");
+ QCOMPARE(message.replaceId(), QString("someotherid"));
+}
+
QTEST_MAIN(tst_QXmppMessage)
#include "tst_qxmppmessage.moc"