diff options
| author | Linus Jahn <lnj@kaidan.im> | 2019-09-04 20:26:48 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2019-09-08 13:31:40 +0200 |
| commit | 35256b7d95374717905f8ac8d4d524c4b691389e (patch) | |
| tree | 55074a75a34eb4a2eaa051e8afe7b4779ab50431 /src/base/QXmppMessage.cpp | |
| parent | e7394afc6730b16673f4173fcbc55d54a810a80b (diff) | |
Implement XEP-0334: Message Processing Hints
This implements parsing and serialization of XEP-0334: Message
Processing Hints in version 0.3.0.
https://xmpp.org/extensions/xep-0334.html
Co-authored-by: Juan Aragon <jaaragont@gmail.com>
Co-authored-by: Sam Truscott <sam@wumpus.co.uk>
Diffstat (limited to 'src/base/QXmppMessage.cpp')
| -rw-r--r-- | src/base/QXmppMessage.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index 54ef4cd6..9806edf0 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -64,6 +64,13 @@ static const QStringList ENCRYPTION_NAMESPACES = { ns_omemo }; +static const QStringList HINT_TYPES = { + QStringLiteral("no-permanent-store"), + QStringLiteral("no-store"), + QStringLiteral("no-copy"), + QStringLiteral("store") +}; + static const QStringList ENCRYPTION_NAMES = { QString(), QString(), @@ -121,6 +128,9 @@ public: // XEP-0308: Last Message Correction QString replaceId; + // XEP-0334: Message Processing Hints + quint8 hints; + // XEP-0367: Message Attaching QString attachId; @@ -161,6 +171,8 @@ QXmppMessage::QXmppMessage(const QString& from, const QString& to, const d->marker = NoMarker; d->privatemsg = false; + + d->hints = 0; } /// Constructs a copy of \a other. @@ -546,6 +558,38 @@ void QXmppMessage::setReplaceId(const QString &replaceId) d->replaceId = replaceId; } +/// Returns true if the message contains the hint passed, as defined in +/// XEP-0334: Message Processing Hints + +bool QXmppMessage::hasHint(const Hint hint) const +{ + return d->hints & hint; +} + +/// Adds a hint to the message, as defined in XEP-0334: Message Processing +/// Hints + +void QXmppMessage::addHint(const Hint hint) +{ + d->hints |= hint; +} + +/// Removes a hint from the message, as defined in XEP-0334: Message Processing +/// Hints + +void QXmppMessage::removeHint(const Hint hint) +{ + d->hints &= ~hint; +} + +/// Removes all hints from the message, as defined in XEP-0334: Message +/// Processing Hints + +void QXmppMessage::removeAllHints() +{ + d->hints = 0; +} + /// Returns the message id this message is linked/attached to. See XEP-0367: /// Message Attaching for details. @@ -848,6 +892,9 @@ void QXmppMessage::parse(const QDomElement &element) else { extensions << QXmppElement(xElement); } + // XEP-0334: Message Processing Hints + } else if (xElement.namespaceURI() == ns_message_processing_hints && HINT_TYPES.contains(xElement.tagName())) { + addHint(Hint(1 << HINT_TYPES.indexOf(xElement.tagName()))); // XEP-0367: Message Attaching } else if (xElement.tagName() == "attach-to" && xElement.namespaceURI() == ns_message_attaching) { d->attachId = xElement.attribute("id"); @@ -1000,6 +1047,15 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0334: Message Processing Hints + for (quint8 i = 0; i < HINT_TYPES.size(); i++) { + if (hasHint(Hint(1 << i))) { + xmlWriter->writeStartElement(HINT_TYPES.at(i)); + xmlWriter->writeAttribute("xmlns", ns_message_processing_hints); + xmlWriter->writeEndElement(); + } + } + // XEP-0367: Message Attaching if (!d->attachId.isEmpty()) { xmlWriter->writeStartElement("attach-to"); |
