aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-04-05 12:48:58 +0200
committerLNJ <lnj@kaidan.im>2020-04-05 13:07:31 +0200
commit420fddae862b0f67e7d8fe712006525c0239154e (patch)
tree8293c6b0cda42f6cc4fd57b6b79de4bb316180ee /src/base
parent2197c188f21d563a192be711d13db7d0d1600681 (diff)
QXmppMessage: Add parent thread attribute from RFC6121
The 'parent' attribute for <thread/> element in messages has been introduced in RFC6121. This commit adds parsing and serialization for it, including unit tests.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppMessage.cpp37
-rw-r--r--src/base/QXmppMessage.h3
2 files changed, 37 insertions, 3 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index daf3e782..743e1dc6 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -107,6 +107,7 @@ public:
QString body;
QString subject;
QString thread;
+ QString parentThread;
// XEP-0071: XHTML-IM
QString xhtml;
@@ -412,6 +413,30 @@ void QXmppMessage::setThread(const QString &thread)
d->thread = thread;
}
+///
+/// Returns the optional parent thread of this message.
+///
+/// The possibility to create child threads was added in RFC6121.
+///
+/// \since QXmpp 1.3
+///
+QString QXmppMessage::parentThread() const
+{
+ return d->parentThread;
+}
+
+///
+/// Sets the optional parent thread of this message.
+///
+/// The possibility to create child threads was added in RFC6121.
+///
+/// \since QXmpp 1.3
+///
+void QXmppMessage::setParentThread(const QString &parent)
+{
+ d->parentThread = parent;
+}
+
/// Returns the message's XHTML body as defined by
/// \xep{0071}: XHTML-IM.
@@ -980,6 +1005,8 @@ void QXmppMessage::parse(const QDomElement &element)
d->subject = childElement.text();
} else if (childElement.tagName() == QStringLiteral("thread")) {
d->thread = childElement.text();
+ d->parentThread = childElement.attribute(QStringLiteral("parent"));
+
// parse message extensions
// XEP-0033: Extended Stanza Addressing and errors are parsed by QXmppStanza
} else if (!checkElement(childElement, QStringLiteral("addresses"), ns_extended_addressing) &&
@@ -1003,8 +1030,12 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
helperToXmlAddTextElement(xmlWriter, QStringLiteral("subject"), d->subject);
if (!d->body.isEmpty())
helperToXmlAddTextElement(xmlWriter, QStringLiteral("body"), d->body);
- if (!d->thread.isEmpty())
- helperToXmlAddTextElement(xmlWriter, QStringLiteral("thread"), d->thread);
+ if (!d->thread.isEmpty()) {
+ xmlWriter->writeStartElement(QStringLiteral("thread"));
+ helperToXmlAddAttribute(xmlWriter, QStringLiteral("parent"), d->parentThread);
+ xmlWriter->writeCharacters(d->thread);
+ xmlWriter->writeEndElement();
+ }
error().toXml(xmlWriter);
// chat states
@@ -1057,7 +1088,7 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
- // \xep{0224}: Attention
+ // XEP-0224: Attention
if (d->attentionRequested) {
xmlWriter->writeStartElement(QStringLiteral("attention"));
xmlWriter->writeDefaultNamespace(ns_attention);
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index 3d8e3ed8..3f311519 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -136,6 +136,9 @@ public:
QString thread() const;
void setThread(const QString &);
+ QString parentThread() const;
+ void setParentThread(const QString &);
+
QXmppMessage::Type type() const;
void setType(QXmppMessage::Type);