TF-1323 Fix can not attach image on mobile and web
This commit is contained in:
@@ -16,7 +16,7 @@ class ComposerRepositoryImpl extends ComposerRepository {
|
||||
this._composerDataSource);
|
||||
|
||||
@override
|
||||
UploadAttachment uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken}) {
|
||||
Future<UploadAttachment> uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken}) {
|
||||
return _attachmentUploadDataSource.uploadAttachment(fileInfo, uploadUri, cancelToken: cancelToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_attachment.dart';
|
||||
|
||||
abstract class ComposerRepository {
|
||||
UploadAttachment uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken});
|
||||
Future<UploadAttachment> uploadAttachment(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken});
|
||||
|
||||
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_attachment.dart';
|
||||
|
||||
class UploadAttachmentSuccess extends UIState {
|
||||
|
||||
final UploadAttachment uploadAttachment;
|
||||
final bool isInline;
|
||||
|
||||
UploadAttachmentSuccess(this.uploadAttachment, {this.isInline = false});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [uploadAttachment, isInline];
|
||||
}
|
||||
|
||||
class UploadAttachmentFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
final bool isInline;
|
||||
|
||||
UploadAttachmentFailure(this.exception, {this.isInline = false});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception, isInline];
|
||||
}
|
||||
@@ -1,14 +1,31 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/upload_attachment.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/upload_attachment_state.dart';
|
||||
|
||||
class UploadAttachmentInteractor {
|
||||
final ComposerRepository _composerRepository;
|
||||
|
||||
UploadAttachmentInteractor(this._composerRepository);
|
||||
|
||||
UploadAttachment execute(FileInfo fileInfo, Uri uploadUri, {CancelToken? cancelToken}) {
|
||||
return _composerRepository.uploadAttachment(fileInfo, uploadUri, cancelToken: cancelToken);
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
FileInfo fileInfo,
|
||||
Uri uploadUri, {
|
||||
CancelToken? cancelToken,
|
||||
bool isInline = false
|
||||
}) async* {
|
||||
try {
|
||||
final uploadAttachment = await _composerRepository.uploadAttachment(
|
||||
fileInfo,
|
||||
uploadUri,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
yield Right<Failure, Success>(UploadAttachmentSuccess(uploadAttachment, isInline: isInline));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(UploadAttachmentFailure(e, isInline: isInline));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import 'package:tmail_ui_user/features/upload/presentation/controller/upload_con
|
||||
import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:worker_manager/worker_manager.dart';
|
||||
|
||||
class ComposerBindings extends BaseBindings {
|
||||
@@ -67,7 +68,11 @@ class ComposerBindings extends BaseBindings {
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>()));
|
||||
Get.lazyPut(() => AttachmentUploadDataSourceImpl(
|
||||
Get.find<FileUploader>(),
|
||||
Get.find<Uuid>(),
|
||||
Get.find<RemoteExceptionThrower>()
|
||||
));
|
||||
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>(), Get.find<RemoteExceptionThrower>()));
|
||||
Get.lazyPut(() => ContactDataSourceImpl(Get.find<CacheExceptionThrower>()));
|
||||
Get.lazyPut(() => MailboxDataSourceImpl(
|
||||
|
||||
@@ -1445,7 +1445,7 @@ class ComposerController extends BaseController {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
if (session != null && accountId != null) {
|
||||
final uploadUri = session.getUploadUri(accountId);
|
||||
uploadController.uploadInlineImage(pickedFile, uploadUri);
|
||||
uploadController.uploadFileAction(pickedFile, uploadUri, isInline: true);
|
||||
}
|
||||
} else {
|
||||
if (currentContext != null) {
|
||||
|
||||
Reference in New Issue
Block a user