From b59078616123e940caca8c59f7d0369a9e5b776f Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 2 Feb 2024 16:23:54 +0700 Subject: [PATCH] TF-2532 Invoke request focus editor when insert inline image Signed-off-by: dab246 --- .../state/download_image_as_base64_state.dart | 5 ----- .../download_image_as_base64_interactor.dart | 2 -- .../presentation/composer_controller.dart | 2 -- .../rich_text_mobile_tablet_controller.dart | 21 +++++++------------ .../domain/state/attachment_upload_state.dart | 7 +------ .../controller/upload_controller.dart | 6 +----- .../upload_attachment_extension.dart | 3 +-- .../presentation/model/upload_file_state.dart | 5 ----- pubspec.lock | 6 +++--- 9 files changed, 14 insertions(+), 43 deletions(-) diff --git a/lib/features/composer/domain/state/download_image_as_base64_state.dart b/lib/features/composer/domain/state/download_image_as_base64_state.dart index af801f1a28..9eff070214 100644 --- a/lib/features/composer/domain/state/download_image_as_base64_state.dart +++ b/lib/features/composer/domain/state/download_image_as_base64_state.dart @@ -10,15 +10,11 @@ class DownloadImageAsBase64Success extends UIState { final String base64Uri; final String cid; final FileInfo fileInfo; - final bool fromFileShared; DownloadImageAsBase64Success( this.base64Uri, this.cid, this.fileInfo, - { - this.fromFileShared = false - } ); @override @@ -26,7 +22,6 @@ class DownloadImageAsBase64Success extends UIState { base64Uri, cid, fileInfo, - fromFileShared, ]; } diff --git a/lib/features/composer/domain/usecases/download_image_as_base64_interactor.dart b/lib/features/composer/domain/usecases/download_image_as_base64_interactor.dart index b3fb5d0ac5..b3417daa17 100644 --- a/lib/features/composer/domain/usecases/download_image_as_base64_interactor.dart +++ b/lib/features/composer/domain/usecases/download_image_as_base64_interactor.dart @@ -16,7 +16,6 @@ class DownloadImageAsBase64Interactor { { double? maxWidth, bool? compress, - bool fromFileShared = false, } ) async* { try { @@ -33,7 +32,6 @@ class DownloadImageAsBase64Interactor { result!, cid, fileInfo, - fromFileShared: fromFileShared )); } else { yield Left(DownloadImageAsBase64Failure(null)); diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 2934cc3b65..b2efe25287 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -283,7 +283,6 @@ class ComposerController extends BaseController { cid: success.cid, base64Uri: success.base64Uri ), - fromFileShare: success.fromFileShared ); } maxWithEditor = null; @@ -1863,7 +1862,6 @@ class ComposerController extends BaseController { uploadState.attachment.cid!, uploadState.fileInfo, maxWidth: maxWithEditor, - fromFileShared: uploadState.fromFileShared, )); } } diff --git a/lib/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart b/lib/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart index 50255814d0..ac45e2fab0 100644 --- a/lib/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart +++ b/lib/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart @@ -12,21 +12,16 @@ import 'package:tmail_ui_user/features/composer/presentation/model/inline_image. class RichTextMobileTabletController extends BaseRichTextController { HtmlEditorApi? htmlEditorApi; - void insertImage( - InlineImage image, - { - double? maxWithEditor, - bool fromFileShare = false - } - ) async { - log('RichTextMobileTabletController::insertImage(): $image | maxWithEditor: $maxWithEditor | $fromFileShare'); - if (image.source == ImageSource.network) { - htmlEditorApi?.insertImageLink(image.link!); + void insertImage(InlineImage inlineImage) async { + if (inlineImage.source == ImageSource.network) { + htmlEditorApi?.insertImageLink(inlineImage.link!); } else { - if (fromFileShare) { - await htmlEditorApi?.moveCursorAtLastNode(); + bool isEditorFocused = await htmlEditorApi?.hasFocus() ?? false; + log('RichTextMobileTabletController::insertImage: isEditorFocused = $isEditorFocused'); + if (!isEditorFocused) { + await htmlEditorApi?.requestFocusLastChild(); } - await htmlEditorApi?.insertHtml(image.base64Uri ?? ''); + await htmlEditorApi?.insertHtml('${inlineImage.base64Uri ?? ''}

'); } } diff --git a/lib/features/upload/domain/state/attachment_upload_state.dart b/lib/features/upload/domain/state/attachment_upload_state.dart index b5f0ee2f57..5b5b20cdfe 100644 --- a/lib/features/upload/domain/state/attachment_upload_state.dart +++ b/lib/features/upload/domain/state/attachment_upload_state.dart @@ -31,15 +31,11 @@ class SuccessAttachmentUploadState extends Success { final UploadTaskId uploadId; final Attachment attachment; final FileInfo fileInfo; - final bool fromFileShared; SuccessAttachmentUploadState( this.uploadId, this.attachment, - this.fileInfo, - { - this.fromFileShared = false - } + this.fileInfo ); @override @@ -47,7 +43,6 @@ class SuccessAttachmentUploadState extends Success { uploadId, attachment, fileInfo, - fromFileShared, ]; } diff --git a/lib/features/upload/presentation/controller/upload_controller.dart b/lib/features/upload/presentation/controller/upload_controller.dart index 7d5d23316e..4f61ac7482 100644 --- a/lib/features/upload/presentation/controller/upload_controller.dart +++ b/lib/features/upload/presentation/controller/upload_controller.dart @@ -155,9 +155,6 @@ class UploadController extends BaseController { cid: uuid.v1() ); - final uploadFileState = _uploadingStateInlineFiles.getUploadFileStateById(success.uploadId); - log('UploadController::_handleProgressUploadInlineImageStateStream:uploadId: ${uploadFileState?.uploadTaskId} | fromFileShared: ${uploadFileState?.fromFileShared}'); - _uploadingStateInlineFiles.updateElementByUploadTaskId( success.uploadId, (currentState) { @@ -173,7 +170,6 @@ class UploadController extends BaseController { success.uploadId, inlineAttachment, success.fileInfo, - fromFileShared: uploadFileState?.fromFileShared ?? false ); _handleUploadInlineAttachmentsSuccess(newUploadSuccess); } @@ -378,7 +374,7 @@ class UploadController extends BaseController { super.handleSuccessViewState(success); if (success is UploadAttachmentSuccess) { if (success.isInline) { - _uploadingStateInlineFiles.add(success.uploadAttachment.toUploadFileState(fromFileShared: success.fromFileShared)); + _uploadingStateInlineFiles.add(success.uploadAttachment.toUploadFileState()); await _progressUploadInlineImageStateStreamGroup.add(success.uploadAttachment.progressState); } else { _uploadingStateFiles.add(success.uploadAttachment.toUploadFileState()); diff --git a/lib/features/upload/presentation/extensions/upload_attachment_extension.dart b/lib/features/upload/presentation/extensions/upload_attachment_extension.dart index 4b45c9427b..64feed8fe7 100644 --- a/lib/features/upload/presentation/extensions/upload_attachment_extension.dart +++ b/lib/features/upload/presentation/extensions/upload_attachment_extension.dart @@ -4,12 +4,11 @@ import 'package:tmail_ui_user/features/upload/presentation/model/upload_file_sta extension UploadAttachmentExtension on UploadAttachment { - UploadFileState toUploadFileState({bool fromFileShared = false}) { + UploadFileState toUploadFileState() { return UploadFileState( uploadTaskId, file: fileInfo, cancelToken: cancelToken, - fromFileShared: fromFileShared, ); } } \ No newline at end of file diff --git a/lib/features/upload/presentation/model/upload_file_state.dart b/lib/features/upload/presentation/model/upload_file_state.dart index 20876fbe43..87df701b74 100644 --- a/lib/features/upload/presentation/model/upload_file_state.dart +++ b/lib/features/upload/presentation/model/upload_file_state.dart @@ -17,7 +17,6 @@ class UploadFileState with EquatableMixin { final int uploadingProgress; final Attachment? attachment; final CancelToken? cancelToken; - final bool fromFileShared; UploadFileState( this.uploadTaskId, @@ -27,7 +26,6 @@ class UploadFileState with EquatableMixin { this.uploadingProgress = 0, this.attachment, this.cancelToken, - this.fromFileShared = false, } ); @@ -38,7 +36,6 @@ class UploadFileState with EquatableMixin { int? uploadingProgress, Attachment? attachment, CancelToken? cancelToken, - bool? fromFileShared, }) { return UploadFileState( uploadTaskId ?? this.uploadTaskId, @@ -47,7 +44,6 @@ class UploadFileState with EquatableMixin { uploadingProgress: uploadingProgress ?? this.uploadingProgress, attachment: attachment ?? this.attachment, cancelToken: cancelToken ?? this.cancelToken, - fromFileShared: fromFileShared ?? this.fromFileShared ); } @@ -87,6 +83,5 @@ class UploadFileState with EquatableMixin { uploadingProgress, attachment, cancelToken, - fromFileShared, ]; } diff --git a/pubspec.lock b/pubspec.lock index 9d3d64d3b5..f53aad6451 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -404,8 +404,8 @@ packages: dependency: transitive description: path: "." - ref: "bugfix/build-failed-on-android" - resolved-ref: "33991d46432a22a79b5d3593262033ae49da77f6" + ref: email_supported + resolved-ref: "562ef89121d2ea8b12340cdf0998104b3fc25857" url: "https://github.com/linagora/enough_html_editor.git" source: git version: "0.0.5" @@ -1540,7 +1540,7 @@ packages: description: path: "." ref: master - resolved-ref: "9c0eb7e3627af6ba6860e986ec6ac1f6f170c71d" + resolved-ref: "91809cfa3095b71f3cce04e8f29f38c238d2e770" url: "https://github.com/linagora/rich-text-composer.git" source: git version: "0.0.2"