TF-4058 Remove class/object are not used
This commit is contained in:
@@ -49,7 +49,6 @@ export 'utils/platform_info.dart';
|
|||||||
export 'utils/file_utils.dart';
|
export 'utils/file_utils.dart';
|
||||||
export 'utils/option_param_mixin.dart';
|
export 'utils/option_param_mixin.dart';
|
||||||
export 'utils/print_utils.dart';
|
export 'utils/print_utils.dart';
|
||||||
export 'utils/broadcast_channel/broadcast_channel.dart';
|
|
||||||
export 'utils/list_utils.dart';
|
export 'utils/list_utils.dart';
|
||||||
export 'utils/mail/domain.dart';
|
export 'utils/mail/domain.dart';
|
||||||
export 'utils/mail/mail_address.dart';
|
export 'utils/mail/mail_address.dart';
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export 'broadcast_channel_stub.dart' if (dart.library.html) 'broadcast_channel_web.dart';
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
class BroadcastChannel {
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
BroadcastChannel(this.name);
|
|
||||||
|
|
||||||
Stream<dynamic> get onMessage => const Stream.empty();
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export 'dart:html' show BroadcastChannel;
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import 'package:core/data/model/source_type/data_source_type.dart';
|
|
||||||
import 'package:core/presentation/resources/image_paths.dart';
|
|
||||||
import 'package:core/utils/file_utils.dart';
|
|
||||||
import 'package:core/utils/preview_eml_file_utils.dart';
|
|
||||||
import 'package:core/utils/print_utils.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
|
|
||||||
import 'package:tmail_ui_user/features/caching/utils/local_storage_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/caching/utils/session_storage_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource/email_datasource.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource/html_datasource.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource/print_file_datasource.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_local_storage_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_session_storage_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/html_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/print_file_datasource_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.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/mailbox_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/local/mailbox_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.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/offline_mode/manager/new_email_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/manager/new_email_cache_worker_queue.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/manager/opened_email_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/manager/opened_email_cache_worker_queue.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/manager/sending_email_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/server_settings/data/datasource/server_settings_data_source.dart';
|
|
||||||
import 'package:tmail_ui_user/features/server_settings/data/datasource_impl/remote_server_settings_data_source_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/server_settings/data/network/server_settings_api.dart';
|
|
||||||
import 'package:tmail_ui_user/features/server_settings/data/repository/server_settings_repository_impl.dart';
|
|
||||||
import 'package:tmail_ui_user/features/server_settings/domain/repository/server_settings_repository.dart';
|
|
||||||
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.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:tmail_ui_user/main/utils/ios_sharing_manager.dart';
|
|
||||||
|
|
||||||
class SendEmailInteractorBindings extends InteractorsBindings {
|
|
||||||
|
|
||||||
@override
|
|
||||||
void bindingsDataSource() {
|
|
||||||
Get.lazyPut<EmailDataSource>(() => Get.find<EmailDataSourceImpl>());
|
|
||||||
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
|
||||||
Get.lazyPut<HtmlDataSource>(() => Get.find<HtmlDataSourceImpl>());
|
|
||||||
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
|
|
||||||
Get.lazyPut<PrintFileDataSource>(() => Get.find<PrintFileDataSourceImpl>());
|
|
||||||
Get.lazyPut<ServerSettingsDataSource>(() => Get.find<RemoteServerSettingsDataSourceImpl>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void bindingsDataSourceImpl() {
|
|
||||||
Get.lazyPut(() => EmailDataSourceImpl(
|
|
||||||
Get.find<EmailAPI>(),
|
|
||||||
Get.find<RemoteExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => MailboxDataSourceImpl(
|
|
||||||
Get.find<MailboxAPI>(),
|
|
||||||
Get.find<MailboxIsolateWorker>(),
|
|
||||||
Get.find<RemoteExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => MailboxCacheDataSourceImpl(
|
|
||||||
Get.find<MailboxCacheManager>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => HtmlDataSourceImpl(
|
|
||||||
Get.find<HtmlAnalyzer>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => StateDataSourceImpl(
|
|
||||||
Get.find<StateCacheManager>(),
|
|
||||||
Get.find<IOSSharingManager>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => PrintFileDataSourceImpl(
|
|
||||||
Get.find<PrintUtils>(),
|
|
||||||
Get.find<ImagePaths>(),
|
|
||||||
Get.find<FileUtils>(),
|
|
||||||
Get.find<HtmlAnalyzer>(),
|
|
||||||
Get.find<CacheExceptionThrower>(),
|
|
||||||
));
|
|
||||||
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
|
|
||||||
Get.find<NewEmailCacheManager>(),
|
|
||||||
Get.find<OpenedEmailCacheManager>(),
|
|
||||||
Get.find<NewEmailCacheWorkerQueue>(),
|
|
||||||
Get.find<OpenedEmailCacheWorkerQueue>(),
|
|
||||||
Get.find<EmailCacheManager>(),
|
|
||||||
Get.find<SendingEmailCacheManager>(),
|
|
||||||
Get.find<FileUtils>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => EmailLocalStorageDataSourceImpl(
|
|
||||||
Get.find<LocalStorageManager>(),
|
|
||||||
Get.find<PreviewEmlFileUtils>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => EmailSessionStorageDatasourceImpl(
|
|
||||||
Get.find<SessionStorageManager>(),
|
|
||||||
Get.find<CacheExceptionThrower>()));
|
|
||||||
Get.lazyPut(() => RemoteServerSettingsDataSourceImpl(
|
|
||||||
Get.find<ServerSettingsAPI>(),
|
|
||||||
Get.find<RemoteExceptionThrower>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void bindingsInteractor() {
|
|
||||||
Get.lazyPut(() => SendEmailInteractor(Get.find<EmailRepository>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void bindingsRepository() {
|
|
||||||
Get.lazyPut<EmailRepository>(() => Get.find<EmailRepositoryImpl>());
|
|
||||||
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
|
||||||
Get.lazyPut<ServerSettingsRepository>(() => Get.find<ServerSettingsRepositoryImpl>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void bindingsRepositoryImpl() {
|
|
||||||
Get.lazyPut(() => EmailRepositoryImpl(
|
|
||||||
{
|
|
||||||
DataSourceType.network: Get.find<EmailDataSource>(),
|
|
||||||
DataSourceType.hiveCache: Get.find<EmailHiveCacheDataSourceImpl>(),
|
|
||||||
DataSourceType.local: Get.find<EmailLocalStorageDataSourceImpl>(),
|
|
||||||
DataSourceType.session: Get.find<EmailSessionStorageDatasourceImpl>(),
|
|
||||||
},
|
|
||||||
Get.find<HtmlDataSource>(),
|
|
||||||
Get.find<StateDataSource>(),
|
|
||||||
Get.find<PrintFileDataSource>(),
|
|
||||||
));
|
|
||||||
Get.lazyPut(() => MailboxRepositoryImpl(
|
|
||||||
{
|
|
||||||
DataSourceType.network: Get.find<MailboxDataSource>(),
|
|
||||||
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
|
|
||||||
},
|
|
||||||
Get.find<StateDataSource>(),
|
|
||||||
));
|
|
||||||
Get.lazyPut(() => ServerSettingsRepositoryImpl(
|
|
||||||
Get.find<ServerSettingsDataSource>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
import 'package:core/core.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/work_dispatcher.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
class WorkManagerConfig {
|
|
||||||
static WorkManagerConfig? _instance;
|
|
||||||
|
|
||||||
WorkManagerConfig._();
|
|
||||||
|
|
||||||
factory WorkManagerConfig() => _instance ??= WorkManagerConfig._();
|
|
||||||
|
|
||||||
Future<void> initialize() {
|
|
||||||
return Workmanager().initialize(
|
|
||||||
callbackDispatcher,
|
|
||||||
isInDebugMode: BuildUtils.isDebugMode
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
class WorkManagerConstants {
|
|
||||||
static const String workerTypeKey = 'worker_type';
|
|
||||||
static const int delayTime = 2000;
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
import 'package:core/utils/app_logger.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_constants.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/exceptions/workmanager_exception.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/one_time_work_request.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/periodic_work_request.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/work_request.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker_type.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
class WorkManagerController {
|
|
||||||
|
|
||||||
static WorkManagerController? _instance;
|
|
||||||
|
|
||||||
WorkManagerController._();
|
|
||||||
|
|
||||||
factory WorkManagerController() => _instance ??= WorkManagerController._();
|
|
||||||
|
|
||||||
Future<void> enqueue(WorkRequest workRequest) async {
|
|
||||||
try {
|
|
||||||
log('WorkSchedulerController::enqueue():workRequest: $workRequest');
|
|
||||||
if (workRequest is OneTimeWorkRequest) {
|
|
||||||
await Workmanager().registerOneOffTask(
|
|
||||||
workRequest.uniqueId,
|
|
||||||
workRequest.taskId,
|
|
||||||
tag: workRequest.tag,
|
|
||||||
initialDelay: workRequest.initialDelay,
|
|
||||||
constraints: workRequest.constraints,
|
|
||||||
backoffPolicy: workRequest.backoffPolicy,
|
|
||||||
backoffPolicyDelay: workRequest.backoffPolicyDelay,
|
|
||||||
outOfQuotaPolicy: workRequest.outOfQuotaPolicy,
|
|
||||||
inputData: workRequest.inputData
|
|
||||||
);
|
|
||||||
} if (workRequest is PeriodicWorkRequest) {
|
|
||||||
await Workmanager().registerPeriodicTask(
|
|
||||||
workRequest.uniqueId,
|
|
||||||
workRequest.taskId,
|
|
||||||
tag: workRequest.tag,
|
|
||||||
frequency: workRequest.frequency,
|
|
||||||
initialDelay: workRequest.initialDelay,
|
|
||||||
constraints: workRequest.constraints,
|
|
||||||
backoffPolicy: workRequest.backoffPolicy,
|
|
||||||
backoffPolicyDelay: workRequest.backoffPolicyDelay,
|
|
||||||
outOfQuotaPolicy: workRequest.outOfQuotaPolicy,
|
|
||||||
inputData: workRequest.inputData
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
logError('WorkSchedulerController::enqueue(): EXCEPTION: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> handleBackgroundTask(String taskName, Map<String, dynamic>? inputData) async {
|
|
||||||
log('WorkSchedulerController::handleBackgroundTask():taskName: $taskName | inputData: $inputData');
|
|
||||||
try {
|
|
||||||
if (inputData != null && inputData.isNotEmpty) {
|
|
||||||
final workerType = inputData.remove(WorkManagerConstants.workerTypeKey);
|
|
||||||
final dataObject = inputData;
|
|
||||||
log('WorkSchedulerController::handleBackgroundTask():workerType: $workerType | dataObject: $dataObject');
|
|
||||||
final matchedType = WorkerType.values.firstWhereOrNull((type) => type.name == workerType);
|
|
||||||
|
|
||||||
if (matchedType != null) {
|
|
||||||
final worker = matchedType.getWorker();
|
|
||||||
await worker.bindDI();
|
|
||||||
final result = await worker.doWork(taskName, dataObject);
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
return Future.error(CanNotFoundWorkerType());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Future.error(CanNotFoundInputData());
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
logError('WorkSchedulerController::handleBackgroundTask():EXCEPTION: $e');
|
|
||||||
return Future.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> cancelByWorkType(WorkerType type) => Workmanager().cancelByTag(type.name);
|
|
||||||
|
|
||||||
Future<void> cancelByUniqueId(String uniqueId) {
|
|
||||||
try {
|
|
||||||
return Workmanager().cancelByUniqueName(uniqueId);
|
|
||||||
} catch (e) {
|
|
||||||
logError('WorkSchedulerController::cancelByUniqueId():EXCEPTION: $e');
|
|
||||||
return Future.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> cancelAll() => Workmanager().cancelAll();
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
class CanNotFoundInputData implements Exception {}
|
|
||||||
|
|
||||||
class CanNotFoundWorkerType implements Exception {}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/work_request.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
/// A WorkRequest for non-repeating work.
|
|
||||||
class OneTimeWorkRequest extends WorkRequest {
|
|
||||||
OneTimeWorkRequest({
|
|
||||||
required String uniqueId,
|
|
||||||
required String taskId,
|
|
||||||
String? tag,
|
|
||||||
Map<String, dynamic>? inputData,
|
|
||||||
Duration initialDelay = Duration.zero,
|
|
||||||
Duration backoffPolicyDelay = Duration.zero,
|
|
||||||
ExistingWorkPolicy? existingWorkPolicy,
|
|
||||||
BackoffPolicy? backoffPolicy,
|
|
||||||
OutOfQuotaPolicy? outOfQuotaPolicy,
|
|
||||||
Constraints? constraints
|
|
||||||
}) : super(
|
|
||||||
uniqueId: uniqueId,
|
|
||||||
taskId: taskId,
|
|
||||||
tag: tag,
|
|
||||||
inputData: inputData,
|
|
||||||
initialDelay: initialDelay,
|
|
||||||
backoffPolicyDelay: backoffPolicyDelay,
|
|
||||||
existingWorkPolicy: existingWorkPolicy,
|
|
||||||
backoffPolicy: backoffPolicy,
|
|
||||||
outOfQuotaPolicy: outOfQuotaPolicy,
|
|
||||||
constraints: constraints
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/work_request.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
/// A WorkRequest for repeating work.
|
|
||||||
class PeriodicWorkRequest extends WorkRequest {
|
|
||||||
final Duration? frequency;
|
|
||||||
|
|
||||||
PeriodicWorkRequest({
|
|
||||||
required String uniqueId,
|
|
||||||
required String taskId,
|
|
||||||
String? tag,
|
|
||||||
Map<String, dynamic>? inputData,
|
|
||||||
Duration initialDelay = Duration.zero,
|
|
||||||
Duration backoffPolicyDelay = Duration.zero,
|
|
||||||
ExistingWorkPolicy? existingWorkPolicy,
|
|
||||||
BackoffPolicy? backoffPolicy,
|
|
||||||
OutOfQuotaPolicy? outOfQuotaPolicy,
|
|
||||||
Constraints? constraints,
|
|
||||||
this.frequency
|
|
||||||
}) : super(
|
|
||||||
uniqueId: uniqueId,
|
|
||||||
taskId: taskId,
|
|
||||||
tag: tag,
|
|
||||||
inputData: inputData,
|
|
||||||
initialDelay: initialDelay,
|
|
||||||
backoffPolicyDelay: backoffPolicyDelay,
|
|
||||||
existingWorkPolicy: existingWorkPolicy,
|
|
||||||
backoffPolicy: backoffPolicy,
|
|
||||||
outOfQuotaPolicy: outOfQuotaPolicy,
|
|
||||||
constraints: constraints
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [super.props, frequency];
|
|
||||||
}
|
|
||||||
@@ -1,279 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:core/data/network/config/dynamic_url_interceptors.dart';
|
|
||||||
import 'package:core/presentation/state/failure.dart';
|
|
||||||
import 'package:core/presentation/state/success.dart';
|
|
||||||
import 'package:core/utils/app_logger.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
|
||||||
import 'package:model/email/email_action_type.dart';
|
|
||||||
import 'package:model/extensions/account_id_extensions.dart';
|
|
||||||
import 'package:model/extensions/session_extension.dart';
|
|
||||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
|
||||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
|
||||||
import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/domain/state/unsubscribe_email_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/domain/usecases/unsubscribe_email_interactor.dart';
|
|
||||||
import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions.dart';
|
|
||||||
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/home/domain/usecases/get_session_interactor.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/domain/state/get_authenticated_account_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/domain/state/get_stored_token_oidc_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/bindings/sending_email_interactor_bindings.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/manager/sending_email_cache_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker.dart';
|
|
||||||
import 'package:tmail_ui_user/features/sending_queue/domain/extensions/sending_email_extension.dart';
|
|
||||||
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
|
|
||||||
import 'package:tmail_ui_user/features/sending_queue/presentation/bindings/sending_queue_interactor_bindings.dart';
|
|
||||||
import 'package:tmail_ui_user/features/sending_queue/presentation/utils/sending_queue_isolate_manager.dart';
|
|
||||||
import 'package:tmail_ui_user/main/bindings/main_bindings.dart';
|
|
||||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
|
||||||
|
|
||||||
class SendingEmailWorker extends Worker {
|
|
||||||
|
|
||||||
SendEmailInteractor? _sendEmailInteractor;
|
|
||||||
GetAuthenticatedAccountInteractor? _getAuthenticatedAccountInteractor;
|
|
||||||
DynamicUrlInterceptors? _dynamicUrlInterceptors;
|
|
||||||
AuthorizationInterceptors? _authorizationInterceptors;
|
|
||||||
GetSessionInteractor? _getSessionInteractor;
|
|
||||||
SendingQueueIsolateManager? _sendingQueueIsolateManager;
|
|
||||||
SendingEmailCacheManager? _sendingEmailCacheManager;
|
|
||||||
UnsubscribeEmailInteractor? _unsubscribeEmailInteractor;
|
|
||||||
|
|
||||||
late Completer<bool> _completer;
|
|
||||||
late SendingEmail _sendingEmail;
|
|
||||||
|
|
||||||
AccountId? _currentAccountId;
|
|
||||||
Session? _currentSession;
|
|
||||||
|
|
||||||
static SendingEmailWorker? _instance;
|
|
||||||
|
|
||||||
SendingEmailWorker._();
|
|
||||||
|
|
||||||
factory SendingEmailWorker() => _instance ??= SendingEmailWorker._();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> doWork(String taskId, Map<String, dynamic> inputData) {
|
|
||||||
_completer = Completer<bool>();
|
|
||||||
_sendingEmail = SendingEmail.fromJson(inputData);
|
|
||||||
log('SendingEmailObserver::observe():_sendingEmail: $_sendingEmail');
|
|
||||||
_updatingSendingStateToMainUI(
|
|
||||||
sendingId: _sendingEmail.sendingId,
|
|
||||||
sendingState: SendingState.running
|
|
||||||
);
|
|
||||||
_getAuthenticatedAccount();
|
|
||||||
return _completer.future;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> bindDI() async {
|
|
||||||
await Future.wait([
|
|
||||||
MainBindings().dependencies(),
|
|
||||||
HiveCacheConfig.instance.setUp()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await Future.sync(() {
|
|
||||||
SendingQueueInteractorBindings().dependencies();
|
|
||||||
SendEmailInteractorBindings().dependencies();
|
|
||||||
MailboxDashBoardBindings().dependencies();
|
|
||||||
});
|
|
||||||
|
|
||||||
_getInteractorBindings();
|
|
||||||
|
|
||||||
await _sendingEmailCacheManager?.closeSendingEmailHiveCacheBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void handleFailureViewState(Failure failure) {
|
|
||||||
log('SendingEmailObserver::_handleFailureViewState(): $failure');
|
|
||||||
if (failure is SendEmailFailure) {
|
|
||||||
_handleSendEmailFailure(failure);
|
|
||||||
} else if (failure is GetAuthenticatedAccountFailure ||
|
|
||||||
failure is GetSessionFailure ||
|
|
||||||
failure is GetStoredTokenOidcFailure ||
|
|
||||||
failure is GetCredentialFailure) {
|
|
||||||
_handleWorkerTaskToRetry();
|
|
||||||
} else if (failure is UnsubscribeEmailFailure) {
|
|
||||||
_handleWorkerTaskSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void handleSuccessViewState(Success success) {
|
|
||||||
log('SendingEmailObserver::handleSuccessViewState(): $success');
|
|
||||||
if (success is GetSessionSuccess) {
|
|
||||||
_handleGetSessionSuccess(success);
|
|
||||||
} else if (success is GetStoredTokenOidcSuccess) {
|
|
||||||
_handleGetAccountByOidcSuccess(success);
|
|
||||||
} else if (success is GetCredentialViewState) {
|
|
||||||
_handleGetAccountByBasicAuthSuccess(success);
|
|
||||||
} else if (success is SendEmailSuccess) {
|
|
||||||
_handleSendEmailSuccess(success);
|
|
||||||
} else if (success is UnsubscribeEmailSuccess) {
|
|
||||||
_handleWorkerTaskSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void handleOnError(Object? error, StackTrace stackTrace) {
|
|
||||||
super.handleOnError(error, stackTrace);
|
|
||||||
_handleWorkerTaskToRetry();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _getInteractorBindings() {
|
|
||||||
_getAuthenticatedAccountInteractor = getBinding<GetAuthenticatedAccountInteractor>();
|
|
||||||
_dynamicUrlInterceptors = getBinding<DynamicUrlInterceptors>();
|
|
||||||
_authorizationInterceptors = getBinding<AuthorizationInterceptors>();
|
|
||||||
_getSessionInteractor = getBinding<GetSessionInteractor>();
|
|
||||||
_sendEmailInteractor = getBinding<SendEmailInteractor>();
|
|
||||||
_sendingQueueIsolateManager = getBinding<SendingQueueIsolateManager>();
|
|
||||||
_sendingEmailCacheManager = getBinding<SendingEmailCacheManager>();
|
|
||||||
_unsubscribeEmailInteractor = getBinding<UnsubscribeEmailInteractor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updatingSendingStateToMainUI({String? sendingId, SendingState? sendingState}) {
|
|
||||||
final eventAction = _generateEventAction(
|
|
||||||
sendingId ?? _sendingEmail.sendingId,
|
|
||||||
sendingState ?? _sendingEmail.sendingState,
|
|
||||||
accountId: _currentAccountId,
|
|
||||||
userName: _currentSession?.username
|
|
||||||
);
|
|
||||||
log('SendingEmailObserver::_updatingSendingStateToMainUI():eventAction: $eventAction');
|
|
||||||
_sendingQueueIsolateManager?.addEvent(eventAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _getAuthenticatedAccount() {
|
|
||||||
consumeState(_getAuthenticatedAccountInteractor!.execute());
|
|
||||||
}
|
|
||||||
|
|
||||||
void _getSessionAction() {
|
|
||||||
consumeState(_getSessionInteractor!.execute());
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleGetSessionSuccess(GetSessionSuccess success) async {
|
|
||||||
_currentSession = success.session;
|
|
||||||
_currentAccountId = success.session.accountId;
|
|
||||||
final apiUrl = success.session.getQualifiedApiUrl(baseUrl: _dynamicUrlInterceptors?.jmapUrl);
|
|
||||||
if (apiUrl.isNotEmpty && _currentSession != null && _currentAccountId != null) {
|
|
||||||
_dynamicUrlInterceptors?.changeBaseUrl(apiUrl);
|
|
||||||
_sendEmailAction(_currentAccountId!, _currentSession!);
|
|
||||||
} else {
|
|
||||||
_handleWorkerTaskToRetry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleGetAccountByBasicAuthSuccess(GetCredentialViewState credentialViewState) {
|
|
||||||
_dynamicUrlInterceptors?.setJmapUrl(credentialViewState.baseUrl.toString());
|
|
||||||
_authorizationInterceptors?.setBasicAuthorization(
|
|
||||||
credentialViewState.userName,
|
|
||||||
credentialViewState.password,
|
|
||||||
);
|
|
||||||
_dynamicUrlInterceptors?.changeBaseUrl(credentialViewState.baseUrl.toString());
|
|
||||||
_getSessionAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _sendEmailAction(AccountId accountId, Session session) {
|
|
||||||
consumeState(
|
|
||||||
_sendEmailInteractor!.execute(
|
|
||||||
session,
|
|
||||||
accountId,
|
|
||||||
_sendingEmail.toEmailRequest(),
|
|
||||||
mailboxRequest: _getMailboxRequest()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateNewMailboxRequest? _getMailboxRequest() {
|
|
||||||
if (_sendingEmail.mailboxNameRequest != null) {
|
|
||||||
return CreateNewMailboxRequest(
|
|
||||||
_sendingEmail.mailboxNameRequest!);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleGetAccountByOidcSuccess(GetStoredTokenOidcSuccess storedTokenOidcSuccess) {
|
|
||||||
_dynamicUrlInterceptors?.setJmapUrl(storedTokenOidcSuccess.baseUrl.toString());
|
|
||||||
_authorizationInterceptors?.setTokenAndAuthorityOidc(
|
|
||||||
newToken: storedTokenOidcSuccess.tokenOidc,
|
|
||||||
newConfig: storedTokenOidcSuccess.oidcConfiguration
|
|
||||||
);
|
|
||||||
_dynamicUrlInterceptors?.changeBaseUrl(storedTokenOidcSuccess.baseUrl.toString());
|
|
||||||
_getSessionAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleSendEmailSuccess(SendEmailSuccess success) {
|
|
||||||
if (success.emailRequest.emailActionType == EmailActionType.composeFromUnsubscribeMailtoLink &&
|
|
||||||
success.emailRequest.previousEmailId != null) {
|
|
||||||
_unsubscribeMail(success.emailRequest.previousEmailId!);
|
|
||||||
} else {
|
|
||||||
_handleWorkerTaskSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleSendEmailFailure(SendEmailFailure failure) {
|
|
||||||
_handleWorkerTaskFailure(failure.exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleWorkerTaskToRetry() async {
|
|
||||||
_updatingSendingStateToMainUI(sendingState: SendingState.canceled);
|
|
||||||
log('SendingEmailObserver::_handleWorkerTaskToRetry():');
|
|
||||||
await Future.delayed(
|
|
||||||
const Duration(milliseconds: 1000),
|
|
||||||
() => _completer.complete(false)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleWorkerTaskFailure(dynamic error) async {
|
|
||||||
log('SendingEmailObserver::_handleWorkerTaskFailure():error: $error');
|
|
||||||
_updatingSendingStateToMainUI(sendingState: SendingState.error);
|
|
||||||
await Future.delayed(
|
|
||||||
const Duration(milliseconds: 1000),
|
|
||||||
() => _completer.completeError(error)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleWorkerTaskSuccess() async {
|
|
||||||
log('SendingEmailObserver::_handleWorkerTaskSuccess():');
|
|
||||||
_updatingSendingStateToMainUI(sendingState: SendingState.success);
|
|
||||||
await Future.delayed(
|
|
||||||
const Duration(milliseconds: 1000),
|
|
||||||
() => _completer.complete(true)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String _generateEventAction(
|
|
||||||
String sendingId,
|
|
||||||
SendingState sendingState,
|
|
||||||
{
|
|
||||||
AccountId? accountId,
|
|
||||||
UserName? userName
|
|
||||||
}
|
|
||||||
) => TupleKey(sendingId, sendingState.name, accountId?.asString, userName?.value).toString();
|
|
||||||
|
|
||||||
void _unsubscribeMail(EmailId emailId) {
|
|
||||||
if (_unsubscribeEmailInteractor != null &&
|
|
||||||
_currentSession != null &&
|
|
||||||
_currentAccountId != null
|
|
||||||
) {
|
|
||||||
consumeState(
|
|
||||||
_unsubscribeEmailInteractor!.execute(
|
|
||||||
_currentSession!,
|
|
||||||
_currentAccountId!,
|
|
||||||
emailId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
_handleWorkerTaskSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
@pragma('vm:entry-point')
|
|
||||||
void callbackDispatcher() {
|
|
||||||
Workmanager().executeTask(WorkManagerController().handleBackgroundTask);
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:workmanager/workmanager.dart';
|
|
||||||
|
|
||||||
/// Represents the scheduling of requests
|
|
||||||
abstract class WorkRequest with EquatableMixin {
|
|
||||||
final String uniqueId;
|
|
||||||
final String taskId;
|
|
||||||
final String? tag;
|
|
||||||
final Map<String, dynamic>? inputData;
|
|
||||||
final Duration initialDelay;
|
|
||||||
final Duration backoffPolicyDelay;
|
|
||||||
final ExistingWorkPolicy? existingWorkPolicy;
|
|
||||||
final BackoffPolicy? backoffPolicy;
|
|
||||||
final OutOfQuotaPolicy? outOfQuotaPolicy;
|
|
||||||
final Constraints? constraints;
|
|
||||||
|
|
||||||
WorkRequest( {
|
|
||||||
required this.uniqueId,
|
|
||||||
required this.taskId,
|
|
||||||
this.tag,
|
|
||||||
this.inputData,
|
|
||||||
this.initialDelay = Duration.zero,
|
|
||||||
this.backoffPolicyDelay = Duration.zero,
|
|
||||||
this.existingWorkPolicy,
|
|
||||||
this.backoffPolicy,
|
|
||||||
this.outOfQuotaPolicy,
|
|
||||||
this.constraints
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [
|
|
||||||
uniqueId,
|
|
||||||
taskId,
|
|
||||||
tag,
|
|
||||||
inputData,
|
|
||||||
initialDelay,
|
|
||||||
backoffPolicyDelay,
|
|
||||||
existingWorkPolicy,
|
|
||||||
backoffPolicy,
|
|
||||||
outOfQuotaPolicy,
|
|
||||||
constraints
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'package:core/presentation/state/failure.dart';
|
|
||||||
import 'package:core/presentation/state/success.dart';
|
|
||||||
import 'package:core/utils/app_logger.dart';
|
|
||||||
import 'package:dartz/dartz.dart';
|
|
||||||
|
|
||||||
abstract class Worker {
|
|
||||||
Future<void> bindDI();
|
|
||||||
|
|
||||||
Future<bool> doWork(String taskId, Map<String, dynamic> inputData);
|
|
||||||
|
|
||||||
void consumeState(Stream<Either<Failure, Success>> newStateStream) {
|
|
||||||
newStateStream.listen(
|
|
||||||
_handleStateStream,
|
|
||||||
onError: handleOnError
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleStateStream(Either<Failure, Success> newState) {
|
|
||||||
newState.fold(handleFailureViewState, handleSuccessViewState);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleFailureViewState(Failure failure) {}
|
|
||||||
|
|
||||||
void handleSuccessViewState(Success success) {}
|
|
||||||
|
|
||||||
void handleOnError(Object? error, StackTrace stackTrace) {
|
|
||||||
logError('WorkObserver::handleOnError():error: $error | stackTrace: $stackTrace');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/sending_email_worker.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker.dart';
|
|
||||||
|
|
||||||
enum WorkerType {
|
|
||||||
sendingEmail;
|
|
||||||
|
|
||||||
Worker getWorker() {
|
|
||||||
switch(this) {
|
|
||||||
case WorkerType.sendingEmail:
|
|
||||||
return SendingEmailWorker();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user