diff --git a/src/base/QXmppFutureUtils_p.h b/src/base/QXmppFutureUtils_p.h index 61a5c4483..ac4f8a042 100644 --- a/src/base/QXmppFutureUtils_p.h +++ b/src/base/QXmppFutureUtils_p.h @@ -211,6 +211,14 @@ auto chainSuccess(QXmppTask &&source, QObject *context) -> QXmppTask +auto chainOnSuccess(QXmppTask &&source, QObject *context, Converter convert) -> QXmppTask +{ + return chain(std::move(source), context, [convert](Input &&input) { + return mapSuccess(std::move(input), convert); + }); +} + } // namespace QXmpp::Private #endif // QXMPPFUTUREUTILS_P_H diff --git a/src/client/QXmppMixManager.cpp b/src/client/QXmppMixManager.cpp index 7863a6222..a3098fbf9 100644 --- a/src/client/QXmppMixManager.cpp +++ b/src/client/QXmppMixManager.cpp @@ -431,12 +431,7 @@ QXmppTask QXmppMixManager::createChannel(const /// QXmppTask QXmppMixManager::requestChannelJids(const QString &serviceJid) { - return chain(d->discoveryManager->requestDiscoItems(serviceJid), this, [](QXmppDiscoveryManager::ItemsResult &&result) -> ChannelJidResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - const auto &items = std::get>(result); + return chainOnSuccess(d->discoveryManager->requestDiscoItems(serviceJid), this, [](QList &&items) { return transform>(items, [](const QXmppDiscoveryIq::Item &item) { return item.jid(); }); @@ -452,17 +447,10 @@ QXmppTask QXmppMixManager::requestChannelJids /// QXmppTask QXmppMixManager::requestChannelNodes(const QString &channelJid) { - return chain(d->discoveryManager->requestDiscoItems(channelJid, MIX_SERVICE_DISCOVERY_NODE.toString()), this, [](QXmppDiscoveryManager::ItemsResult &&result) -> ChannelNodeResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - const auto &items = std::get>(result); - const auto nodes = transform>(items, [](const QXmppDiscoveryIq::Item &item) { + return chainOnSuccess(d->discoveryManager->requestDiscoItems(channelJid, MIX_SERVICE_DISCOVERY_NODE.toString()), this, [](QList &&items) { + return listToMixNodes(transform>(items, [](const QXmppDiscoveryIq::Item &item) { return item.node(); - }); - - return listToMixNodes(nodes); + })); }); } @@ -475,12 +463,8 @@ QXmppTask QXmppMixManager::requestChannelNod /// QXmppTask QXmppMixManager::requestChannelConfiguration(const QString &channelJid) { - return chain(d->pubSubManager->requestItems(channelJid, ns_mix_node_config.toString()), this, [](QXmppPubSubManager::ItemsResult &&result) -> ConfigurationResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return std::get>(result).items.takeFirst(); + return chainOnSuccess(d->pubSubManager->requestItems(channelJid, ns_mix_node_config.toString()), this, [](QXmppPubSubManager::Items &&items) { + return items.items.takeFirst(); }); } @@ -520,12 +504,8 @@ QXmppTask QXmppMixManager::updateChannelConfiguration( /// QXmppTask QXmppMixManager::requestChannelInformation(const QString &channelJid) { - return chain(d->pubSubManager->requestItems(channelJid, ns_mix_node_info.toString()), this, [](QXmppPubSubManager::ItemsResult &&result) -> InformationResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return std::get>(result).items.takeFirst(); + return chainOnSuccess(d->pubSubManager->requestItems(channelJid, ns_mix_node_info.toString()), this, [](QXmppPubSubManager::Items &&items) { + return items.items.takeFirst(); }); } @@ -885,12 +865,8 @@ QXmppTask QXmppMixManager::unbanAllJids(const QString /// QXmppTask QXmppMixManager::requestParticipants(const QString &channelJid) { - return chain(d->pubSubManager->requestItems(channelJid, ns_mix_node_participants.toString()), this, [](QXmppPubSubManager::ItemsResult &&result) -> ParticipantResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return std::get>(std::move(result)).items; + return chainOnSuccess(d->pubSubManager->requestItems(channelJid, ns_mix_node_participants.toString()), this, [](QXmppPubSubManager::Items &&items) { + return items.items; }); } @@ -1187,13 +1163,8 @@ QXmppTask QXmppMixManager::joinChannel(QXmppMixI /// QXmppTask QXmppMixManager::requestJids(const QString &channelJid, const QString &node) { - return chain(d->pubSubManager->requestItems(channelJid, node), this, [](QXmppPubSubManager::ItemsResult &&result) -> JidResult { - if (auto error = std::get_if(&result)) { - return std::move(*error); - } - - const auto &items = std::get>(result).items; - return transform>(items, [](const QXmppPubSubBaseItem &item) { + return chainOnSuccess(d->pubSubManager->requestItems(channelJid, node), this, [](QXmppPubSubManager::Items &&items) { + return transform>(items.items, [](const QXmppPubSubBaseItem &item) { return item.id(); }); });