From a0095bc85041dc399ceb0e6bb8e06aaba8ac262e Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Sat, 5 Mar 2022 19:20:27 +0100 Subject: Message: Add end-to-end encryption fallback body --- src/base/QXmppMessage.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/base/QXmppMessage.h | 3 +++ 2 files changed, 43 insertions(+) (limited to 'src/base') diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index 41b654ed..e493cf17 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -88,6 +88,7 @@ public: QXmppMessagePrivate(); QString body; + QString e2eeFallbackBody; QString subject; QString thread; QString parentThread; @@ -236,6 +237,36 @@ void QXmppMessage::setBody(const QString &body) d->body = body; } +/// +/// Returns a body that is unlike the normal body not encrypted. +/// +/// It can be presented to users if the message could not be decrypted (e.g., +/// because their clients do not support the used end-to-end encryption). +/// +/// \return the end-to-end encryption fallback body +/// +/// \since QXmpp 1.5 +/// +QString QXmppMessage::e2eeFallbackBody() const +{ + return d->e2eeFallbackBody; +} + +/// +/// Sets a body that is unlike the normal body not encrypted. +/// +/// It can be presented to users if the message could not be decrypted (e.g., +/// because their clients do not support the used end-to-end encryption). +/// +/// \param fallbackBody end-to-end encryption fallback body +/// +/// \since QXmpp 1.5 +/// +void QXmppMessage::setE2eeFallbackBody(const QString &fallbackBody) +{ + d->e2eeFallbackBody = fallbackBody; +} + /// Returns the message's type. QXmppMessage::Type QXmppMessage::type() const @@ -1239,6 +1270,11 @@ void QXmppMessage::toXml(QXmlStreamWriter *writer, QXmpp::SceMode sceMode) const bool QXmppMessage::parseExtension(const QDomElement &element, QXmpp::SceMode sceMode) { if (sceMode & QXmpp::ScePublic) { + if (sceMode == QXmpp::ScePublic && element.tagName() == QStringLiteral("body")) { + d->e2eeFallbackBody = element.text(); + return true; + } + // XEP-0280: Message Carbons if (checkElement(element, QStringLiteral("private"), ns_carbons)) { d->privatemsg = true; @@ -1445,6 +1481,10 @@ bool QXmppMessage::parseExtension(const QDomElement &element, QXmpp::SceMode sce void QXmppMessage::serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode sceMode, const QString &baseNamespace) const { if (sceMode & QXmpp::ScePublic) { + if (sceMode == QXmpp::ScePublic && !d->e2eeFallbackBody.isEmpty()) { + writer->writeTextElement(QStringLiteral("body"), d->e2eeFallbackBody); + } + // XEP-0280: Message Carbons if (d->privatemsg) { writer->writeStartElement(QStringLiteral("private")); diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index bdd47800..b7db3eab 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -108,6 +108,9 @@ public: QString body() const; void setBody(const QString &); + QString e2eeFallbackBody() const; + void setE2eeFallbackBody(const QString &fallbackBody); + QString subject() const; void setSubject(const QString &); -- cgit v1.2.3