From e50f3d34dfa39ed0016386bf731fe2df3ff5036f Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Wed, 3 Jul 2024 23:23:02 +0300 Subject: [PATCH] Added XEP-0424: message retraction support --- src/xmpp/xmpp-im/types.cpp | 18 ++++++++++++++++++ src/xmpp/xmpp-im/xmpp_message.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/xmpp/xmpp-im/types.cpp b/src/xmpp/xmpp-im/types.cpp index 497af45c..db99cd2d 100644 --- a/src/xmpp/xmpp-im/types.cpp +++ b/src/xmpp/xmpp-im/types.cpp @@ -752,6 +752,7 @@ class Message::Private : public QSharedData { Message::StanzaId stanzaId; // XEP-0359 QList references; // XEP-0385 and XEP-0372 Message::Reactions reactions; // XEP-0444 + QString retraction; // XEP-0424 }; #define MessageD() (d ? d : (d = new Private)) @@ -1103,6 +1104,10 @@ void Message::setReactions(const XMPP::Message::Reactions &reactions) { MessageD XMPP::Message::Reactions Message::reactions() const { return d ? d->reactions : Reactions {}; } +void Message::setRetraction(const QString &retractedMessageId) { MessageD()->retraction = retractedMessageId; } + +QString Message::retraction() const { return d ? d->retraction : QString {}; } + QString Message::invite() const { return d ? d->invite : QString(); } void Message::setInvite(const QString &s) { MessageD()->invite = s; } @@ -1452,6 +1457,14 @@ Stanza Message::toStanza(Stream *stream) const s.appendChild(s.createElement(QStringLiteral("urn:xmpp:hints"), QStringLiteral("store"))); } + // XEP-0424 + if (!d->retraction.isEmpty()) { + auto e = s.createElement("urn:xmpp:message-retract:1", QStringLiteral("retract")); + e.setAttribute(QLatin1String("id"), d->retraction); + s.appendChild(e); + s.appendChild(s.createElement(QStringLiteral("urn:xmpp:hints"), QStringLiteral("store"))); + } + return s; } @@ -1820,6 +1833,11 @@ bool Message::fromStanza(const Stanza &s, bool useTimeZoneOffset, int timeZoneOf } } + // XEP-0424 message retraction + d->retraction = childElementsByTagNameNS(root, "urn:xmpp:message-retract:1", QStringLiteral("retract")) + .item(0) + .toElement() + .attribute(QLatin1String("id")); return true; } diff --git a/src/xmpp/xmpp-im/xmpp_message.h b/src/xmpp/xmpp-im/xmpp_message.h index 61b13af1..45b5965d 100644 --- a/src/xmpp/xmpp-im/xmpp_message.h +++ b/src/xmpp/xmpp-im/xmpp_message.h @@ -230,6 +230,9 @@ class Message { void setReactions(const Reactions &reactions); Reactions reactions() const; + void setRetraction(const QString &retractedMessageId); + QString retraction() const; + // Obsolete invitation QString invite() const; void setInvite(const QString &s);