TF-654 Update datasource/repository for download attachment on web
This commit is contained in:
@@ -2,13 +2,13 @@ import 'dart:async';
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/user_name.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
@@ -30,14 +30,19 @@ class DownloadAttachmentForWebInteractor {
|
||||
this._authenticationOIDCRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl
|
||||
String baseDownloadUrl,
|
||||
StreamController<Either<Failure, Success>> onReceiveController
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment));
|
||||
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment)));
|
||||
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
|
||||
final result = await Future.wait([
|
||||
final bytesDownloaded = await Future.wait([
|
||||
if (currentAccount.authenticationType == AuthenticationType.oidc)
|
||||
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
|
||||
else
|
||||
@@ -61,20 +66,23 @@ class DownloadAttachmentForWebInteractor {
|
||||
}
|
||||
|
||||
return await emailRepository.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest);
|
||||
accountRequest,
|
||||
onReceiveController
|
||||
);
|
||||
});
|
||||
|
||||
if (result) {
|
||||
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess());
|
||||
} else {
|
||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(null));
|
||||
}
|
||||
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess(
|
||||
taskId,
|
||||
attachment,
|
||||
bytesDownloaded));
|
||||
} catch (exception) {
|
||||
log('DownloadAttachmentForWebInteractor::execute(): exception: $exception');
|
||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(exception));
|
||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(
|
||||
taskId,
|
||||
exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user