|
1 | 1 | // SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com> |
| 2 | +// SPDX-FileCopyrightText: 2022 Melvin Keskin <melvo@olomono.de> |
2 | 3 | // |
3 | 4 | // SPDX-License-Identifier: LGPL-2.1-or-later |
4 | 5 |
|
5 | 6 | #include "QXmppPresence.h" |
6 | 7 |
|
7 | 8 | #include "QXmppConstants_p.h" |
| 9 | +#include "QXmppJingleIq.h" |
8 | 10 | #include "QXmppUtils.h" |
9 | 11 |
|
10 | 12 | #include <QDateTime> |
@@ -59,6 +61,10 @@ class QXmppPresencePrivate : public QSharedData |
59 | 61 | QByteArray photoHash; |
60 | 62 | QXmppPresence::VCardUpdateType vCardUpdateType; |
61 | 63 |
|
| 64 | + // XEP-0272: Multiparty Jingle (Muji) |
| 65 | + bool isPreparingMujiSession = false; |
| 66 | + QVector<QXmppJingleIq::Content> mujiContents; |
| 67 | + |
62 | 68 | // XEP-0319: Last User Interaction in Presence |
63 | 69 | QDateTime lastUserInteraction; |
64 | 70 |
|
@@ -253,6 +259,54 @@ QStringList QXmppPresence::capabilityExt() const |
253 | 259 | return d->capabilityExt; |
254 | 260 | } |
255 | 261 |
|
| 262 | +/// |
| 263 | +/// Returns whether a \xep{0272, Multiparty Jingle (Muji)} session is being prepared. |
| 264 | +/// |
| 265 | +/// \return whether a Muji session is being prepared |
| 266 | +/// |
| 267 | +/// \since QXmpp 1.5 |
| 268 | +/// |
| 269 | +bool QXmppPresence::isPreparingMujiSession() const |
| 270 | +{ |
| 271 | + return d->isPreparingMujiSession; |
| 272 | +} |
| 273 | + |
| 274 | +/// |
| 275 | +/// Sets whether a \xep{0272, Multiparty Jingle (Muji)} session is being prepared. |
| 276 | +/// |
| 277 | +/// \param isPreparingMujiSession whether a Muji session is being prepared |
| 278 | +/// |
| 279 | +/// \since QXmpp 1.5 |
| 280 | +/// |
| 281 | +void QXmppPresence::setIsPreparingMujiSession(bool isPreparingMujiSession) |
| 282 | +{ |
| 283 | + d->isPreparingMujiSession = isPreparingMujiSession; |
| 284 | +} |
| 285 | + |
| 286 | +/// |
| 287 | +/// Returns \xep{0272, Multiparty Jingle (Muji)} contents. |
| 288 | +/// |
| 289 | +/// \return Muji contents |
| 290 | +/// |
| 291 | +/// \since QXmpp 1.5 |
| 292 | +/// |
| 293 | +QVector<QXmppJingleIq::Content> QXmppPresence::mujiContents() const |
| 294 | +{ |
| 295 | + return d->mujiContents; |
| 296 | +} |
| 297 | + |
| 298 | +/// |
| 299 | +/// Sets \xep{0272, Multiparty Jingle (Muji)} contents. |
| 300 | +/// |
| 301 | +/// \param mujiContents Muji contents |
| 302 | +/// |
| 303 | +/// \since QXmpp 1.5 |
| 304 | +/// |
| 305 | +void QXmppPresence::setMujiContents(const QVector<QXmppJingleIq::Content> &mujiContents) |
| 306 | +{ |
| 307 | + d->mujiContents = mujiContents; |
| 308 | +} |
| 309 | + |
256 | 310 | /// Returns the MUC item. |
257 | 311 |
|
258 | 312 | QXmppMucItem QXmppPresence::mucItem() const |
@@ -447,6 +501,19 @@ void QXmppPresence::parseExtension(const QDomElement &element, QXmppElementList |
447 | 501 | d->vCardUpdateType = VCardUpdateValidPhoto; |
448 | 502 | } |
449 | 503 | } |
| 504 | + // XEP-0272: Multiparty Jingle (Muji) |
| 505 | + } else if (element.tagName() == QStringLiteral("muji") && element.namespaceURI() == ns_muji) { |
| 506 | + if (!element.firstChildElement(QStringLiteral("preparing")).isNull()) { |
| 507 | + d->isPreparingMujiSession = true; |
| 508 | + } |
| 509 | + |
| 510 | + for (auto contentElement = element.firstChildElement(QStringLiteral("content")); |
| 511 | + !contentElement.isNull(); |
| 512 | + contentElement = contentElement.nextSiblingElement(QStringLiteral("content"))) { |
| 513 | + QXmppJingleIq::Content content; |
| 514 | + content.parse(contentElement); |
| 515 | + d->mujiContents.append(content); |
| 516 | + } |
450 | 517 | // XEP-0319: Last User Interaction in Presence |
451 | 518 | } else if (element.tagName() == QStringLiteral("idle") && element.namespaceURI() == ns_idle) { |
452 | 519 | if (element.hasAttribute(QStringLiteral("since"))) { |
@@ -537,6 +604,22 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const |
537 | 604 | xmlWriter->writeEndElement(); |
538 | 605 | } |
539 | 606 |
|
| 607 | + // XEP-0272: Multiparty Jingle (Muji) |
| 608 | + if (d->isPreparingMujiSession || !d->mujiContents.isEmpty()) { |
| 609 | + xmlWriter->writeStartElement(QStringLiteral("muji")); |
| 610 | + xmlWriter->writeDefaultNamespace(ns_muji); |
| 611 | + |
| 612 | + if (d->isPreparingMujiSession) { |
| 613 | + xmlWriter->writeEmptyElement(QStringLiteral("preparing")); |
| 614 | + } |
| 615 | + |
| 616 | + for (const auto &mujiContent : d->mujiContents) { |
| 617 | + mujiContent.toXml(xmlWriter); |
| 618 | + } |
| 619 | + |
| 620 | + xmlWriter->writeEndElement(); |
| 621 | + } |
| 622 | + |
540 | 623 | // XEP-0319: Last User Interaction in Presence |
541 | 624 | if (!d->lastUserInteraction.isNull() && d->lastUserInteraction.isValid()) { |
542 | 625 | xmlWriter->writeStartElement(QStringLiteral("idle")); |
|
0 commit comments