From 1d838fb55fc7f4be8c96f8a02dfa9d1a82af2c05 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 29 Dec 2018 23:54:06 +0100 Subject: Implement XEP-0308: Last Message Correction --- src/base/QXmppMessage.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/base/QXmppMessage.cpp') 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 > &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); -- cgit v1.2.3