Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive
(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
|
||||
abstract class AccountDatasource {
|
||||
Future<Account> getCurrentAccount();
|
||||
Future<PersonalAccount> getCurrentAccount();
|
||||
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount);
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount);
|
||||
|
||||
Future<void> deleteCurrentAccount(String accountId);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
|
||||
abstract class AuthenticationDataSource {
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||
|
||||
class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||
@@ -8,7 +10,7 @@ class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||
@override
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
|
||||
return Future.sync(() {
|
||||
return UserProfile(userName.userName);
|
||||
return UserProfile(userName.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
@@ -11,14 +11,14 @@ class HiveAccountDatasourceImpl extends AccountDatasource {
|
||||
HiveAccountDatasourceImpl(this._accountCacheManager, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<Account> getCurrentAccount() {
|
||||
Future<PersonalAccount> getCurrentAccount() {
|
||||
return Future.sync(() async {
|
||||
return await _accountCacheManager.getSelectedAccount();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount) {
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
|
||||
return Future.sync(() async {
|
||||
return await _accountCacheManager.setSelectedAccount(newCurrentAccount);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:model/account/account.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 {
|
||||
@@ -15,14 +16,14 @@ extension AccountCacheExtension on AccountCache {
|
||||
}
|
||||
}
|
||||
|
||||
Account toAccount() {
|
||||
PersonalAccount toAccount() {
|
||||
final authenticationType = fromAuthenticationTypeString();
|
||||
return Account(
|
||||
return PersonalAccount(
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected: isSelected,
|
||||
accountId: accountId != null ? AccountId(Id(accountId!)) : null,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
apiUrl: apiUrl,
|
||||
userName: userName != null ? UserName(userName!) : null);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
import 'package:model/account/account.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 AccountExtensions on Account {
|
||||
extension PersonalAccountExtension on PersonalAccount {
|
||||
AccountCache toCache() {
|
||||
return AccountCache(
|
||||
id,
|
||||
authenticationType.asString(),
|
||||
isSelected: isSelected,
|
||||
accountId: accountId?.id.value,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
apiUrl: apiUrl,
|
||||
userName: userName?.value);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/caching/account_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/account_cache_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/account_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/extensions/personal_account_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
|
||||
class AccountCacheManager {
|
||||
@@ -10,7 +10,7 @@ class AccountCacheManager {
|
||||
|
||||
AccountCacheManager(this._accountCacheClient);
|
||||
|
||||
Future<Account> getSelectedAccount() async {
|
||||
Future<PersonalAccount> getSelectedAccount() async {
|
||||
try {
|
||||
final allAccounts = await _accountCacheClient.getAll();
|
||||
return allAccounts.firstWhere((account) => account.isSelected)
|
||||
@@ -21,7 +21,7 @@ class AccountCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setSelectedAccount(Account account) {
|
||||
Future<void> setSelectedAccount(PersonalAccount account) {
|
||||
log('AccountCacheManager::setSelectedAccount(): $_accountCacheClient');
|
||||
return _accountCacheClient.insertItem(account.id, account.toCache());
|
||||
}
|
||||
|
||||
@@ -21,13 +21,17 @@ class AccountCache extends HiveObject with EquatableMixin {
|
||||
@HiveField(4)
|
||||
final String? apiUrl;
|
||||
|
||||
@HiveField(5)
|
||||
final String? userName;
|
||||
|
||||
AccountCache(
|
||||
this.id,
|
||||
this.authenticationType,
|
||||
{
|
||||
required this.isSelected,
|
||||
this.accountId,
|
||||
this.apiUrl
|
||||
this.apiUrl,
|
||||
this.userName
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,6 +41,7 @@ class AccountCache extends HiveObject with EquatableMixin {
|
||||
authenticationType,
|
||||
isSelected,
|
||||
accountId,
|
||||
apiUrl
|
||||
apiUrl,
|
||||
userName
|
||||
];
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/token.dart';
|
||||
@@ -93,13 +93,13 @@ class AuthorizationInterceptors extends InterceptorsWrapper {
|
||||
await Future.wait([
|
||||
_tokenOidcCacheManager.persistOneTokenOidc(newToken),
|
||||
_accountCacheManager.deleteSelectedAccount(_token!.tokenIdHash),
|
||||
_accountCacheManager.setSelectedAccount(Account(
|
||||
_accountCacheManager.setSelectedAccount(PersonalAccount(
|
||||
newToken.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true,
|
||||
accountId: accountCurrent.accountId,
|
||||
apiUrl: accountCurrent.apiUrl
|
||||
)),
|
||||
apiUrl: accountCurrent.apiUrl,
|
||||
userName: accountCurrent.userName))
|
||||
]);
|
||||
|
||||
log('AuthorizationInterceptors::onError(): refreshToken: $newToken');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
|
||||
@@ -10,12 +10,12 @@ class AccountRepositoryImpl extends AccountRepository {
|
||||
AccountRepositoryImpl(this._accountDatasource);
|
||||
|
||||
@override
|
||||
Future<Account> getCurrentAccount() {
|
||||
Future<PersonalAccount> getCurrentAccount() {
|
||||
return _accountDatasource.getCurrentAccount();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentAccount(Account newCurrentAccount) {
|
||||
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
|
||||
log('AccountRepositoryImpl::setCurrentAccount(): $newCurrentAccount');
|
||||
return _accountDatasource.setCurrentAccount(newCurrentAccount);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:model/model.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/user/user_profile.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user