diff --git a/src/base/QXmppFutureUtils_p.h b/src/base/QXmppFutureUtils_p.h index 8925a6c06..e2bf6caab 100644 --- a/src/base/QXmppFutureUtils_p.h +++ b/src/base/QXmppFutureUtils_p.h @@ -15,6 +15,7 @@ // We mean it. // +#include "QXmppClient.h" #include "QXmppIq.h" #include "QXmppPromise.h" #include "QXmppSendResult.h" @@ -215,6 +216,26 @@ auto mapSuccess(std::variant var, Function lambda) std::move(var)); } +template +auto mapToSuccess(std::variant var) +{ + return mapSuccess(std::move(var), [](T) { + return Success(); + }); +} + +template +auto chainSuccess(QXmppTask &&source, QObject *context) -> QXmppTask +{ + QXmppPromise promise; + + source.then(context, [=](Input &&input) mutable { + promise.finish(mapToSuccess(std::move(input))); + }); + + return promise.task(); +} + template static auto taskFromFuture(QFuture &&future) -> QXmppTask { diff --git a/src/client/QXmppMixManager.cpp b/src/client/QXmppMixManager.cpp index f83c724da..9508a3eff 100644 --- a/src/client/QXmppMixManager.cpp +++ b/src/client/QXmppMixManager.cpp @@ -499,14 +499,7 @@ QXmppTask QXmppMixManager::requestChannelC QXmppTask QXmppMixManager::updateChannelConfiguration(const QString &channelJid, QXmppMixConfigItem configuration) { configuration.setFormType(QXmppDataForm::Submit); - - return chain(d->pubSubManager->publishItem(channelJid, ns_mix_node_config.toString(), configuration), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return QXmpp::Success(); - }); + return chainSuccess(d->pubSubManager->publishItem(channelJid, ns_mix_node_config.toString(), configuration), this); } /// @@ -550,14 +543,7 @@ QXmppTask QXmppMixManager::requestChannelInf QXmppTask QXmppMixManager::updateChannelInformation(const QString &channelJid, QXmppMixInfoItem information) { information.setFormType(QXmppDataForm::Submit); - - return chain(d->pubSubManager->publishItem(channelJid, ns_mix_node_info.toString(), information), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return QXmpp::Success(); - }); + return chainSuccess(d->pubSubManager->publishItem(channelJid, ns_mix_node_info.toString(), information), this); } /// @@ -1225,15 +1211,7 @@ QXmppTask QXmppMixManager::requestJids(const QString /// QXmppTask QXmppMixManager::addJidToNode(const QString &channelJid, const QString &node, const QString &jid) { - const QXmppPubSubBaseItem item { jid }; - - return chain(d->pubSubManager->publishItem(channelJid, node, item), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult { - if (auto *error = std::get_if(&result)) { - return std::move(*error); - } - - return QXmpp::Success(); - }); + return chainSuccess(d->pubSubManager->publishItem(channelJid, node, QXmppPubSubBaseItem { jid }), this); } /// diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index 3f9852b8e..04354f783 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -179,12 +179,6 @@ static void replaceChildElements(QDomElement &oldElement, const QDomElement &new } } -template -auto mapToSuccess(std::variant var) -{ - return mapSuccess(std::move(var), [](T) { return Success(); }); -} - QXmppOmemoManagerPrivate::QXmppOmemoManagerPrivate(Manager *parent, QXmppOmemoStorage *omemoStorage) : q(parent), omemoStorage(omemoStorage),