TF-654 Update datasource/repository for download attachment on web

This commit is contained in:
dab246
2022-08-06 19:51:25 +07:00
committed by Dat H. Pham
parent 88ca9dbc9a
commit 6ad10cad4a
6 changed files with 121 additions and 21 deletions
@@ -1,4 +1,8 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
@@ -28,11 +32,13 @@ abstract class EmailDataSource {
CancelToken cancelToken
);
Future<bool> downloadAttachmentForWeb(
Future<Uint8List> downloadAttachmentForWeb(
DownloadTaskId taskId,
Attachment attachment,
AccountId accountId,
String baseDownloadUrl,
AccountRequest accountRequest,
StreamController<Either<Failure, Success>> onReceiveController
);
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:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
@@ -116,9 +120,22 @@ class EmailDataSourceImpl extends EmailDataSource {
}
@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 await emailAPI.downloadAttachmentForWeb(attachment, accountId, baseDownloadUrl, accountRequest);
return await emailAPI.downloadAttachmentForWeb(
taskId,
attachment,
accountId,
baseDownloadUrl,
accountRequest,
onReceiveController);
}).catchError((error) {
throw error;
});
@@ -1,5 +1,9 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
@@ -106,8 +110,21 @@ class EmailRepositoryImpl extends EmailRepository {
}
@override
Future<bool> downloadAttachmentForWeb(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
return emailDataSource.downloadAttachmentForWeb(attachment, accountId, baseDownloadUrl, accountRequest);
Future<Uint8List> downloadAttachmentForWeb(
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