From 7b3ad2eabba4b9ead6fe4415c9e353bd32f6aa3b Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Sun, 19 Jan 2025 13:21:03 +0000 Subject: [PATCH] refactor: simplify setTagsAction --- src/webui/api/torrentscontroller.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index a913d5796..d44bcee24 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -1482,23 +1482,14 @@ void TorrentsController::setTagsAction() const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)}; const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)}; - // Convert QStringList to TagSet - TagSet newTags; - for (const QString &tagStr : tags) - newTags.insert(Tag(tagStr)); - - // Apply the new tags to the selected torrents + const TagSet newTags {tags.begin(), tags.end()}; applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent) { - // Identify tags to add - for (const Tag &tag : newTags) - if (!torrent->hasTag(tag)) - torrent->addTag(tag); - - // Identify tags to remove for (const Tag &tag : asConst(torrent->tags())) if (!newTags.contains(tag)) torrent->removeTag(tag); + for (const Tag &tag : newTags) + torrent->addTag(tag); }); }