From 524a02debffd9552f0928b5804d7b51b045aa9d2 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Sun, 25 Sep 2022 14:12:51 +0200 Subject: Implement XEP-0272: Multiparty Jingle (Muji) stanza extensions (#457) Adds the presence extension and the extension of the Jingle IQ. https://xmpp.org/extensions/xep-0272.html --- src/base/QXmppPresence.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'src/base/QXmppPresence.cpp') diff --git a/src/base/QXmppPresence.cpp b/src/base/QXmppPresence.cpp index 54e44fb4..059bd642 100644 --- a/src/base/QXmppPresence.cpp +++ b/src/base/QXmppPresence.cpp @@ -1,10 +1,12 @@ // SPDX-FileCopyrightText: 2009 Manjeet Dahiya +// SPDX-FileCopyrightText: 2022 Melvin Keskin // // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppPresence.h" #include "QXmppConstants_p.h" +#include "QXmppJingleIq.h" #include "QXmppUtils.h" #include @@ -59,6 +61,10 @@ public: QByteArray photoHash; QXmppPresence::VCardUpdateType vCardUpdateType; + // XEP-0272: Multiparty Jingle (Muji) + bool isPreparingMujiSession = false; + QVector mujiContents; + // XEP-0319: Last User Interaction in Presence QDateTime lastUserInteraction; @@ -253,6 +259,54 @@ QStringList QXmppPresence::capabilityExt() const return d->capabilityExt; } +/// +/// Returns whether a \xep{0272, Multiparty Jingle (Muji)} session is being prepared. +/// +/// \return whether a Muji session is being prepared +/// +/// \since QXmpp 1.5 +/// +bool QXmppPresence::isPreparingMujiSession() const +{ + return d->isPreparingMujiSession; +} + +/// +/// Sets whether a \xep{0272, Multiparty Jingle (Muji)} session is being prepared. +/// +/// \param isPreparingMujiSession whether a Muji session is being prepared +/// +/// \since QXmpp 1.5 +/// +void QXmppPresence::setIsPreparingMujiSession(bool isPreparingMujiSession) +{ + d->isPreparingMujiSession = isPreparingMujiSession; +} + +/// +/// Returns \xep{0272, Multiparty Jingle (Muji)} contents. +/// +/// \return Muji contents +/// +/// \since QXmpp 1.5 +/// +QVector QXmppPresence::mujiContents() const +{ + return d->mujiContents; +} + +/// +/// Sets \xep{0272, Multiparty Jingle (Muji)} contents. +/// +/// \param mujiContents Muji contents +/// +/// \since QXmpp 1.5 +/// +void QXmppPresence::setMujiContents(const QVector &mujiContents) +{ + d->mujiContents = mujiContents; +} + /// Returns the MUC item. QXmppMucItem QXmppPresence::mucItem() const @@ -447,6 +501,19 @@ void QXmppPresence::parseExtension(const QDomElement &element, QXmppElementList d->vCardUpdateType = VCardUpdateValidPhoto; } } + // XEP-0272: Multiparty Jingle (Muji) + } else if (element.tagName() == QStringLiteral("muji") && element.namespaceURI() == ns_muji) { + if (!element.firstChildElement(QStringLiteral("preparing")).isNull()) { + d->isPreparingMujiSession = true; + } + + for (auto contentElement = element.firstChildElement(QStringLiteral("content")); + !contentElement.isNull(); + contentElement = contentElement.nextSiblingElement(QStringLiteral("content"))) { + QXmppJingleIq::Content content; + content.parse(contentElement); + d->mujiContents.append(content); + } // XEP-0319: Last User Interaction in Presence } else if (element.tagName() == QStringLiteral("idle") && element.namespaceURI() == ns_idle) { if (element.hasAttribute(QStringLiteral("since"))) { @@ -537,6 +604,22 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0272: Multiparty Jingle (Muji) + if (d->isPreparingMujiSession || !d->mujiContents.isEmpty()) { + xmlWriter->writeStartElement(QStringLiteral("muji")); + xmlWriter->writeDefaultNamespace(ns_muji); + + if (d->isPreparingMujiSession) { + xmlWriter->writeEmptyElement(QStringLiteral("preparing")); + } + + for (const auto &mujiContent : d->mujiContents) { + mujiContent.toXml(xmlWriter); + } + + xmlWriter->writeEndElement(); + } + // XEP-0319: Last User Interaction in Presence if (!d->lastUserInteraction.isNull() && d->lastUserInteraction.isValid()) { xmlWriter->writeStartElement(QStringLiteral("idle")); -- cgit v1.2.3