TF-654 Update datasource/repository for download attachment on web
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -28,11 +32,13 @@ abstract class EmailDataSource {
|
|||||||
CancelToken cancelToken
|
CancelToken cancelToken
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<bool> downloadAttachmentForWeb(
|
Future<Uint8List> downloadAttachmentForWeb(
|
||||||
|
DownloadTaskId taskId,
|
||||||
Attachment attachment,
|
Attachment attachment,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
String baseDownloadUrl,
|
String baseDownloadUrl,
|
||||||
AccountRequest accountRequest,
|
AccountRequest accountRequest,
|
||||||
|
StreamController<Either<Failure, Success>> onReceiveController
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveToMailboxRequest moveRequest);
|
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveToMailboxRequest moveRequest);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -116,9 +120,22 @@ class EmailDataSourceImpl extends EmailDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> downloadAttachmentForWeb(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
|
Future<Uint8List> downloadAttachmentForWeb(
|
||||||
|
DownloadTaskId taskId,
|
||||||
|
Attachment attachment,
|
||||||
|
AccountId accountId,
|
||||||
|
String baseDownloadUrl,
|
||||||
|
AccountRequest accountRequest,
|
||||||
|
StreamController<Either<Failure, Success>> onReceiveController
|
||||||
|
) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
return await emailAPI.downloadAttachmentForWeb(attachment, accountId, baseDownloadUrl, accountRequest);
|
return await emailAPI.downloadAttachmentForWeb(
|
||||||
|
taskId,
|
||||||
|
attachment,
|
||||||
|
accountId,
|
||||||
|
baseDownloadUrl,
|
||||||
|
accountRequest,
|
||||||
|
onReceiveController);
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -106,8 +110,21 @@ class EmailRepositoryImpl extends EmailRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> downloadAttachmentForWeb(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
|
Future<Uint8List> downloadAttachmentForWeb(
|
||||||
return emailDataSource.downloadAttachmentForWeb(attachment, accountId, baseDownloadUrl, accountRequest);
|
DownloadTaskId taskId,
|
||||||
|
Attachment attachment,
|
||||||
|
AccountId accountId,
|
||||||
|
String baseDownloadUrl,
|
||||||
|
AccountRequest accountRequest,
|
||||||
|
StreamController<Either<Failure, Success>> onReceiveController
|
||||||
|
) {
|
||||||
|
return emailDataSource.downloadAttachmentForWeb(
|
||||||
|
taskId,
|
||||||
|
attachment,
|
||||||
|
accountId,
|
||||||
|
baseDownloadUrl,
|
||||||
|
accountRequest,
|
||||||
|
onReceiveController);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -28,11 +32,13 @@ abstract class EmailRepository {
|
|||||||
CancelToken cancelToken
|
CancelToken cancelToken
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<bool> downloadAttachmentForWeb(
|
Future<Uint8List> downloadAttachmentForWeb(
|
||||||
|
DownloadTaskId taskId,
|
||||||
Attachment attachment,
|
Attachment attachment,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
String baseDownloadUrl,
|
String baseDownloadUrl,
|
||||||
AccountRequest accountRequest,
|
AccountRequest accountRequest,
|
||||||
|
StreamController<Either<Failure, Success>> onReceiveController
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveToMailboxRequest moveRequest);
|
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveToMailboxRequest moveRequest);
|
||||||
|
|||||||
@@ -1,18 +1,64 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:model/model.dart';
|
||||||
|
|
||||||
|
class StartDownloadAttachmentForWeb extends UIState {
|
||||||
|
|
||||||
|
final DownloadTaskId taskId;
|
||||||
|
final Attachment attachment;
|
||||||
|
|
||||||
|
StartDownloadAttachmentForWeb(this.taskId, this.attachment);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [taskId, attachment];
|
||||||
|
}
|
||||||
|
|
||||||
|
class DownloadingAttachmentForWeb extends UIState {
|
||||||
|
|
||||||
|
final DownloadTaskId taskId;
|
||||||
|
final Attachment attachment;
|
||||||
|
final double progress;
|
||||||
|
final int downloaded;
|
||||||
|
final int total;
|
||||||
|
|
||||||
|
DownloadingAttachmentForWeb(
|
||||||
|
this.taskId,
|
||||||
|
this.attachment,
|
||||||
|
this.progress,
|
||||||
|
this.downloaded,
|
||||||
|
this.total
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [
|
||||||
|
taskId,
|
||||||
|
attachment,
|
||||||
|
progress,
|
||||||
|
downloaded,
|
||||||
|
total
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
class DownloadAttachmentForWebSuccess extends UIState {
|
class DownloadAttachmentForWebSuccess extends UIState {
|
||||||
|
|
||||||
DownloadAttachmentForWebSuccess();
|
final DownloadTaskId taskId;
|
||||||
|
final Attachment attachment;
|
||||||
|
final Uint8List bytes;
|
||||||
|
|
||||||
|
DownloadAttachmentForWebSuccess(this.taskId, this.attachment, this.bytes);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [taskId, attachment, bytes];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadAttachmentForWebFailure extends FeatureFailure {
|
class DownloadAttachmentForWebFailure extends FeatureFailure {
|
||||||
|
|
||||||
|
final DownloadTaskId taskId;
|
||||||
final dynamic exception;
|
final dynamic exception;
|
||||||
|
|
||||||
DownloadAttachmentForWebFailure(this.exception);
|
DownloadAttachmentForWebFailure(this.taskId, this.exception);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [exception];
|
List<Object> get props => [taskId, exception];
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:core/presentation/state/failure.dart';
|
import 'package:core/presentation/state/failure.dart';
|
||||||
import 'package:core/presentation/state/success.dart';
|
import 'package:core/presentation/state/success.dart';
|
||||||
import 'package:core/utils/app_logger.dart';
|
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:model/account/account_request.dart';
|
import 'package:model/account/account_request.dart';
|
||||||
import 'package:model/account/authentication_type.dart';
|
import 'package:model/account/authentication_type.dart';
|
||||||
import 'package:model/account/password.dart';
|
import 'package:model/account/password.dart';
|
||||||
import 'package:model/account/user_name.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/email/attachment.dart';
|
||||||
import 'package:model/oidc/token_oidc.dart';
|
import 'package:model/oidc/token_oidc.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||||
@@ -30,14 +30,19 @@ class DownloadAttachmentForWebInteractor {
|
|||||||
this._authenticationOIDCRepository);
|
this._authenticationOIDCRepository);
|
||||||
|
|
||||||
Stream<Either<Failure, Success>> execute(
|
Stream<Either<Failure, Success>> execute(
|
||||||
|
DownloadTaskId taskId,
|
||||||
Attachment attachment,
|
Attachment attachment,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
String baseDownloadUrl
|
String baseDownloadUrl,
|
||||||
|
StreamController<Either<Failure, Success>> onReceiveController
|
||||||
) async* {
|
) async* {
|
||||||
try {
|
try {
|
||||||
|
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment));
|
||||||
|
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment)));
|
||||||
|
|
||||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||||
|
|
||||||
final result = await Future.wait([
|
final bytesDownloaded = await Future.wait([
|
||||||
if (currentAccount.authenticationType == AuthenticationType.oidc)
|
if (currentAccount.authenticationType == AuthenticationType.oidc)
|
||||||
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
|
_authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id)
|
||||||
else
|
else
|
||||||
@@ -61,20 +66,23 @@ class DownloadAttachmentForWebInteractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await emailRepository.downloadAttachmentForWeb(
|
return await emailRepository.downloadAttachmentForWeb(
|
||||||
|
taskId,
|
||||||
attachment,
|
attachment,
|
||||||
accountId,
|
accountId,
|
||||||
baseDownloadUrl,
|
baseDownloadUrl,
|
||||||
accountRequest);
|
accountRequest,
|
||||||
|
onReceiveController
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess(
|
||||||
yield Right<Failure, Success>(DownloadAttachmentForWebSuccess());
|
taskId,
|
||||||
} else {
|
attachment,
|
||||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(null));
|
bytesDownloaded));
|
||||||
}
|
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
log('DownloadAttachmentForWebInteractor::execute(): exception: $exception');
|
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(
|
||||||
yield Left<Failure, Success>(DownloadAttachmentForWebFailure(exception));
|
taskId,
|
||||||
|
exception));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user