diff --git a/lib/features/base/reloadable/reloadable_controller.dart b/lib/features/base/reloadable/reloadable_controller.dart index 297c1c1e9..cd689374a 100644 --- a/lib/features/base/reloadable/reloadable_controller.dart +++ b/lib/features/base/reloadable/reloadable_controller.dart @@ -24,6 +24,8 @@ import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_ import 'package:tmail_ui_user/features/manage_account/domain/state/log_out_oidc_state.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/vacation/vacation_interactors_bindings.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/state/get_fcm_subscription_local.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_receiver.dart'; import 'package:tmail_ui_user/features/session/domain/state/get_session_state.dart'; import 'package:tmail_ui_user/features/session/domain/usecases/get_session_interactor.dart'; @@ -46,6 +48,8 @@ abstract class ReloadableController extends BaseController { final GetAuthenticatedAccountInteractor _getAuthenticatedAccountInteractor; final _fcmReceiver = FcmReceiver.instance; + GetFCMSubscriptionLocalInteractor? _getSubscriptionLocalInteractor; + ReloadableController( this._logoutOidcInteractor, this._deleteAuthorityOidcInteractor, @@ -67,7 +71,9 @@ abstract class ReloadableController extends BaseController { _goToLogin(arguments: LoginArguments(LoginFormType.ssoForm)); } else if (failure is GetAuthenticatedAccountFailure || failure is NoAuthenticatedAccountFailure) { _goToLogin(arguments: LoginArguments(LoginFormType.credentialForm)); - } + } else if (failure is GetFCMSubscriptionLocalFailure){ + logoutAction(); + } }, (success) { if (success is GetCredentialViewState) { @@ -201,4 +207,16 @@ abstract class ReloadableController extends BaseController { logError('ReloadableController::injectVacationBindings(): exception: $e'); } } + + Future getSubscriptionLocalAction() { + try { + _getSubscriptionLocalInteractor = Get.find(); + consumeState(_getSubscriptionLocalInteractor!.execute()); + } catch (e) { + logError( + 'ReloadableController::getSubscriptionLocalAction(): exception: $e'); + logoutAction(); + } + return Future.value(); + } } \ No newline at end of file diff --git a/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart b/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart index cee81fdfe..91af57fd3 100644 --- a/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart +++ b/lib/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart @@ -9,18 +9,17 @@ import 'package:tmail_ui_user/features/push_notification/data/network/fcm_api.da import 'package:tmail_ui_user/features/push_notification/data/repository/fcm_repository_impl.dart'; import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/destroy_subscription_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_firebase_subscription_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/register_new_token_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_subscription_interator.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_email_delivery_state_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_email_state_to_refresh_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_mailbox_state_to_refresh_interactor.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_subscription_interator.dart'; import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.dart'; import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.dart'; import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart'; @@ -65,7 +64,8 @@ class FcmInteractorBindings extends InteractorsBindings { Get.lazyPut(() => RegisterNewTokenInteractor(Get.find())); Get.lazyPut(() => StoreMailboxStateToRefreshInteractor(Get.find())); Get.lazyPut(() => GetMailboxStateToRefreshInteractor(Get.find())); - Get.lazyPut(() => DestroySubscriptionInteractor(Get.find())); + Get.lazyPut(() => StoreSubscriptionInteractor(Get.find())); + Get.lazyPut(() => GetFCMSubscriptionLocalInteractor(Get.find())); } @override diff --git a/lib/features/push_notification/presentation/controller/fcm_token_handler.dart b/lib/features/push_notification/presentation/controller/fcm_token_handler.dart index 69d090050..5cd9784a6 100644 --- a/lib/features/push_notification/presentation/controller/fcm_token_handler.dart +++ b/lib/features/push_notification/presentation/controller/fcm_token_handler.dart @@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/push_notification/domain/model/register_n import 'package:tmail_ui_user/features/push_notification/domain/state/get_fcm_subscription_local.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/get_firebase_subscription_state.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/register_new_token_state.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_subscription_local_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_firebase_subscription_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/register_new_token_interactor.dart'; import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_subscription_interator.dart'; @@ -37,6 +38,7 @@ class FcmTokenHandler { StoreSubscriptionInteractor? _storeSubscriptionInteractor; GetFirebaseSubscriptionInteractor? _getFirebaseSubscriptionInteractor; RegisterNewTokenInteractor? _registerNewTokenInteractor; + GetFCMSubscriptionLocalInteractor? _getFCMSubscriptionLocalInteractor; FirebaseToken? _fcmToken; DeviceClientId? _deviceClientId; @@ -46,6 +48,7 @@ class FcmTokenHandler { _storeSubscriptionInteractor = getBinding(); _getFirebaseSubscriptionInteractor = getBinding(); _registerNewTokenInteractor = getBinding(); + _getFCMSubscriptionLocalInteractor = getBinding(); } catch (e) { logError('FcmTokenHandler::initialize(): ${e.toString()}'); } @@ -60,6 +63,8 @@ class FcmTokenHandler { log('FcmTokenHandler::handle(): fcmToken: $_fcmToken'); log('FcmTokenHandler::handle(): deviceId: $deviceId'); _getFcmTokenFromBackend(deviceId); + } else { + _getFCMSubscriptionLocalAction(); } } @@ -178,4 +183,10 @@ class FcmTokenHandler { _consumeState(_registerNewTokenInteractor!.execute(newTokenRequest)); } } + + void _getFCMSubscriptionLocalAction() { + if (_getFCMSubscriptionLocalInteractor != null) { + _consumeState(_getFCMSubscriptionLocalInteractor!.execute()); + } + } } \ No newline at end of file