TF-2177 Update account cache when store new account

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 3fff318bbe66a5f4387c25d18e0d2a9480719d72)
This commit is contained in:
dab246
2023-10-24 14:08:54 +07:00
committed by Dat H. Pham
parent 6a0b3a7bc4
commit fc4a4792c3
4 changed files with 109 additions and 6 deletions
@@ -26,4 +26,26 @@ extension AccountCacheExtension on AccountCache {
apiUrl: apiUrl,
userName: userName != null ? UserName(userName!) : null);
}
AccountCache unselected() {
return AccountCache(
id,
authenticationType,
isSelected: false,
accountId: accountId,
apiUrl: apiUrl,
userName: userName
);
}
AccountCache emptyId() {
return AccountCache(
'',
authenticationType,
isSelected: false,
accountId: accountId,
apiUrl: apiUrl,
userName: userName
);
}
}
@@ -0,0 +1,23 @@
import 'package:collection/collection.dart';
import 'package:core/utils/app_logger.dart';
import 'package:tmail_ui_user/features/login/data/extensions/account_cache_extensions.dart';
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
extension ListAccountCacheExtension on List<AccountCache> {
List<AccountCache> unselected() => map((account) => account.unselected()).toList();
List<AccountCache> removeDuplicated() {
final listAccountId = map((account) => account.accountId).whereNotNull().toSet();
log('ListAccountCacheExtension::removeDuplicated:listAccountId: $listAccountId');
retainWhere((account) => listAccountId.remove(account.accountId));
log('ListAccountCacheExtension::removeDuplicated:listAccount: $this');
return this;
}
Map<String, AccountCache> toMap() {
return {
for (var account in this)
account.id: account
};
}
}