Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement XEP-0428: Fallback Indication #253

Merged
merged 1 commit into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/xep.doc
Expand Up @@ -47,6 +47,7 @@ Complete:
- XEP-0367: Message Attaching (v0.3.0)
- XEP-0380: Explicit Message Encryption (v0.3.0)
- XEP-0382: Spoiler messages (v0.2.0)
- XEP-0428: Fallback Indication (v0.1.0)

Ongoing:
- XEP-0009: Jabber-RPC (API is not finalized yet)
Expand Down
2 changes: 2 additions & 0 deletions src/base/QXmppConstants.cpp
Expand Up @@ -166,3 +166,5 @@ const char* ns_omemo = "eu.siacs.conversations.axolotl";
const char* ns_mix_pam = "urn:xmpp:mix:pam:1";
const char* ns_mix_roster = "urn:xmpp:mix:roster:0";
const char* ns_mix_presence = "urn:xmpp:presence:0";
// XEP-0428: Fallback Indication
const char* ns_fallback_indication = "urn:xmpp:fallback:0";
2 changes: 2 additions & 0 deletions src/base/QXmppConstants_p.h
Expand Up @@ -178,5 +178,7 @@ extern const char* ns_omemo;
extern const char* ns_mix_pam;
extern const char* ns_mix_roster;
extern const char* ns_mix_presence;
// XEP-0428: Fallback Indication
extern const char* ns_fallback_indication;

#endif // QXMPPCONSTANTS_H
44 changes: 43 additions & 1 deletion src/base/QXmppMessage.cpp
Expand Up @@ -155,6 +155,9 @@ class QXmppMessagePrivate : public QSharedData
// XEP-0382: Spoiler messages
bool isSpoiler;
QString spoilerHint;

// XEP-0428: Fallback Indication
bool isFallback;
};

QXmppMessagePrivate::QXmppMessagePrivate()
Expand All @@ -167,7 +170,8 @@ QXmppMessagePrivate::QXmppMessagePrivate()
marker(QXmppMessage::NoMarker),
privatemsg(false),
hints(0),
isSpoiler(false)
isSpoiler(false),
isFallback(false)
{
}

Expand Down Expand Up @@ -796,6 +800,34 @@ void QXmppMessage::setSpoilerHint(const QString &spoilerHint)
d->isSpoiler = true;
}

///
/// Sets whether this message is only a fallback according to \xep{0428}:
/// Fallback Indication.
///
/// This is useful for clients not supporting end-to-end encryption to indicate
/// that the message body does not contain the intended text of the author.
///
/// \since QXmpp 1.3
///
bool QXmppMessage::isFallback() const
{
return d->isFallback;
}

///
/// Sets whether this message is only a fallback according to \xep{0428}:
/// Fallback Indication.
///
/// This is useful for clients not supporting end-to-end encryption to indicate
/// that the message body does not contain the intended text of the author.
///
/// \since QXmpp 1.3
///
void QXmppMessage::setIsFallback(bool isFallback)
{
d->isFallback = isFallback;
}

/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
Expand Down Expand Up @@ -999,6 +1031,13 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}

// XEP-0428: Fallback Indication
if (d->isFallback) {
xmlWriter->writeStartElement(QStringLiteral("fallback"));
xmlWriter->writeDefaultNamespace(ns_fallback_indication);
xmlWriter->writeEndElement();
}

// other extensions
QXmppStanza::extensionsToXml(xmlWriter);

Expand Down Expand Up @@ -1093,6 +1132,9 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList &
} else if (checkElement(element, QStringLiteral("spoiler"), ns_spoiler)) {
d->isSpoiler = true;
d->spoilerHint = element.text();
} else if (checkElement(element, QStringLiteral("fallback"), ns_fallback_indication)) {
// XEP-0428: Fallback Indication
d->isFallback = true;
} else {
// other extensions
unknownExtensions << QXmppElement(element);
Expand Down
4 changes: 4 additions & 0 deletions src/base/QXmppMessage.h
Expand Up @@ -205,6 +205,10 @@ class QXMPP_EXPORT QXmppMessage : public QXmppStanza
QString spoilerHint() const;
void setSpoilerHint(const QString &);

// XEP-0428: Fallback Indication
bool isFallback() const;
void setIsFallback(bool isFallback);

/// \cond
void parse(const QDomElement &element) override;
void toXml(QXmlStreamWriter *writer) const override;
Expand Down
19 changes: 19 additions & 0 deletions tests/qxmppmessage/tst_qxmppmessage.cpp
Expand Up @@ -59,6 +59,7 @@ private slots:
void testSpoiler();
void testProcessingHints();
void testBobData();
void testFallbackIndication();
};

void tst_QXmppMessage::testBasic_data()
Expand Down Expand Up @@ -131,6 +132,7 @@ void tst_QXmppMessage::testBasic()
QVERIFY(!message.hasHint(QXmppMessage::NoCopy));
QVERIFY(!message.hasHint(QXmppMessage::Store));
QCOMPARE(message.bitsOfBinaryData(), QXmppBitsOfBinaryDataList());
QVERIFY(!message.isFallback());

message = QXmppMessage();
message.setTo(QStringLiteral("foo@example.com/QXmpp"));
Expand Down Expand Up @@ -966,5 +968,22 @@ void tst_QXmppMessage::testBobData()
QCOMPARE(constMessage.bitsOfBinaryData(), msg.bitsOfBinaryData());
}

void tst_QXmppMessage::testFallbackIndication()
{
const QByteArray xml = QByteArrayLiteral(
"<message type=\"chat\">"
"<fallback xmlns=\"urn:xmpp:fallback:0\"/>"
"</message>");

QXmppMessage message;
parsePacket(message, xml);
QVERIFY(message.isFallback());
serializePacket(message, xml);

QXmppMessage message2;
message2.setIsFallback(true);
serializePacket(message2, xml);
}

QTEST_MAIN(tst_QXmppMessage)
#include "tst_qxmppmessage.moc"