refact: Move unconditional logic outside of if.

This commit is contained in:
Stiliyan Tonev (Bark) 2025-05-20 11:26:03 +03:00
commit 3d59cb9199

View file

@ -1120,17 +1120,11 @@ void TorrentsController::addTrackersAction()
QList<BitTorrent::Torrent *> torrents;
const QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(params()[u"urls"_s]);
if (hashParam == u"*"_s)
{
// add this tracker to all torrents
torrents = BitTorrent::Session::instance()->torrents();
}
else if (hashParam.contains(u'|'))
{
// add this tracker to all torrents in the list
const QStringList idStrings = hashParam.split(u'|', Qt::SkipEmptyParts);
for (const QString &hash : idStrings)
{
if (hash == u"*"_s)
continue;
const auto id = BitTorrent::TorrentID::fromString(hash);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent)
@ -1138,6 +1132,15 @@ void TorrentsController::addTrackersAction()
torrents.append(torrent);
}
if (hashParam == u"*"_s)
{
// add this tracker to all torrents
torrents = BitTorrent::Session::instance()->torrents();
}
else if (hashParam.contains(u'|'))
{
// We have this, so that we wont enter the `else` and break it.
}
else
{
@ -1223,17 +1226,11 @@ void TorrentsController::removeTrackersAction()
QList<BitTorrent::Torrent *> torrents;
if (hashParam == u"*"_s)
{
// remove trackers from all torrents
torrents = BitTorrent::Session::instance()->torrents();
}
else if (hashParam.contains(u'|'))
{
// remove trackers from all torrents in the list
const QStringList idStrings = hashParam.split(u'|', Qt::SkipEmptyParts);
for (const QString &hash : idStrings)
{
if (hash == u"*"_s)
continue;
const auto id = BitTorrent::TorrentID::fromString(hash);
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent)
@ -1241,6 +1238,15 @@ void TorrentsController::removeTrackersAction()
torrents.append(torrent);
}
if (hashParam == u"*"_s)
{
// remove trackers from all torrents
torrents = BitTorrent::Session::instance()->torrents();
}
else if (hashParam.contains(u'|'))
{
// Don't want to enter `else` with a `hashParam` not an id
}
else
{