chore: cleanup AccountController connections (#6735)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user