aboutsummaryrefslogtreecommitdiff
path: root/src/client/QXmppPubSubManager.cpp
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2022-04-07 18:10:42 +0200
committerLinus Jahn <lnj@kaidan.im>2022-04-09 22:27:12 +0200
commita42c11570b9bba3465fb79dc936de6cb3c7c48cb (patch)
tree0d5a417e9fa1972fd89797c074bbbef3113fd51f /src/client/QXmppPubSubManager.cpp
parentd306ed08aa9d681a0b51ebbf2ec2a00b70b61018 (diff)
downloadqxmpp-a42c11570b9bba3465fb79dc936de6cb3c7c48cb.tar.gz
PubSubManager: Add requestFeatures()
Diffstat (limited to 'src/client/QXmppPubSubManager.cpp')
-rw-r--r--src/client/QXmppPubSubManager.cpp59
1 files changed, 59 insertions, 0 deletions
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
@@ -79,6 +79,13 @@ using namespace QXmpp::Private;
///
///
+/// \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
///
/// Type containing a list of node names or the returned IQ error
@@ -171,6 +178,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::FeaturesResult> 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.
///
/// This uses a \xep{0030, Service Discovery} items request to get a list of