From 423a12eea1a4c40c34c6f99eccef25e8da430d39 Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 27 Oct 2022 17:00:44 +0700 Subject: [PATCH] TF-1115 Implement catch exception when for GetAllEmail and RefreshChangesEmail --- contact/pubspec.lock | 12 ++--- forward/pubspec.lock | 8 ++-- lib/features/base/base_controller.dart | 45 ++++++++++++++++++- lib/features/caching/caching_manager.dart | 8 ++++ .../thread_datasource_impl.dart | 12 +++-- .../thread/presentation/thread_bindings.dart | 8 +++- .../presentation/thread_controller.dart | 27 +++++++---- model/pubspec.lock | 12 ++--- pubspec.lock | 14 +++--- rule_filter/pubspec.lock | 8 ++-- 10 files changed, 112 insertions(+), 42 deletions(-) diff --git a/contact/pubspec.lock b/contact/pubspec.lock index 4cf82f3a3..99da934c1 100644 --- a/contact/pubspec.lock +++ b/contact/pubspec.lock @@ -77,7 +77,7 @@ packages: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.6" + version: "7.2.7" built_collection: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -365,7 +365,7 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" html: dependency: transitive description: @@ -420,7 +420,7 @@ packages: description: path: "." ref: master - resolved-ref: ab07a8a03d63e20f6ea5e62bcc1ca8cdc1fd93ff + resolved-ref: "45ea109f70be0d868b005aadf11a39e2ac816c38" url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" @@ -631,7 +631,7 @@ packages: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" stack_trace: dependency: transitive description: @@ -729,7 +729,7 @@ packages: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.19" + version: "6.0.20" url_launcher_ios: dependency: transitive description: diff --git a/forward/pubspec.lock b/forward/pubspec.lock index 03d050102..f89b485ab 100644 --- a/forward/pubspec.lock +++ b/forward/pubspec.lock @@ -77,7 +77,7 @@ packages: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.6" + version: "7.2.7" built_collection: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -234,7 +234,7 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" http_mock_adapter: dependency: "direct main" description: @@ -268,7 +268,7 @@ packages: description: path: "." ref: master - resolved-ref: ab07a8a03d63e20f6ea5e62bcc1ca8cdc1fd93ff + resolved-ref: "45ea109f70be0d868b005aadf11a39e2ac816c38" url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index 5c96bc5ce..0fcd6bdfb 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -1,6 +1,8 @@ import 'package:contact/contact/model/capability_contact.dart'; import 'package:core/core.dart'; import 'package:dartz/dartz.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; @@ -12,18 +14,30 @@ import 'package:tmail_ui_user/features/email/presentation/mdn_interactor_binding import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/contact_autocomplete_bindings.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/tmail_autocomplete_bindings.dart'; import 'package:tmail_ui_user/main/error/capability_validator.dart'; +import 'package:tmail_ui_user/main/exceptions/remote_exception.dart'; +import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; +import 'package:tmail_ui_user/main/routes/route_navigation.dart'; abstract class BaseController extends GetxController with MessageDialogActionMixin, PopupContextMenuActionMixin, ViewAsDialogActionMixin { + + final _appToast = Get.find(); + final _imagePaths = Get.find(); + final _responsiveUtils = Get.find(); + final viewState = Rx>(Right(UIState.idle)); FpsCallback? fpsCallback; void consumeState(Stream> newStateStream) async { newStateStream.listen( (state) => onData(state), - onError: (error) => onError(error), + onError: (error, stackTrace) { + logError('BaseController::consumeState():onError:error: $error'); + logError('BaseController::consumeState():onError:stackTrace: $stackTrace'); + onError(error); + }, onDone: () => onDone() ); } @@ -48,7 +62,34 @@ abstract class BaseController extends GetxController viewState.value = newState; } - void onError(dynamic error); + void onError(dynamic error) { + String messageError = ''; + if (error is MethodLevelErrors) { + messageError = error.message ?? error.type.value; + } else { + if (currentContext != null) { + messageError = AppLocalizations + .of(currentContext!) + .unknown_error_login_message; + } + } + + if (messageError.isNotEmpty && currentContext != null && currentOverlayContext != null) { + _appToast.showBottomToast( + currentOverlayContext!, + messageError, + leadingIcon: SvgPicture.asset( + _imagePaths.icNotConnection, + width: 24, + height: 24, + color: Colors.white, + fit: BoxFit.fill), + backgroundColor: AppColor.toastErrorBackgroundColor, + textColor: Colors.white, + textActionColor: Colors.white, + maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!)); + } + } void onDone(); diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index 44d192b2a..b2076cb8c 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -5,6 +5,7 @@ import 'package:tmail_ui_user/features/caching/email_cache_client.dart'; import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; import 'package:tmail_ui_user/features/caching/recent_search_cache_client.dart'; import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; class CachingManager { @@ -41,4 +42,11 @@ class CachingManager { ]); } } + + Future cleanEmailCache() async { + await Future.wait([ + _stateCacheClient.deleteItem(StateType.email.value), + _emailCacheClient.clearAllData(), + ]); + } } \ No newline at end of file diff --git a/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart b/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart index e7dc53c86..a30e82f6d 100644 --- a/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart +++ b/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart @@ -14,13 +14,19 @@ import 'package:tmail_ui_user/features/thread/data/network/thread_isolate_worker import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart'; import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart'; import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart'; +import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart'; class ThreadDataSourceImpl extends ThreadDataSource { final ThreadAPI threadAPI; final ThreadIsolateWorker _threadIsolateWorker; + final ExceptionThrower _exceptionThrower; - ThreadDataSourceImpl(this.threadAPI, this._threadIsolateWorker); + ThreadDataSourceImpl( + this.threadAPI, + this._threadIsolateWorker, + this._exceptionThrower + ); @override Future getAllEmail( @@ -40,7 +46,7 @@ class ThreadDataSourceImpl extends ThreadDataSource { filter: filter, properties: properties); }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } @@ -60,7 +66,7 @@ class ThreadDataSourceImpl extends ThreadDataSource { propertiesCreated: propertiesCreated, propertiesUpdated: propertiesUpdated); }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } diff --git a/lib/features/thread/presentation/thread_bindings.dart b/lib/features/thread/presentation/thread_bindings.dart index 476d71278..100e0f46b 100644 --- a/lib/features/thread/presentation/thread_bindings.dart +++ b/lib/features/thread/presentation/thread_bindings.dart @@ -1,6 +1,7 @@ import 'package:core/core.dart'; import 'package:get/get.dart'; import 'package:tmail_ui_user/features/base/base_bindings.dart'; +import 'package:tmail_ui_user/features/caching/caching_manager.dart'; import 'package:tmail_ui_user/features/caching/state_cache_client.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'; @@ -42,6 +43,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/refresh_changes_em import 'package:tmail_ui_user/features/thread/domain/usecases/search_email_interactor.dart'; import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_email_interactor.dart'; import 'package:tmail_ui_user/features/thread/presentation/thread_controller.dart'; +import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart'; class ThreadBindings extends BaseBindings { @@ -61,6 +63,7 @@ class ThreadBindings extends BaseBindings { Get.find(), Get.find(), Get.find(), + Get.find(), )); } @@ -77,7 +80,10 @@ class ThreadBindings extends BaseBindings { void bindingsDataSourceImpl() { Get.lazyPut(() => MailboxDataSourceImpl(Get.find(), Get.find())); Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find())); - Get.lazyPut(() => ThreadDataSourceImpl(Get.find(), Get.find())); + Get.lazyPut(() => ThreadDataSourceImpl( + Get.find(), + Get.find(), + Get.find())); Get.lazyPut(() => LocalThreadDataSourceImpl(Get.find())); Get.lazyPut(() => StateDataSourceImpl(Get.find())); Get.lazyPut(() => EmailDataSourceImpl(Get.find())); diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index e193849db..49cfdd148 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -17,6 +17,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:model/model.dart'; import 'package:pointer_interceptor/pointer_interceptor.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; +import 'package:tmail_ui_user/features/caching/caching_manager.dart'; import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart'; import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart'; import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart'; @@ -71,6 +72,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_email_ import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart'; import 'package:tmail_ui_user/features/thread/presentation/model/search_state.dart'; import 'package:tmail_ui_user/features/thread/presentation/model/search_status.dart'; +import 'package:tmail_ui_user/main/exceptions/remote_exception.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/routes/app_routes.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; @@ -95,6 +97,7 @@ class ThreadController extends BaseController { final EmptyTrashFolderInteractor _emptyTrashFolderInteractor; final MarkAsEmailReadInteractor _markAsEmailReadInteractor; final MoveToMailboxInteractor _moveToMailboxInteractor; + final CachingManager _cachingManager; final emailList = [].obs; final listEmailDrag = [].obs; @@ -139,6 +142,7 @@ class ThreadController extends BaseController { this._emptyTrashFolderInteractor, this._markAsEmailReadInteractor, this._moveToMailboxInteractor, + this._cachingManager, ); @override @@ -199,8 +203,6 @@ class ThreadController extends BaseController { } else if (failure is MarkAsStarMultipleEmailAllFailure || failure is MarkAsStarMultipleEmailFailure) { _markAsStarMultipleEmailFailure(failure); - } else if (failure is LoadMoreEmailsFailure) { - stopFpsMeter(); } }, (success) { @@ -224,15 +226,15 @@ class ThreadController extends BaseController { _markAsEmailReadSuccess(success); } else if (success is MoveToMailboxSuccess) { _moveToMailboxSuccess(success); - } else if (success is LoadMoreEmailsSuccess) { - stopFpsMeter(); } } ); } @override - void onError(error) {} + void onError(error) { + _handleErrorGetAllOrRefreshChangesEmail(error); + } void _initWorker() { mailboxWorker = ever(mailboxDashBoardController.selectedMailbox, (mailbox) { @@ -345,6 +347,16 @@ class ThreadController extends BaseController { viewStateWorker.call(); } + void _handleErrorGetAllOrRefreshChangesEmail(dynamic error) async { + logError('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error'); + if (error is CannotCalculateChangesMethodResponseException) { + await _cachingManager.cleanEmailCache(); + _getAllEmail(); + } else { + super.onError(error); + } + } + void _getAllEmail() { if (_accountId != null) { _getAllEmailAction(_accountId!, mailboxId: _currentMailboxId); @@ -427,10 +439,7 @@ class ThreadController extends BaseController { dispatchState(Right(LoadingState())); canLoadMore = true; cancelSelectEmail(); - - if (_accountId != null) { - _getAllEmail(); - } + _getAllEmail(); } void _refreshEmailChanges({jmap.State? currentEmailState}) { diff --git a/model/pubspec.lock b/model/pubspec.lock index e21de1c6f..3a7f84cca 100644 --- a/model/pubspec.lock +++ b/model/pubspec.lock @@ -77,7 +77,7 @@ packages: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.6" + version: "7.2.7" built_collection: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -372,7 +372,7 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" html: dependency: transitive description: @@ -420,7 +420,7 @@ packages: description: path: "." ref: master - resolved-ref: ab07a8a03d63e20f6ea5e62bcc1ca8cdc1fd93ff + resolved-ref: "45ea109f70be0d868b005aadf11a39e2ac816c38" url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" @@ -617,7 +617,7 @@ packages: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" stack_trace: dependency: transitive description: @@ -715,7 +715,7 @@ packages: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.19" + version: "6.0.20" url_launcher_ios: dependency: transitive description: diff --git a/pubspec.lock b/pubspec.lock index c7876f6b0..f7900ede4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -91,7 +91,7 @@ packages: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.6" + version: "7.2.7" built_collection: dependency: "direct main" description: @@ -105,7 +105,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" byte_converter: dependency: "direct main" description: @@ -658,7 +658,7 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" hive: dependency: "direct main" description: @@ -757,7 +757,7 @@ packages: description: path: "." ref: master - resolved-ref: ab07a8a03d63e20f6ea5e62bcc1ca8cdc1fd93ff + resolved-ref: "45ea109f70be0d868b005aadf11a39e2ac816c38" url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1" @@ -1231,7 +1231,7 @@ packages: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" stack_trace: dependency: transitive description: @@ -1273,7 +1273,7 @@ packages: name: syncfusion_flutter_core url: "https://pub.dartlang.org" source: hosted - version: "20.3.50" + version: "20.3.52" syncfusion_flutter_datepicker: dependency: transitive description: @@ -1364,7 +1364,7 @@ packages: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.19" + version: "6.0.20" url_launcher_ios: dependency: transitive description: diff --git a/rule_filter/pubspec.lock b/rule_filter/pubspec.lock index 03d050102..f89b485ab 100644 --- a/rule_filter/pubspec.lock +++ b/rule_filter/pubspec.lock @@ -77,7 +77,7 @@ packages: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.6" + version: "7.2.7" built_collection: dependency: transitive description: @@ -91,7 +91,7 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.4.1" + version: "8.4.2" characters: dependency: transitive description: @@ -234,7 +234,7 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" http_mock_adapter: dependency: "direct main" description: @@ -268,7 +268,7 @@ packages: description: path: "." ref: master - resolved-ref: ab07a8a03d63e20f6ea5e62bcc1ca8cdc1fd93ff + resolved-ref: "45ea109f70be0d868b005aadf11a39e2ac816c38" url: "https://github.com/linagora/jmap-dart-client.git" source: git version: "0.0.1"