aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppRosterIq.cpp
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-01-05 14:06:09 +0100
committerJeremy Lainé <jeremy.laine@m4x.org>2019-05-01 10:24:51 +0200
commit740a085ef7ac707e2cc2217edf02e296c3f7692e (patch)
tree243cf37fccb12b20092993aa20f536b067db2064 /src/base/QXmppRosterIq.cpp
parentc0412e29545c109e3473b38dbeba4e17514a7b05 (diff)
downloadqxmpp-740a085ef7ac707e2cc2217edf02e296c3f7692e.tar.gz
Implement MIX-PAM XEP-0405: Roster IQ extension
This adds the MIX extensions for roster queries as defined in XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements in version 0.4.0. https://xmpp.org/extensions/xep-0405.html#mix-roster-capability-sharing
Diffstat (limited to 'src/base/QXmppRosterIq.cpp')
-rw-r--r--src/base/QXmppRosterIq.cpp88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/base/QXmppRosterIq.cpp b/src/base/QXmppRosterIq.cpp
index 6e87909a..3dfb32b4 100644
--- a/src/base/QXmppRosterIq.cpp
+++ b/src/base/QXmppRosterIq.cpp
@@ -35,6 +35,8 @@ public:
QList<QXmppRosterIq::Item> items;
// XEP-0237 Roster Versioning
QString version;
+ // XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+ bool mixAnnotate = false;
};
QXmppRosterIq::QXmppRosterIq()
@@ -82,6 +84,21 @@ void QXmppRosterIq::setVersion(const QString &version)
d->version = version;
}
+/// Whether to annotate which items are MIX channels.
+
+bool QXmppRosterIq::mixAnnotate() const
+{
+ return d->mixAnnotate;
+}
+
+/// Sets whether to include which roster items are MIX channels. This MUST only
+/// be enabled in get requests.
+
+void QXmppRosterIq::setMixAnnotate(bool mixAnnotate)
+{
+ d->mixAnnotate = mixAnnotate;
+}
+
/// \cond
bool QXmppRosterIq::isRosterIq(const QDomElement &element)
{
@@ -91,16 +108,20 @@ bool QXmppRosterIq::isRosterIq(const QDomElement &element)
void QXmppRosterIq::parseElementFromChild(const QDomElement &element)
{
QDomElement queryElement = element.firstChildElement("query");
- QDomElement itemElement = queryElement.firstChildElement("item");
-
setVersion(queryElement.attribute("ver"));
+
+ QDomElement itemElement = queryElement.firstChildElement("item");
while(!itemElement.isNull())
{
QXmppRosterIq::Item item;
item.parse(itemElement);
d->items.append(item);
- itemElement = itemElement.nextSiblingElement();
+ itemElement = itemElement.nextSiblingElement("item");
}
+
+ QDomElement annotateElement = queryElement.firstChildElement("annotate");
+ setMixAnnotate(!annotateElement.isNull() && annotateElement.namespaceURI()
+ == ns_mix_roster);
}
void QXmppRosterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
@@ -109,9 +130,17 @@ void QXmppRosterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeAttribute( "xmlns", ns_roster);
// XEP-0237 roster versioning - If the server does not advertise support for roster versioning, the client MUST NOT include the 'ver' attribute.
- if(!version().isEmpty())
- writer->writeAttribute( "ver", version());
- for(int i = 0; i < d->items.count(); ++i)
+ if (!version().isEmpty())
+ writer->writeAttribute("ver", version());
+
+ // XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+ if (d->mixAnnotate) {
+ writer->writeStartElement("annotate");
+ writer->writeAttribute("xmlns", ns_mix_roster);
+ writer->writeEndElement();
+ }
+
+ for (int i = 0; i < d->items.count(); ++i)
d->items.at(i).toXml(writer);
writer->writeEndElement();
}
@@ -126,6 +155,9 @@ public:
// can be subscribe/unsubscribe (attribute "ask")
QString subscriptionStatus;
QSet<QString> groups;
+ // XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+ bool isMixChannel = false;
+ QString mixParticipantId;
};
/// Constructs a new roster entry.
@@ -292,6 +324,34 @@ void QXmppRosterIq::Item::setSubscriptionTypeFromStr(const QString& type)
qWarning("QXmppRosterIq::Item::setTypeFromStr(): invalid type");
}
+/// Returns whether this is a MIX channel.
+
+bool QXmppRosterIq::Item::isMixChannel() const
+{
+ return d->isMixChannel;
+}
+
+/// Sets whether this is a MIX channel.
+
+void QXmppRosterIq::Item::setIsMixChannel(bool isMixChannel)
+{
+ d->isMixChannel = isMixChannel;
+}
+
+/// Returns the participant id for this MIX channel.
+
+QString QXmppRosterIq::Item::mixParticipantId() const
+{
+ return d->mixParticipantId;
+}
+
+/// Sets the participant id for this MIX channel.
+
+void QXmppRosterIq::Item::setMixParticipantId(const QString& participantId)
+{
+ d->mixParticipantId = participantId;
+}
+
/// \cond
void QXmppRosterIq::Item::parse(const QDomElement &element)
{
@@ -306,6 +366,13 @@ void QXmppRosterIq::Item::parse(const QDomElement &element)
d->groups << groupElement.text();
groupElement = groupElement.nextSiblingElement("group");
}
+
+ // XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+ QDomElement channelElement = element.firstChildElement("channel");
+ if (!channelElement.isNull() && channelElement.namespaceURI() == ns_mix_roster) {
+ d->isMixChannel = true;
+ d->mixParticipantId = channelElement.attribute("participant-id");
+ }
}
void QXmppRosterIq::Item::toXml(QXmlStreamWriter *writer) const
@@ -322,6 +389,15 @@ void QXmppRosterIq::Item::toXml(QXmlStreamWriter *writer) const
helperToXmlAddTextElement(writer,"group", *i);
++i;
}
+
+ // XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+ if (d->isMixChannel) {
+ writer->writeStartElement("channel");
+ writer->writeAttribute("xmlns", ns_mix_roster);
+ helperToXmlAddAttribute(writer, "participant-id", d->mixParticipantId);
+ writer->writeEndElement();
+ }
+
writer->writeEndElement();
}
/// \endcond