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