TF-1289: [Presentation] implement StoreSubscription in presentation
This commit is contained in:
@@ -3,20 +3,21 @@ import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/fcm_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/hive_fcm_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/cache_fcm_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/network/fcm_api.dart';
|
||||
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/get_device_id_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_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_device_id_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';
|
||||
@@ -37,7 +38,7 @@ class FcmInteractorBindings extends InteractorsBindings {
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => HiveFCMDatasourceImpl(
|
||||
Get.lazyPut(() => CacheFCMDatasourceImpl(
|
||||
Get.find<FCMCacheManager>(),
|
||||
Get.find<CacheExceptionThrower>(),
|
||||
));
|
||||
@@ -60,12 +61,11 @@ class FcmInteractorBindings extends InteractorsBindings {
|
||||
Get.lazyPut(() => StoreEmailStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => GetEmailStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => DeleteEmailStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => StoreDeviceIdInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => GetFirebaseSubscriptionInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => RegisterNewTokenInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => GetDeviceIdInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => StoreMailboxStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => GetMailboxStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.lazyPut(() => DestroySubscriptionInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -77,7 +77,7 @@ class FcmInteractorBindings extends InteractorsBindings {
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.lazyPut(() => FCMRepositoryImpl(
|
||||
{
|
||||
DataSourceType.local: Get.find<HiveFCMDatasourceImpl>(),
|
||||
DataSourceType.local: Get.find<CacheFCMDatasourceImpl>(),
|
||||
DataSourceType.network: Get.find<FCMDatasource>(),
|
||||
},
|
||||
Get.find<ThreadDataSource>()
|
||||
|
||||
@@ -11,14 +11,14 @@ import 'package:fcm/model/firebase_token.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/datetime_extension.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_device_id_state.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/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_device_id_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_device_id_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/usecases/store_subscription_interator.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/presentation/utils/fcm_utils.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@@ -34,20 +34,18 @@ class FcmTokenHandler {
|
||||
static const int limitedTimeToExpire = 3;
|
||||
static const int extensionTimeExpire = 7;
|
||||
|
||||
StoreDeviceIdInteractor? _storeDeviceIdInteractor;
|
||||
StoreSubscriptionInteractor? _storeSubscriptionInteractor;
|
||||
GetFirebaseSubscriptionInteractor? _getFirebaseSubscriptionInteractor;
|
||||
RegisterNewTokenInteractor? _registerNewTokenInteractor;
|
||||
GetDeviceIdInteractor? _getDeviceIdInteractor;
|
||||
|
||||
FirebaseToken? _fcmToken;
|
||||
DeviceClientId? _deviceClientId;
|
||||
|
||||
void initialize() {
|
||||
try {
|
||||
_storeDeviceIdInteractor = getBinding<StoreDeviceIdInteractor>();
|
||||
_storeSubscriptionInteractor = getBinding<StoreSubscriptionInteractor>();
|
||||
_getFirebaseSubscriptionInteractor = getBinding<GetFirebaseSubscriptionInteractor>();
|
||||
_registerNewTokenInteractor = getBinding<RegisterNewTokenInteractor>();
|
||||
_getDeviceIdInteractor = getBinding<GetDeviceIdInteractor>();
|
||||
} catch (e) {
|
||||
logError('FcmTokenHandler::initialize(): ${e.toString()}');
|
||||
}
|
||||
@@ -62,8 +60,6 @@ class FcmTokenHandler {
|
||||
log('FcmTokenHandler::handle(): fcmToken: $_fcmToken');
|
||||
log('FcmTokenHandler::handle(): deviceId: $deviceId');
|
||||
_getFcmTokenFromBackend(deviceId);
|
||||
} else {
|
||||
_getDeviceIdAction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,15 +69,9 @@ class FcmTokenHandler {
|
||||
}
|
||||
}
|
||||
|
||||
void _storeDeviceIdAction(String deviceId) {
|
||||
if (_storeDeviceIdInteractor != null) {
|
||||
_consumeState(_storeDeviceIdInteractor!.execute(deviceId));
|
||||
}
|
||||
}
|
||||
|
||||
void _getDeviceIdAction() {
|
||||
if (_getDeviceIdInteractor != null) {
|
||||
_consumeState(_getDeviceIdInteractor!.execute());
|
||||
void _storeSubscriptionAction(FCMSubscription fcmSubscription){
|
||||
if (_storeSubscriptionInteractor != null) {
|
||||
_consumeState(_storeSubscriptionInteractor!.execute(fcmSubscription));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,11 +110,12 @@ class FcmTokenHandler {
|
||||
}
|
||||
} else if (success is RegisterNewTokenSuccess) {
|
||||
final deviceId = success.firebaseSubscription.deviceClientId?.value;
|
||||
if (deviceId != null) {
|
||||
_storeDeviceIdAction(deviceId);
|
||||
final subscriptionId = success.firebaseSubscription.id?.id.value;
|
||||
if (deviceId != null && subscriptionId != null) {
|
||||
_storeSubscriptionAction(FCMSubscription(deviceId, subscriptionId));
|
||||
}
|
||||
} else if (success is GetDeviceIdSuccess) {
|
||||
_getFcmTokenFromBackend(success.deviceId);
|
||||
} else if (success is GetFCMSubscriptionLocalSuccess) {
|
||||
_getFcmTokenFromBackend(success.fcmSubscription.deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user