Files
workavia-mail-front/lib/features/login/data/extensions/account_cache_extensions.dart
T
dab246 fc4a4792c3 TF-2177 Update account cache when store new account
Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 3fff318bbe66a5f4387c25d18e0d2a9480719d72)
2023-10-27 11:18:29 +07:00

51 lines
1.4 KiB
Dart

import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/account/authentication_type.dart';
import 'package:model/account/personal_account.dart';
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
extension AccountCacheExtension on AccountCache {
AuthenticationType fromAuthenticationTypeString() {
if (authenticationType == 'basic') {
return AuthenticationType.basic;
} else if (authenticationType == 'oidc') {
return AuthenticationType.oidc;
} else {
return AuthenticationType.none;
}
}
PersonalAccount toAccount() {
final authenticationType = fromAuthenticationTypeString();
return PersonalAccount(
id,
authenticationType,
isSelected: isSelected,
accountId: accountId != null ? AccountId(Id(accountId!)) : null,
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
);
}
}