Fix bug where accounts would be removed while being iterated over

This commit is contained in:
shilangyu 2021-01-17 17:35:07 +00:00
parent f37da51137
commit e2af8326e2
1 changed files with 12 additions and 9 deletions

View File

@ -69,15 +69,18 @@ class AccountsStore extends ChangeNotifier {
/// automatically sets default accounts /// automatically sets default accounts
void _assignDefaultAccounts() { void _assignDefaultAccounts() {
// remove dangling defaults // remove dangling defaults
_defaultAccounts.entries.map((dft) { _defaultAccounts.entries
final instance = dft.key; .map((dft) {
final username = dft.value; final instance = dft.key;
// if instance or username doesn't exist, remove final username = dft.value;
if (!instances.contains(instance) || // if instance or username doesn't exist, remove
!usernamesFor(instance).contains(username)) { if (!instances.contains(instance) ||
return instance; !usernamesFor(instance).contains(username)) {
} return instance;
}).forEach(_defaultAccounts.remove); }
})
.toList()
.forEach(_defaultAccounts.remove);
if (_defaultAccount != null) { if (_defaultAccount != null) {
final instance = _defaultAccount.split('@')[1]; final instance = _defaultAccount.split('@')[1];
final username = _defaultAccount.split('@')[0]; final username = _defaultAccount.split('@')[0];