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:
@@ -55,9 +55,11 @@ class DownloadAttachmentForWebSuccess extends UIState {
|
||||
|
||||
class DownloadAttachmentForWebFailure extends FeatureFailure {
|
||||
|
||||
final DownloadTaskId taskId;
|
||||
final DownloadTaskId? taskId;
|
||||
|
||||
DownloadAttachmentForWebFailure(this.taskId, dynamic exception) : super(exception: exception);
|
||||
DownloadAttachmentForWebFailure({
|
||||
this.taskId, dynamic exception
|
||||
}) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [taskId, ...super.props];
|
||||
|
||||
@@ -45,39 +45,38 @@ class DownloadAttachmentForWebInteractor {
|
||||
|
||||
if (currentAccount.authenticationType == AuthenticationType.oidc) {
|
||||
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
|
||||
accountRequest = AccountRequest(
|
||||
token: tokenOidc.toToken(),
|
||||
authenticationType: AuthenticationType.oidc);
|
||||
accountRequest = AccountRequest.withOidc(token: tokenOidc.toToken());
|
||||
} else {
|
||||
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
|
||||
if (authenticationInfoCache != null) {
|
||||
accountRequest = AccountRequest(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
authenticationType: AuthenticationType.basic);
|
||||
}
|
||||
accountRequest = AccountRequest.withBasic(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
);
|
||||
}
|
||||
|
||||
if (accountRequest != null) {
|
||||
final bytesDownloaded = await emailRepository.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
onReceiveController);
|
||||
final bytesDownloaded = await emailRepository.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
onReceiveController
|
||||
);
|
||||
|
||||
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess(
|
||||
taskId,
|
||||
attachment,
|
||||
bytesDownloaded));
|
||||
} else {
|
||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(taskId, null));
|
||||
}
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(
|
||||
yield Right<Failure, Success>(
|
||||
DownloadAttachmentForWebSuccess(
|
||||
taskId,
|
||||
exception));
|
||||
attachment,
|
||||
bytesDownloaded
|
||||
)
|
||||
);
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(
|
||||
DownloadAttachmentForWebFailure(
|
||||
taskId: taskId,
|
||||
exception: exception
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,32 +46,25 @@ class DownloadAttachmentsInteractor {
|
||||
|
||||
if (currentAccount.authenticationType == AuthenticationType.oidc) {
|
||||
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
|
||||
accountRequest = AccountRequest(
|
||||
token: tokenOidc.toToken(),
|
||||
authenticationType: AuthenticationType.oidc);
|
||||
accountRequest = AccountRequest.withOidc(token: tokenOidc.toToken());
|
||||
} else {
|
||||
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
|
||||
if (authenticationInfoCache != null) {
|
||||
accountRequest = AccountRequest(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
authenticationType: AuthenticationType.basic);
|
||||
}
|
||||
accountRequest = AccountRequest.withBasic(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
);
|
||||
}
|
||||
|
||||
if (accountRequest != null) {
|
||||
final taskIds = await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest);
|
||||
final taskIds = await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest
|
||||
);
|
||||
|
||||
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
} else {
|
||||
yield Left<Failure, Success>(DownloadAttachmentsFailure(null));
|
||||
}
|
||||
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
} catch (exception) {
|
||||
log('DownloadAttachmentsInteractor::execute(): $exception');
|
||||
logError('DownloadAttachmentsInteractor::execute(): $exception');
|
||||
if (exception is DownloadAttachmentHasTokenExpiredException &&
|
||||
exception.refreshToken.isNotEmpty) {
|
||||
yield* _retryDownloadAttachments(
|
||||
@@ -101,9 +94,10 @@ class DownloadAttachmentsInteractor {
|
||||
oidcConfig.scopes,
|
||||
refreshToken);
|
||||
|
||||
await _accountRepository.deleteCurrentAccount(accountCurrent.id);
|
||||
|
||||
await Future.wait([
|
||||
_authenticationOIDCRepository.persistTokenOIDC(newTokenOIDC),
|
||||
_accountRepository.deleteCurrentAccount(accountCurrent.id),
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
newTokenOIDC.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
@@ -117,9 +111,7 @@ class DownloadAttachmentsInteractor {
|
||||
newToken: newTokenOIDC.toToken(),
|
||||
newConfig: oidcConfig);
|
||||
|
||||
final accountRequest = AccountRequest(
|
||||
token: newTokenOIDC.toToken(),
|
||||
authenticationType: AuthenticationType.oidc);
|
||||
final accountRequest = AccountRequest.withOidc(token: newTokenOIDC.toToken());
|
||||
|
||||
final taskIds = await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
|
||||
@@ -38,31 +38,24 @@ class ExportAttachmentInteractor {
|
||||
|
||||
if (currentAccount.authenticationType == AuthenticationType.oidc) {
|
||||
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
|
||||
accountRequest = AccountRequest(
|
||||
token: tokenOidc.toToken(),
|
||||
authenticationType: AuthenticationType.oidc);
|
||||
accountRequest = AccountRequest.withOidc(token: tokenOidc.toToken());
|
||||
} else {
|
||||
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
|
||||
if (authenticationInfoCache != null) {
|
||||
accountRequest = AccountRequest(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
authenticationType: AuthenticationType.basic);
|
||||
}
|
||||
accountRequest = AccountRequest.withBasic(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
);
|
||||
}
|
||||
|
||||
if (accountRequest != null) {
|
||||
final downloadedResponse = await emailRepository.exportAttachment(
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
cancelToken);
|
||||
final downloadedResponse = await emailRepository.exportAttachment(
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
cancelToken
|
||||
);
|
||||
|
||||
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
|
||||
} else {
|
||||
yield Left<Failure, Success>(ExportAttachmentFailure(null));
|
||||
}
|
||||
yield Right<Failure, Success>(ExportAttachmentSuccess(downloadedResponse));
|
||||
} catch (exception) {
|
||||
log('ExportAttachmentInteractor::execute(): exception: $exception');
|
||||
yield Left<Failure, Success>(ExportAttachmentFailure(exception));
|
||||
|
||||
@@ -74,6 +74,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/create_new
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_identities_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/datetime_extension.dart';
|
||||
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/model/rules_filter_creator_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart';
|
||||
import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart';
|
||||
import 'package:tmail_ui_user/main/error/capability_validator.dart';
|
||||
@@ -698,8 +699,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void _downloadAttachmentForWebAction(BuildContext context, Attachment attachment) async {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
if (accountId != null && mailboxDashBoardController.sessionCurrent != null) {
|
||||
final baseDownloadUrl = mailboxDashBoardController.sessionCurrent!.getDownloadUrl(jmapUrl: _dynamicUrlInterceptors.jmapUrl);
|
||||
final session = mailboxDashBoardController.sessionCurrent;
|
||||
if (accountId != null && session != null) {
|
||||
final baseDownloadUrl = session.getDownloadUrl(jmapUrl: _dynamicUrlInterceptors.jmapUrl);
|
||||
final generateTaskId = DownloadTaskId(_uuid.v4());
|
||||
consumeState(_downloadAttachmentForWebInteractor.execute(
|
||||
generateTaskId,
|
||||
@@ -707,6 +709,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
_downloadProgressStateController));
|
||||
} else {
|
||||
consumeState(Stream.value(
|
||||
Left(DownloadAttachmentForWebFailure(exception: NotFoundSessionException()))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,7 +727,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void _downloadAttachmentForWebFailureAction(DownloadAttachmentForWebFailure failure) {
|
||||
log('SingleEmailController::_downloadAttachmentForWebFailureAction(): $failure');
|
||||
mailboxDashBoardController.deleteDownloadTask(failure.taskId);
|
||||
if (failure.taskId != null) {
|
||||
mailboxDashBoardController.deleteDownloadTask(failure.taskId!);
|
||||
}
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
_appToast.showToastErrorMessage(
|
||||
|
||||
Reference in New Issue
Block a user