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: Refactored types used for emoji parsing. (#6714)
- Dev: `LinkParser` now parses `QStringView`s. (#6715)
- Dev: Cleaned up `AccountController` connections. (#6735)
## 2.5.4
+1 -2
View File
@@ -132,8 +132,7 @@ public:
this->itemsChanged_();
}
bool removeFirstMatching(std::function<bool(const T &)> matcher,
void *caller = nullptr)
bool removeFirstMatching(auto &&matcher, void *caller = nullptr)
{
assertInGuiThread();
+11 -11
View File
@@ -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<Account>(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;