From 37783c0b1a1f86f86d8ea9399fe5db6fbcd6e004 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Tue, 28 May 2024 11:33:53 +0700 Subject: [PATCH 1/2] TW-1615: Support auto jump to lastest message when user send an attachment --- lib/pages/chat/chat.dart | 21 ++++++++++++++++--- lib/presentation/mixins/send_files_mixin.dart | 10 +++++++-- .../send_files_with_caption_web_mixin.dart | 2 ++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index cd23170cd3..e5e2515263 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -378,7 +378,12 @@ class ChatController extends State void handleDragDone(DropDoneDetails details) async { final matrixFiles = await onDragDone(details); - sendFileOnWebAction(context, room: room, matrixFilesList: matrixFiles); + sendFileOnWebAction( + context, + room: room, + matrixFilesList: matrixFiles, + onSendFileCallback: scrollDown, + ); } void _handleReceivedShareFiles() { @@ -1292,7 +1297,12 @@ class ChatController extends State _showMediaPicker(context); } else { final matrixFiles = await pickFilesFromSystem(); - sendFileOnWebAction(context, room: room, matrixFilesList: matrixFiles); + sendFileOnWebAction( + context, + room: room, + matrixFilesList: matrixFiles, + onSendFileCallback: scrollDown, + ); } } @@ -1309,6 +1319,7 @@ class ChatController extends State type: action, room: room, context: context, + onSendFileCallback: scrollDown, ), onSendTap: () { sendMedia( @@ -1316,9 +1327,13 @@ class ChatController extends State room: room, caption: _captionsController.text, ); + scrollDown(); _captionsController.clear(); }, - onCameraPicked: (_) => sendMedia(imagePickerController, room: room), + onCameraPicked: (_) { + sendMedia(imagePickerController, room: room); + scrollDown(); + }, captionController: _captionsController, focusSuggestionController: _focusSuggestionController, typeAheadKey: _chatMediaPickerTypeAheadKey, diff --git a/lib/presentation/mixins/send_files_mixin.dart b/lib/presentation/mixins/send_files_mixin.dart index 1b7fa60c87..3edc0e827f 100644 --- a/lib/presentation/mixins/send_files_mixin.dart +++ b/lib/presentation/mixins/send_files_mixin.dart @@ -34,6 +34,7 @@ mixin SendFilesMixin { BuildContext context, { Room? room, List? fileInfos, + VoidCallback? onSendFileCallback, }) async { if (room == null) {} final sendFileInteractor = getIt.get(); @@ -54,7 +55,7 @@ mixin SendFilesMixin { .toList(); if (fileInfos == null || fileInfos.isEmpty == true) return; - + onSendFileCallback?.call(); sendFileInteractor.execute(room: room!, fileInfos: fileInfos); } @@ -72,12 +73,17 @@ mixin SendFilesMixin { required BuildContext context, Room? room, required PickerType type, + VoidCallback? onSendFileCallback, }) async { switch (type) { case PickerType.gallery: break; case PickerType.documents: - sendFileAction(context, room: room); + sendFileAction( + context, + room: room, + onSendFileCallback: onSendFileCallback, + ); break; case PickerType.location: break; diff --git a/lib/presentation/mixins/send_files_with_caption_web_mixin.dart b/lib/presentation/mixins/send_files_with_caption_web_mixin.dart index 45949fa373..d657f1faed 100644 --- a/lib/presentation/mixins/send_files_with_caption_web_mixin.dart +++ b/lib/presentation/mixins/send_files_with_caption_web_mixin.dart @@ -12,6 +12,7 @@ mixin SendFilesWithCaptionWebMixin { BuildContext context, { Room? room, required List matrixFilesList, + VoidCallback? onSendFileCallback, }) async { if (matrixFilesList.length <= AppConfig.maxFilesSendPerDialog && matrixFilesList.isNotEmpty) { @@ -25,6 +26,7 @@ mixin SendFilesWithCaptionWebMixin { ); }, ); + onSendFileCallback?.call(); if (result is SendMediaWithCaptionStatus) { switch (result) { case SendMediaWithCaptionStatus.done: From 607fe1aaee773c8cf9624a80cddc830bf173c1eb Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Wed, 29 May 2024 09:06:07 +0700 Subject: [PATCH 2/2] TW-1615: Support auto jump to lastest message when use copy/paste --- lib/pages/chat/chat.dart | 4 +++- .../mixins/handle_clipboard_action_mixin.dart | 23 +++++++++++++++---- .../mixins/paste_image_mixin.dart | 14 ++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index e5e2515263..d373b84b1d 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -1891,7 +1891,9 @@ class ChatController extends State @override void initState() { _initializePinnedEvents(); - registerPasteShortcutListeners(); + registerPasteShortcutListeners( + onSendFileCallback: scrollDown, + ); keyboardVisibilitySubscription = keyboardVisibilityController.onChange.listen(_keyboardListener); scrollController.addListener(_updateScrollController); diff --git a/lib/presentation/mixins/handle_clipboard_action_mixin.dart b/lib/presentation/mixins/handle_clipboard_action_mixin.dart index c203eb39b3..581b690d7f 100644 --- a/lib/presentation/mixins/handle_clipboard_action_mixin.dart +++ b/lib/presentation/mixins/handle_clipboard_action_mixin.dart @@ -14,15 +14,25 @@ mixin HandleClipboardActionMixin on PasteImageMixin { TextEditingController get sendController; - void registerPasteShortcutListeners() { - ClipboardEvents.instance?.registerPasteEventListener(_onPasteEvent); + void registerPasteShortcutListeners({ + VoidCallback? onSendFileCallback, + }) { + ClipboardEvents.instance?.registerPasteEventListener( + (event) => _onPasteEvent( + event, + onSendFileCallback: onSendFileCallback, + ), + ); } void unregisterPasteShortcutListeners() { ClipboardEvents.instance?.unregisterPasteEventListener(_onPasteEvent); } - void _onPasteEvent(ClipboardReadEvent event) async { + void _onPasteEvent( + ClipboardReadEvent event, { + VoidCallback? onSendFileCallback, + }) async { if (chatFocusNode.hasFocus != true) { return; } @@ -30,7 +40,12 @@ mixin HandleClipboardActionMixin on PasteImageMixin { if (await TwakeClipboard.instance .isReadableImageFormat(clipboardReader: clipboardReader) && room != null) { - await pasteImage(context, room!, clipboardReader: clipboardReader); + await pasteImage( + context, + room!, + clipboardReader: clipboardReader, + onSendFileCallback: onSendFileCallback, + ); } else { sendController.pasteText(clipboardReader: clipboardReader); } diff --git a/lib/presentation/mixins/paste_image_mixin.dart b/lib/presentation/mixins/paste_image_mixin.dart index 7dff5f4421..73318f3128 100644 --- a/lib/presentation/mixins/paste_image_mixin.dart +++ b/lib/presentation/mixins/paste_image_mixin.dart @@ -1,4 +1,5 @@ import 'package:fluffychat/pages/chat/send_file_dialog/send_file_dialog.dart'; +import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart'; import 'package:fluffychat/utils/clipboard.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/twake_snackbar.dart'; @@ -12,6 +13,7 @@ mixin PasteImageMixin { BuildContext context, Room room, { ClipboardReader? clipboardReader, + VoidCallback? onSendFileCallback, }) async { if (!(await TwakeClipboard.instance .isReadableImageFormat(clipboardReader: clipboardReader))) { @@ -41,7 +43,7 @@ mixin PasteImageMixin { ) .cast() .toList(); - await showDialog( + final result = await showDialog( context: context, useRootNavigator: PlatformInfos.isWeb, builder: (context) { @@ -51,5 +53,15 @@ mixin PasteImageMixin { ); }, ); + if (result is SendMediaWithCaptionStatus) { + switch (result) { + case SendMediaWithCaptionStatus.done: + case SendMediaWithCaptionStatus.error: + onSendFileCallback?.call(); + break; + case SendMediaWithCaptionStatus.cancel: + break; + } + } } }