chore: cleanup AccountController connections (#6735)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Nerixyz
2026-01-11 21:57:55 +01:00
committed by GitHub
parent cffd86aa4f
commit 31ef6eeddf
3 changed files with 13 additions and 13 deletions
+1
View File
@@ -88,6 +88,7 @@
- Dev: Moved Twitch PubSub to liveupdates. (#6638) - Dev: Moved Twitch PubSub to liveupdates. (#6638)
- Dev: Refactored types used for emoji parsing. (#6714) - Dev: Refactored types used for emoji parsing. (#6714)
- Dev: `LinkParser` now parses `QStringView`s. (#6715) - Dev: `LinkParser` now parses `QStringView`s. (#6715)
- Dev: Cleaned up `AccountController` connections. (#6735)
## 2.5.4 ## 2.5.4
+1 -2
View File
@@ -132,8 +132,7 @@ public:
this->itemsChanged_(); this->itemsChanged_();
} }
bool removeFirstMatching(std::function<bool(const T &)> matcher, bool removeFirstMatching(auto &&matcher, void *caller = nullptr)
void *caller = nullptr)
{ {
assertInGuiThread(); assertInGuiThread();
+11 -11
View File
@@ -18,19 +18,18 @@ AccountController::AccountController()
// will always be destroyed before the AccountController // will always be destroyed before the AccountController
std::ignore = std::ignore =
this->twitch.accounts.itemInserted.connect([this](const auto &args) { this->twitch.accounts.itemInserted.connect([this](const auto &args) {
this->accounts_.insert( this->accounts_.insert(args.item);
std::dynamic_pointer_cast<Account>(args.item));
}); });
std::ignore = std::ignore =
this->twitch.accounts.itemRemoved.connect([this](const auto &args) { this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this) if (args.caller != this)
{ {
const auto &accs = this->twitch.accounts.raw(); this->accounts_.removeFirstMatching(
auto it = std::find(accs.begin(), accs.end(), args.item); [&](const auto &item) {
assert(it != accs.end()); return item == args.item;
},
this->accounts_.removeAt(it - accs.begin(), this); this);
} }
}); });
@@ -40,10 +39,11 @@ AccountController::AccountController()
case ProviderId::Twitch: { case ProviderId::Twitch: {
if (args.caller != this) if (args.caller != this)
{ {
auto &&accs = this->twitch.accounts; this->twitch.accounts.removeFirstMatching(
auto it = std::find(accs.begin(), accs.end(), args.item); [&](const auto &item) {
assert(it != accs.end()); return item == args.item;
this->twitch.accounts.removeAt(it - accs.begin(), this); },
this);
} }
} }
break; break;