From 0201242f3ac349e40a42dc37081ebf027c6c0a70 Mon Sep 17 00:00:00 2001 From: ManhNTX Date: Fri, 19 Aug 2022 00:55:08 +0700 Subject: [PATCH] TF-831: add set forward to module --- .../forward_id_nullable_converter.dart | 13 +++ forward/lib/forward/tmail_forward.dart | 8 +- .../mails_forward_creator_binding.dart | 72 ++++++++++++++++ .../mails_forward_creator_controller.dart | 86 +++++++++++++++++++ .../mails_forward_creator_view.dart | 0 .../mails_forward_creator_arguments.dart | 12 +++ 6 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 forward/lib/forward/converter/forward_id_nullable_converter.dart create mode 100644 lib/features/mails_forward_creator/presentation/mails_forward_creator_binding.dart create mode 100644 lib/features/mails_forward_creator/presentation/mails_forward_creator_controller.dart create mode 100644 lib/features/mails_forward_creator/presentation/mails_forward_creator_view.dart create mode 100644 lib/features/mails_forward_creator/presentation/model/mails_forward_creator_arguments.dart diff --git a/forward/lib/forward/converter/forward_id_nullable_converter.dart b/forward/lib/forward/converter/forward_id_nullable_converter.dart new file mode 100644 index 000000000..4ed6c7fbe --- /dev/null +++ b/forward/lib/forward/converter/forward_id_nullable_converter.dart @@ -0,0 +1,13 @@ +import 'package:forward/forward/forward_id.dart'; +import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:json_annotation/json_annotation.dart'; + +class ForwardIdNullableConverter implements JsonConverter { + const ForwardIdNullableConverter(); + + @override + ForwardId? fromJson(String? json) => json != null ? ForwardId(id: Id(json)) : null; + + @override + String? toJson(ForwardId? object) => object?.id.value; +} diff --git a/forward/lib/forward/tmail_forward.dart b/forward/lib/forward/tmail_forward.dart index a9c7e4c45..28011d881 100644 --- a/forward/lib/forward/tmail_forward.dart +++ b/forward/lib/forward/tmail_forward.dart @@ -1,4 +1,5 @@ import 'package:forward/forward/converter/forward_id_coverter.dart'; +import 'package:forward/forward/converter/forward_id_nullable_converter.dart'; import 'package:forward/forward/forward.dart'; import 'package:forward/forward/forward_id.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -6,13 +7,14 @@ import 'package:json_annotation/json_annotation.dart'; part 'tmail_forward.g.dart'; @ForwardIdConverter() -@JsonSerializable() +@ForwardIdNullableConverter() +@JsonSerializable(explicitToJson: true, includeIfNull: false) class TMailForward extends Forward { - final ForwardId id; + final ForwardId? id; final bool localCopy; final Set forwards; TMailForward({ - required this.id, + this.id, required this.localCopy, required this.forwards, }); diff --git a/lib/features/mails_forward_creator/presentation/mails_forward_creator_binding.dart b/lib/features/mails_forward_creator/presentation/mails_forward_creator_binding.dart new file mode 100644 index 000000000..00783459e --- /dev/null +++ b/lib/features/mails_forward_creator/presentation/mails_forward_creator_binding.dart @@ -0,0 +1,72 @@ +import 'package:contact/data/datasource/auto_complete_datasource.dart'; +import 'package:contact/data/datasource_impl/tmail_contact_datasource_impl.dart'; +import 'package:contact/data/network/contact_api.dart'; +import 'package:core/data/model/source_type/data_source_type.dart'; +import 'package:get/get.dart'; +import 'package:tmail_ui_user/features/base/base_bindings.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart'; +import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; +import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/autocomplete_bindings.dart'; +import 'package:tmail_ui_user/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart'; + +class MailsForwardCreatorBindings extends BaseBindings { + + @override + void dependencies() { + _bindingsUtils(); + super.dependencies(); + } + + void _bindingsUtils() { + Get.lazyPut(() => AutoCompleteBindings()); + } + + @override + void bindingsController() { + Get.lazyPut(() => RulesFilterCreatorController( + Get.find(), + Get.find(), + Get.find() + )); + } + + @override + void bindingsDataSource() { + Get.lazyPut(() => Get.find()); + Get.lazyPut(() => Get.find()); + } + + @override + void bindingsDataSourceImpl() { + Get.lazyPut(() => TMailContactDataSourceImpl(Get.find())); + } + + @override + void bindingsInteractor() { + Get.lazyPut(() => VerifyNameInteractor()); + Get.lazyPut(() => GetAllMailboxInteractor(Get.find())); + } + + @override + void bindingsRepository() { + Get.lazyPut(() => Get.find()); + } + + @override + void bindingsRepositoryImpl() { + Get.lazyPut(() => MailboxRepositoryImpl( + { + DataSourceType.network: Get.find(), + DataSourceType.local: Get.find() + }, + Get.find(), + )); + } +} \ No newline at end of file diff --git a/lib/features/mails_forward_creator/presentation/mails_forward_creator_controller.dart b/lib/features/mails_forward_creator/presentation/mails_forward_creator_controller.dart new file mode 100644 index 000000000..8bb37a69c --- /dev/null +++ b/lib/features/mails_forward_creator/presentation/mails_forward_creator_controller.dart @@ -0,0 +1,86 @@ + +import 'package:core/utils/app_logger.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:get/get.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; +import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/base/base_controller.dart'; +import 'package:tmail_ui_user/features/composer/domain/model/contact_suggestion_source.dart'; +import 'package:tmail_ui_user/features/composer/domain/state/get_autocomplete_state.dart'; +import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_interactor.dart'; +import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_with_device_contact_interactor.dart'; +import 'package:tmail_ui_user/features/mails_forward_creator/presentation/model/mails_forward_creator_arguments.dart'; +import 'package:tmail_ui_user/main/routes/route_navigation.dart'; + +class RulesFilterCreatorController extends BaseController { + + final inputEmailForwardController = TextEditingController(); + final ContactSuggestionSource _contactSuggestionSource = ContactSuggestionSource.tMailContact; + + late AccountId _accountId; + late GetAutoCompleteWithDeviceContactInteractor _getAutoCompleteWithDeviceContactInteractor; + late GetAutoCompleteInteractor _getAutoCompleteInteractor; + + final listEmailForwards = [].obs; + + RulesFilterCreatorController( + this._getAutoCompleteWithDeviceContactInteractor, + this._getAutoCompleteInteractor, + ); + + @override + void onReady() { + _getArguments(); + super.onReady(); + } + + @override + void onClose() { + inputEmailForwardController.dispose(); + super.onClose(); + } + + @override + void onDone() {} + + @override + void onError(error) {} + + void _getArguments() { + final arguments = Get.arguments; + if (arguments is MailsForwardCreatorArguments) { + _accountId = arguments.accountId; + } + } + + Future> getAutoCompleteSuggestion( + {required String word}) async { + log('ComposerController::getAutoCompleteSuggestion(): $word | $_contactSuggestionSource'); + + _getAutoCompleteWithDeviceContactInteractor = Get.find(); + _getAutoCompleteInteractor = Get.find(); + + if (_contactSuggestionSource == ContactSuggestionSource.all) { + return await _getAutoCompleteWithDeviceContactInteractor + .execute(AutoCompletePattern(word: word, accountId: _accountId)) + .then((value) => value.fold( + (failure) => [], + (success) => success is GetAutoCompleteSuccess ? success.listEmailAddress : [])); + } + return await _getAutoCompleteInteractor + .execute(AutoCompletePattern(word: word, accountId: _accountId)) + .then((value) => value.fold( + (failure) => [], + (success) => success is GetAutoCompleteSuccess ? success.listEmailAddress : [])); + } + + void _clearAll() { + inputEmailForwardController.clear(); + } + + void closeView(BuildContext context) { + FocusScope.of(context).unfocus(); + popBack(); + } +} \ No newline at end of file diff --git a/lib/features/mails_forward_creator/presentation/mails_forward_creator_view.dart b/lib/features/mails_forward_creator/presentation/mails_forward_creator_view.dart new file mode 100644 index 000000000..e69de29bb diff --git a/lib/features/mails_forward_creator/presentation/model/mails_forward_creator_arguments.dart b/lib/features/mails_forward_creator/presentation/model/mails_forward_creator_arguments.dart new file mode 100644 index 000000000..bc7a2c5da --- /dev/null +++ b/lib/features/mails_forward_creator/presentation/model/mails_forward_creator_arguments.dart @@ -0,0 +1,12 @@ + +import 'package:equatable/equatable.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; + +class MailsForwardCreatorArguments with EquatableMixin { + final AccountId accountId; + + MailsForwardCreatorArguments(this.accountId); + + @override + List get props => [accountId]; +} \ No newline at end of file