Skip to content

Commit

Permalink
MixManager: Always catch error case first and remove unneeded 'else' …
Browse files Browse the repository at this point in the history
…cases
  • Loading branch information
melvo committed Mar 22, 2024
1 parent 5fc73aa commit 31372af
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions src/client/QXmppMixManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,14 @@ QXmppTask<QXmppMixManager::CreationResult> QXmppMixManager::createChannel(const
QXmppTask<QXmppMixManager::ChannelJidResult> QXmppMixManager::requestChannelJids(const QString &serviceJid)
{
return chain<ChannelJidResult>(d->discoveryManager->requestDiscoItems(serviceJid), this, [](QXmppDiscoveryManager::ItemsResult &&result) -> ChannelJidResult {
if (const auto items = std::get_if<QList<QXmppDiscoveryIq::Item>>(&result)) {
return transform<QVector<ChannelJid>>(*items, [](const QXmppDiscoveryIq::Item &item) {
return item.jid();
});
} else {
return std::get<QXmppError>(std::move(result));
if (const auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
}

const auto &items = std::get<QList<QXmppDiscoveryIq::Item>>(result);
return transform<QVector<ChannelJid>>(items, [](const QXmppDiscoveryIq::Item &item) {
return item.jid();
});
});
}

Expand All @@ -454,15 +455,14 @@ QXmppTask<QXmppMixManager::ChannelNodeResult> QXmppMixManager::requestChannelNod
return chain<ChannelNodeResult>(d->discoveryManager->requestDiscoItems(channelJid, MIX_SERVICE_DISCOVERY_NODE.toString()), this, [](QXmppDiscoveryManager::ItemsResult &&result) -> ChannelNodeResult {
if (const auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
const auto &items = std::get<QList<QXmppDiscoveryIq::Item>>(result);
}

const auto nodes = transform<QVector<QString>>(items, [](const QXmppDiscoveryIq::Item &item) {
return item.node();
});
const auto &items = std::get<QList<QXmppDiscoveryIq::Item>>(result);
const auto nodes = transform<QVector<QString>>(items, [](const QXmppDiscoveryIq::Item &item) {
return item.node();
});

return std::move(listToMixNodes(nodes));
}
return std::move(listToMixNodes(nodes));
});
}

Expand All @@ -478,9 +478,9 @@ QXmppTask<QXmppMixManager::ConfigurationResult> QXmppMixManager::requestChannelC
return chain<ConfigurationResult>(d->pubSubManager->requestItems<QXmppMixConfigItem>(channelJid, ns_mix_node_config.toString()), this, [](QXmppPubSubManager::ItemsResult<QXmppMixConfigItem> &&result) -> ConfigurationResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return std::get<QXmppPubSubManager::Items<QXmppMixConfigItem>>(result).items.constFirst();
}

return std::get<QXmppPubSubManager::Items<QXmppMixConfigItem>>(result).items.constFirst();
});
}

Expand All @@ -503,9 +503,9 @@ QXmppTask<QXmppClient::EmptyResult> QXmppMixManager::updateChannelConfiguration(
return chain<QXmppClient::EmptyResult>(d->pubSubManager->publishItem(channelJid, ns_mix_node_config.toString(), configuration), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return QXmpp::Success();
}

return QXmpp::Success();
});
}

Expand All @@ -530,9 +530,9 @@ QXmppTask<QXmppMixManager::InformationResult> QXmppMixManager::requestChannelInf
return chain<InformationResult>(d->pubSubManager->requestItems<QXmppMixInfoItem>(channelJid, ns_mix_node_info.toString()), this, [](QXmppPubSubManager::ItemsResult<QXmppMixInfoItem> &&result) -> InformationResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return std::get<QXmppPubSubManager::Items<QXmppMixInfoItem>>(result).items.constFirst();
}

return std::get<QXmppPubSubManager::Items<QXmppMixInfoItem>>(result).items.constFirst();
});
}

Expand All @@ -554,9 +554,9 @@ QXmppTask<QXmppClient::EmptyResult> QXmppMixManager::updateChannelInformation(co
return chain<QXmppClient::EmptyResult>(d->pubSubManager->publishItem(channelJid, ns_mix_node_info.toString(), information), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return QXmpp::Success();
}

return QXmpp::Success();
});
}

Expand Down Expand Up @@ -913,9 +913,9 @@ QXmppTask<QXmppMixManager::ParticipantResult> QXmppMixManager::requestParticipan
return chain<ParticipantResult>(d->pubSubManager->requestItems<QXmppMixParticipantItem>(channelJid, ns_mix_node_participants.toString()), this, [](QXmppPubSubManager::ItemsResult<QXmppMixParticipantItem> &&result) -> ParticipantResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return std::get<QXmppPubSubManager::Items<QXmppMixParticipantItem>>(std::move(result)).items;
}

return std::get<QXmppPubSubManager::Items<QXmppMixParticipantItem>>(std::move(result)).items;
});
}

Expand Down Expand Up @@ -1036,7 +1036,9 @@ bool QXmppMixManager::handlePubSubEvent(const QDomElement &element, const QStrin
}

return true;
} else if (nodeName == ns_mix_node_banned && QXmppPubSubEvent<QXmppPubSubBaseItem>::isPubSubEvent(element)) {
}

if (nodeName == ns_mix_node_banned && QXmppPubSubEvent<QXmppPubSubBaseItem>::isPubSubEvent(element)) {
QXmppPubSubEvent<QXmppPubSubBaseItem> event;
event.parse(element);

Expand Down Expand Up @@ -1069,7 +1071,9 @@ bool QXmppMixManager::handlePubSubEvent(const QDomElement &element, const QStrin
}

return true;
} else if (nodeName == ns_mix_node_config && QXmppPubSubEvent<QXmppMixConfigItem>::isPubSubEvent(element)) {
}

if (nodeName == ns_mix_node_config && QXmppPubSubEvent<QXmppMixConfigItem>::isPubSubEvent(element)) {
QXmppPubSubEvent<QXmppMixConfigItem> event;
event.parse(element);

Expand All @@ -1088,7 +1092,9 @@ bool QXmppMixManager::handlePubSubEvent(const QDomElement &element, const QStrin
}

return true;
} else if (nodeName == ns_mix_node_info && QXmppPubSubEvent<QXmppMixInfoItem>::isPubSubEvent(element)) {
}

if (nodeName == ns_mix_node_info && QXmppPubSubEvent<QXmppMixInfoItem>::isPubSubEvent(element)) {
QXmppPubSubEvent<QXmppMixInfoItem> event;
event.parse(element);

Expand All @@ -1107,7 +1113,9 @@ bool QXmppMixManager::handlePubSubEvent(const QDomElement &element, const QStrin
}

return true;
} else if (nodeName == ns_mix_node_participants && QXmppPubSubEvent<QXmppMixParticipantItem>::isPubSubEvent(element)) {
}

if (nodeName == ns_mix_node_participants && QXmppPubSubEvent<QXmppMixParticipantItem>::isPubSubEvent(element)) {
QXmppPubSubEvent<QXmppMixParticipantItem> event;
event.parse(element);

Expand Down Expand Up @@ -1199,12 +1207,12 @@ QXmppTask<QXmppMixManager::JidResult> QXmppMixManager::requestJids(const QString
return chain<JidResult>(d->pubSubManager->requestItems(channelJid, node), this, [](QXmppPubSubManager::ItemsResult<QXmppPubSubBaseItem> &&result) -> JidResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
const auto &items = std::get<QXmppPubSubManager::Items<QXmppPubSubBaseItem>>(result).items;
return transform<QVector<Jid>>(items, [](const QXmppPubSubBaseItem &item) {
return item.id();
});
}

const auto &items = std::get<QXmppPubSubManager::Items<QXmppPubSubBaseItem>>(result).items;
return transform<QVector<Jid>>(items, [](const QXmppPubSubBaseItem &item) {
return item.id();
});
});
}

Expand All @@ -1226,9 +1234,9 @@ QXmppTask<QXmppClient::EmptyResult> QXmppMixManager::addJidToNode(const QString
return chain<QXmppClient::EmptyResult>(d->pubSubManager->publishItem(channelJid, node, item), this, [](QXmppPubSubManager::PublishItemResult &&result) -> QXmppClient::EmptyResult {
if (auto error = std::get_if<QXmppError>(&result)) {
return std::move(*error);
} else {
return QXmpp::Success();
}

return QXmpp::Success();
});
}

Expand Down Expand Up @@ -1346,10 +1354,10 @@ void QXmppMixManager::removeService(const QString &jid)

if (itr == d->services.end()) {
return;
} else {
d->services.erase(itr);
}

d->services.erase(itr);

Q_EMIT servicesChanged();
}

Expand Down

0 comments on commit 31372af

Please sign in to comment.