TF-2177 Fix download attachment not working on web

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 09cbfe5245c206670aa2191c151fd8f2ea48df3a)
This commit is contained in:
dab246
2023-10-23 23:19:12 +07:00
committed by Dat H. Pham
parent 73a8919f18
commit 424ab675d5
17 changed files with 134 additions and 113 deletions
@@ -13,21 +13,21 @@ class HiveAccountDatasourceImpl extends AccountDatasource {
@override
Future<PersonalAccount> getCurrentAccount() {
return Future.sync(() async {
return await _accountCacheManager.getSelectedAccount();
return await _accountCacheManager.getCurrentAccount();
}).catchError(_exceptionThrower.throwException);
}
@override
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
return Future.sync(() async {
return await _accountCacheManager.setSelectedAccount(newCurrentAccount);
return await _accountCacheManager.setCurrentAccount(newCurrentAccount);
}).catchError(_exceptionThrower.throwException);
}
@override
Future<void> deleteCurrentAccount(String accountId) {
return Future.sync(() async {
return await _accountCacheManager.deleteSelectedAccount(accountId);
return await _accountCacheManager.deleteCurrentAccount(accountId);
}).catchError(_exceptionThrower.throwException);
}
}
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:core/utils/app_logger.dart';
import 'package:model/account/personal_account.dart';
import 'package:tmail_ui_user/features/caching/clients/account_cache_client.dart';
@@ -10,24 +11,29 @@ class AccountCacheManager {
AccountCacheManager(this._accountCacheClient);
Future<PersonalAccount> getSelectedAccount() async {
try {
final allAccounts = await _accountCacheClient.getAll();
return allAccounts.firstWhere((account) => account.isSelected)
.toAccount();
} catch (e) {
logError('AccountCacheManager::getSelectedAccount(): $e');
Future<PersonalAccount> getCurrentAccount() async {
final allAccounts = await _accountCacheClient.getAll();
log('AccountCacheManager::getCurrentAccount::allAccounts(): $allAccounts');
final accountCache = allAccounts.firstWhereOrNull((account) => account.isSelected);
log('AccountCacheManager::getCurrentAccount::accountCache(): $accountCache');
if (accountCache != null) {
return accountCache.toAccount();
} else {
throw NotFoundAuthenticatedAccountException();
}
}
Future<void> setSelectedAccount(PersonalAccount account) {
log('AccountCacheManager::setSelectedAccount(): $_accountCacheClient');
Future<void> setCurrentAccount(PersonalAccount account) async {
log('AccountCacheManager::setCurrentAccount(): $account');
final accountCacheExist = await _accountCacheClient.isExistTable();
if (accountCacheExist) {
await _accountCacheClient.clearAllData();
}
return _accountCacheClient.insertItem(account.id, account.toCache());
}
Future<void> deleteSelectedAccount(String accountId) {
log('AccountCacheManager::deleteSelectedAccount(): $accountId');
return _accountCacheClient.deleteItem(accountId);
Future<void> deleteCurrentAccount(String hashId) {
log('AccountCacheManager::deleteCurrentAccount(): $hashId');
return _accountCacheClient.deleteItem(hashId);
}
}
@@ -1,5 +1,6 @@
import 'package:tmail_ui_user/features/caching/clients/authentication_info_cache_client.dart';
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
class AuthenticationInfoCacheManager {
final AuthenticationInfoCacheClient _authenticationInfoCacheClient;
@@ -12,8 +13,13 @@ class AuthenticationInfoCacheManager {
authenticationInfoCache);
}
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue);
Future<AuthenticationInfoCache> getAuthenticationInfoStored() async {
final authenticationInfoCache = await _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue);
if (authenticationInfoCache != null) {
return authenticationInfoCache;
} else {
throw NotFoundAuthenticationInfoCache();
}
}
Future<void> removeAuthenticationInfo() {
@@ -56,8 +56,7 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
log('AuthorizationInterceptors::onRequest():DATA: ${options.data}');
log('AuthorizationInterceptors::onRequest():TOKEN_HASHCODE_CURRENT: ${_token?.token.hashCode}');
log('AuthorizationInterceptors::onRequest():data: ${options.data} | header: ${options.headers}');
switch(_authenticationType) {
case AuthenticationType.basic:
if (_authorization != null) {
@@ -78,8 +77,6 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
@override
void onError(DioError err, ErrorInterceptorHandler handler) async {
logError('AuthorizationInterceptors::onError(): $err');
logError('AuthorizationInterceptors::onError():TOKEN_HASHCODE_CURRENT: ${_token?.token.hashCode}');
final requestOptions = err.requestOptions;
final extraInRequest = requestOptions.extra;
var retries = extraInRequest[RETRY_KEY] ?? 0;
@@ -94,20 +91,20 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
_token!.refreshToken
);
final accountCurrent = await _accountCacheManager.getSelectedAccount();
final currentAccount = await _accountCacheManager.getCurrentAccount();
await _accountCacheManager.deleteSelectedAccount(_token!.tokenIdHash);
await _accountCacheManager.deleteCurrentAccount(currentAccount.id);
await Future.wait([
_tokenOidcCacheManager.persistOneTokenOidc(newToken),
_accountCacheManager.setSelectedAccount(
_accountCacheManager.setCurrentAccount(
PersonalAccount(
newToken.tokenIdHash,
AuthenticationType.oidc,
isSelected: true,
accountId: accountCurrent.accountId,
apiUrl: accountCurrent.apiUrl,
userName: accountCurrent.userName
accountId: currentAccount.accountId,
apiUrl: currentAccount.apiUrl,
userName: currentAccount.userName
)
)
]);
@@ -1,4 +1,3 @@
import 'package:core/utils/app_logger.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';
@@ -16,12 +15,11 @@ class AccountRepositoryImpl extends AccountRepository {
@override
Future<void> setCurrentAccount(PersonalAccount newCurrentAccount) {
log('AccountRepositoryImpl::setCurrentAccount(): $newCurrentAccount');
return _accountDatasource.setCurrentAccount(newCurrentAccount);
}
@override
Future<void> deleteCurrentAccount(String accountId) {
return _accountDatasource.deleteCurrentAccount(accountId);
Future<void> deleteCurrentAccount(String hashId) {
return _accountDatasource.deleteCurrentAccount(hashId);
}
}
@@ -36,7 +36,7 @@ class CredentialRepositoryImpl extends CredentialRepository {
}
@override
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
Future<AuthenticationInfoCache> getAuthenticationInfoStored() {
return _authenticationInfoCacheManager.getAuthenticationInfoStored();
}