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:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user