From 1654f24a1af4f96f2f1a06a2308bd05ad6f9c978 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 29 Sep 2021 15:45:52 +0200 Subject: PubSubManager: Add create node requests with config --- src/client/QXmppPubSubManager.cpp | 67 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'src/client/QXmppPubSubManager.cpp') diff --git a/src/client/QXmppPubSubManager.cpp b/src/client/QXmppPubSubManager.cpp index 08fe75e7..c4a9107f 100644 --- a/src/client/QXmppPubSubManager.cpp +++ b/src/client/QXmppPubSubManager.cpp @@ -233,6 +233,30 @@ auto QXmppPubSubManager::createNode(const QString &jid, const QString &nodeName) return client()->sendGenericIq(std::move(request)); } +/// +/// Creates an empty pubsub node with a custom configuration. +/// +/// Calling this before QXmppPubSubManager::publishItems is usually not +/// necessary when publishing to a node for the first time if the service +/// suppports the auto-create feature (Section 7.1.4 of \xep{0060}). +/// +/// \param jid Jabber ID of the entity hosting the pubsub service +/// \param nodeName the name of the node to be created +/// \param config The configuration for the node +/// \return +/// +auto QXmppPubSubManager::createNode(const QString &jid, const QString &nodeName, const QXmppPubSubNodeConfig &config) -> QFuture +{ + QXmppPubSubIq request; + request.setType(QXmppIq::Set); + request.setQueryType(QXmppPubSubIq<>::Create); + request.setQueryNode(nodeName); + request.setTo(jid); + request.setDataForm(config); + + return client()->sendGenericIq(std::move(request)); +} + /// /// Creates an instant pubsub node with the default configuration. /// @@ -255,6 +279,30 @@ QFuture QXmppPubSubManager::createInstant }); } +/// +/// Creates an instant pubsub node with a custom configuration. +/// +/// The pubsub service automatically generates a random node name. On success +/// it is returned via the QFuture. +/// +/// \param jid Jabber ID of the entity hosting the pubsub service +/// \param config The configuration for the node +/// \return +/// +auto QXmppPubSubManager::createInstantNode(const QString &jid, const QXmppPubSubNodeConfig &config) -> QFuture +{ + QXmppPubSubIq request; + request.setType(QXmppIq::Set); + request.setQueryType(QXmppPubSubIq<>::Create); + request.setTo(jid); + request.setDataForm(config); + + return chainIq(client()->sendIq(std::move(request)), this, + [](const QXmppPubSubIq<> &iq) -> InstantNodeResult { + return iq.queryNode(); + }); +} + /// /// Deletes a pubsub node. /// @@ -561,7 +609,7 @@ QFuture QXmppPubSubManager::cancelNodeConfiguration( } /// -/// \fn QXmppPubSubManager::createPepNode +/// \fn QFuture QXmppPubSubManager::createPepNode(const QString &nodeName) /// /// Creates an empty PEP node with the default configuration. /// @@ -576,6 +624,23 @@ QFuture QXmppPubSubManager::cancelNodeConfiguration( /// \return /// +/// +/// \fn QFuture QXmppPubSubManager::createPepNode(const QString &nodeName, const QXmppPubSubNodeConfig &config) +/// +/// Creates an empty PEP node with a custom configuration. +/// +/// This is a convenience method equivalent to calling +/// QXmppPubSubManager::createNode on the current account's bare JID. +/// +/// Calling this before QXmppPubSubManager::publishPepItems is usually not +/// necessary when publishing to a node for the first time if the service +/// suppports the auto-create feature (Section 7.1.4 of \xep{0060}). +/// +/// \param nodeName the name of the PEP node to be created +/// \param config The configuration for the node +/// \return +/// + /// /// \fn QXmppPubSubManager::deletePepNode /// -- cgit v1.2.3