From a42c11570b9bba3465fb79dc936de6cb3c7c48cb Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Thu, 7 Apr 2022 18:10:42 +0200 Subject: PubSubManager: Add requestFeatures() --- src/client/QXmppPubSubManager.cpp | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/client/QXmppPubSubManager.cpp') diff --git a/src/client/QXmppPubSubManager.cpp b/src/client/QXmppPubSubManager.cpp index 8e2a1b6f..00d537db 100644 --- a/src/client/QXmppPubSubManager.cpp +++ b/src/client/QXmppPubSubManager.cpp @@ -78,6 +78,13 @@ using namespace QXmpp::Private; /// QXmppStanza::Error is reported. /// +/// +/// \typedef QXmppPubSubManager::FeaturesResult +/// +/// Type containing service discovery features, InvalidServiceType if the service is not of the +/// desired type or the returned IQ error (QXmppStanza::Error). +/// + /// /// \typedef QXmppPubSubManager::NodesResult /// @@ -170,6 +177,58 @@ QXmppPubSubManager::~QXmppPubSubManager() { } +/// +/// Requests all features of a pubsub service and checks the identities via service discovery. +/// +/// This uses a \xep{0030, Service Discovery} info request to get the service +/// identities and features. +/// +/// The features are only returned if the service is of type serviceType, +/// otherwise InvalidServiceType is returned. +/// +/// \warning THIS API IS NOT FINALIZED YET! +/// +/// \param serviceJid JID of the entity hosting the pubsub service +/// \param serviceType type of service to retrieve features for +/// +QFuture QXmppPubSubManager::requestFeatures(const QString &serviceJid, ServiceType serviceType) +{ + QXmppDiscoveryIq request; + request.setType(QXmppIq::Get); + request.setQueryType(QXmppDiscoveryIq::InfoQuery); + request.setTo(serviceJid); + + return chainIq(client()->sendIq(std::move(request)), this, [=](QXmppDiscoveryIq &&iq) -> FeaturesResult { + const auto identities = iq.identities(); + + const auto isPubSubServiceFound = std::any_of(identities.cbegin(), identities.cend(), [=](const QXmppDiscoveryIq::Identity &identity) { + if (identity.category() == QStringLiteral("pubsub")) { + const auto identityType = identity.type(); + + switch (serviceType) { + case PubSubOrPep: + return identityType == QStringLiteral("service") || identityType == QStringLiteral("pep"); + case PubSub: + return identityType == QStringLiteral("service"); + case Pep: + return identityType == QStringLiteral("pep"); + } + } + return false; + }); + + if (isPubSubServiceFound) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return iq.features(); +#else + return iq.features().toVector(); +#endif + } + + return InvalidServiceType(); + }); +} + /// /// Requests all listed nodes of a pubsub service via service discovery. /// -- cgit v1.2.3