From 31ef6eeddf5db154882543a4a8a1533e620951f2 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sun, 11 Jan 2026 21:57:55 +0100 Subject: [PATCH] chore: cleanup AccountController connections (#6735) Reviewed-by: pajlada --- CHANGELOG.md | 1 + src/common/SignalVector.hpp | 3 +-- .../accounts/AccountController.cpp | 22 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71f01ebe..bc8ddc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ - Dev: Moved Twitch PubSub to liveupdates. (#6638) - Dev: Refactored types used for emoji parsing. (#6714) - Dev: `LinkParser` now parses `QStringView`s. (#6715) +- Dev: Cleaned up `AccountController` connections. (#6735) ## 2.5.4 diff --git a/src/common/SignalVector.hpp b/src/common/SignalVector.hpp index ce7203a6..c8a5acdf 100644 --- a/src/common/SignalVector.hpp +++ b/src/common/SignalVector.hpp @@ -132,8 +132,7 @@ public: this->itemsChanged_(); } - bool removeFirstMatching(std::function matcher, - void *caller = nullptr) + bool removeFirstMatching(auto &&matcher, void *caller = nullptr) { assertInGuiThread(); diff --git a/src/controllers/accounts/AccountController.cpp b/src/controllers/accounts/AccountController.cpp index dc9a436b..0e8c861e 100644 --- a/src/controllers/accounts/AccountController.cpp +++ b/src/controllers/accounts/AccountController.cpp @@ -18,19 +18,18 @@ AccountController::AccountController() // will always be destroyed before the AccountController std::ignore = this->twitch.accounts.itemInserted.connect([this](const auto &args) { - this->accounts_.insert( - std::dynamic_pointer_cast(args.item)); + this->accounts_.insert(args.item); }); std::ignore = this->twitch.accounts.itemRemoved.connect([this](const auto &args) { if (args.caller != this) { - const auto &accs = this->twitch.accounts.raw(); - auto it = std::find(accs.begin(), accs.end(), args.item); - assert(it != accs.end()); - - this->accounts_.removeAt(it - accs.begin(), this); + this->accounts_.removeFirstMatching( + [&](const auto &item) { + return item == args.item; + }, + this); } }); @@ -40,10 +39,11 @@ AccountController::AccountController() case ProviderId::Twitch: { if (args.caller != this) { - auto &&accs = this->twitch.accounts; - auto it = std::find(accs.begin(), accs.end(), args.item); - assert(it != accs.end()); - this->twitch.accounts.removeAt(it - accs.begin(), this); + this->twitch.accounts.removeFirstMatching( + [&](const auto &item) { + return item == args.item; + }, + this); } } break;