diff --git a/android/app/build.gradle b/android/app/build.gradle index ccfae58f0..36c9d6160 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -41,7 +41,7 @@ android { defaultConfig { applicationId "com.linagora.android.teammail" minSdkVersion 19 - targetSdkVersion 33 + targetSdkVersion 32 versionCode flutterVersionCode.toInteger() versionName flutterVersionName // The number of method references in a .dex file cannot exceed 64K diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index af0b19a26..3a1650c90 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -54,11 +54,16 @@ android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> + + diff --git a/configurations/env.fcm b/configurations/env.fcm new file mode 100644 index 000000000..341f7206d --- /dev/null +++ b/configurations/env.fcm @@ -0,0 +1,6 @@ +FIREBASE_ANDROID_API_KEY=example +FIREBASE_ANDROID_APP_ID=example +FIREBASE_ANDROID_MESSAGING_SENDER_ID=example +FIREBASE_ANDROID_PROJECT_ID=example +FIREBASE_ANDROID_DATABASE_URL=https://example.com +FIREBASE_ANDROID_STORAGE_BUCKET=example.com \ No newline at end of file diff --git a/docs/configuration/fcm_configuration.md b/docs/configuration/fcm_configuration.md index abe9e0cfe..376b2166a 100644 --- a/docs/configuration/fcm_configuration.md +++ b/docs/configuration/fcm_configuration.md @@ -6,7 +6,7 @@ - Now only support to Android ### How to config -1.Add environment of FCM service in [env.file](https://github.com/linagora/tmail-flutter/blob/master/env.file) +1.Add environment of FCM service in [env.fcm](https://github.com/linagora/tmail-flutter/blob/master/configurations/env.fcm) ``` FIREBASE_ANDROID_API_KEY=abc FIREBASE_ANDROID_APP_ID=abc diff --git a/env.file b/env.file index 8eaf87604..98c0dabdb 100644 --- a/env.file +++ b/env.file @@ -1,4 +1,5 @@ -SERVER_URL=http://localhost/ +SERVER_URL=http://localhost DOMAIN_REDIRECT_URL=http://localhost:3000 WEB_OIDC_CLIENT_ID=teammail-web APP_GRID_AVAILABLE=supported +FCM_AVAILABLE=unsupported \ No newline at end of file diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2cdf1b9c9..2207fea33 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -55,7 +55,7 @@ PODS: - firebase_core (2.2.0): - Firebase/CoreOnly (= 10.1.0) - Flutter - - firebase_messaging (14.1.0): + - firebase_messaging (14.0.4): - Firebase/Messaging (= 10.1.0) - firebase_core - Flutter @@ -292,7 +292,7 @@ SPEC CHECKSUMS: file_picker: 817ab1d8cd2da9d2da412a417162deee3500fc95 Firebase: 444b35a9c568a516666213c2f6cccd10cb12559f firebase_core: d2242c6f318db1d0dcecfbfa491e943337b0d755 - firebase_messaging: 59f435c4cd0d5448e7268a7f70bce9b1287c1742 + firebase_messaging: 9b704e183cbcc36120b4744eb966c1947baf47a6 FirebaseCore: 55e7ae35991ccca4db03ff8d8df6ed5f17a3e4c7 FirebaseCoreInternal: 091bde13e47bb1c5e9fe397634f3593dc390430f FirebaseInstallations: 004915af170935e3a583faefd5f8bc851afc220f diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index 0708f73c3..90739b8b4 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -1,7 +1,9 @@ import 'package:contact/contact/model/capability_contact.dart'; import 'package:core/core.dart'; import 'package:dartz/dartz.dart'; +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:forward/forward/capability_forward.dart'; import 'package:get/get.dart'; @@ -17,12 +19,15 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/c import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/tmail_autocomplete_bindings.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/bindings/email_rules_interactor_bindings.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/forward/bindings/forwarding_interactors_bindings.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.dart'; import 'package:tmail_ui_user/features/push_notification/domain/model/capability_push_notification.dart'; import 'package:tmail_ui_user/features/push_notification/presentation/firebase_bindings.dart'; +import 'package:tmail_ui_user/features/push_notification/presentation/firebase_options.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'; +import 'package:tmail_ui_user/main/utils/app_config.dart'; abstract class BaseController extends GetxController with MessageDialogActionMixin, @@ -143,10 +148,16 @@ abstract class BaseController extends GetxController } } - void injectFirebaseBindings(Session? session, AccountId? accountId) { + Future injectFCMBindings(Session? session, AccountId? accountId) async { try { requireCapability(session!, accountId!, [capabilityPushNotification]); - FireBaseBindings().dependencies(); + if(AppConfig.appFCMAvailable) { + await dotenv.load(fileName: AppConfig.appFCMConfigurationPath); + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + FCMBindings().dependencies(); + } else { + throw NotSupportFCMException(); + } } catch(e) { logError('BaseController::injectFirebaseBindings(): exception: $e'); } diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index 24cacf1ff..3c72006b0 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:tmail_ui_user/features/caching/account_cache_client.dart'; import 'package:tmail_ui_user/features/caching/email_cache_client.dart'; -import 'package:tmail_ui_user/features/caching/firebase_config_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/fcm_token_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'; @@ -13,7 +13,7 @@ class CachingManager { final EmailCacheClient _emailCacheClient; final RecentSearchCacheClient _recentSearchCacheClient; final AccountCacheClient _accountCacheClient; - final FirebaseCacheClient _firebaseCacheClient; + final FcmTokenCacheClient _firebaseCacheClient; CachingManager( this._mailboxCacheClient, diff --git a/lib/features/caching/config/hive_cache_config.dart b/lib/features/caching/config/hive_cache_config.dart index 963101416..7e8cc9512 100644 --- a/lib/features/caching/config/hive_cache_config.dart +++ b/lib/features/caching/config/hive_cache_config.dart @@ -18,7 +18,7 @@ import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.d import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/recent_search_cache.dart'; -import 'package:tmail_ui_user/features/push_notification/data/model/firebase_cache.dart'; +import 'package:tmail_ui_user/features/push_notification/data/model/fcm_token_cache.dart'; import 'package:tmail_ui_user/features/thread/data/model/email_address_hive_cache.dart'; import 'package:tmail_ui_user/features/thread/data/model/email_cache.dart'; @@ -79,7 +79,7 @@ class HiveCacheConfig { Hive.registerAdapter(AuthenticationInfoCacheAdapter()); Hive.registerAdapter(RecentLoginUrlCacheAdapter()); Hive.registerAdapter(RecentLoginUsernameCacheAdapter()); - Hive.registerAdapter(FirebaseCacheAdapter()); + Hive.registerAdapter(FCMTokenCacheAdapter()); } Future closeHive() async { diff --git a/lib/features/caching/firebase_config_cache_client.dart b/lib/features/caching/fcm_token_cache_client.dart similarity index 54% rename from lib/features/caching/firebase_config_cache_client.dart rename to lib/features/caching/fcm_token_cache_client.dart index e45c9b060..d0dbf486d 100644 --- a/lib/features/caching/firebase_config_cache_client.dart +++ b/lib/features/caching/fcm_token_cache_client.dart @@ -1,8 +1,8 @@ import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; -import 'package:tmail_ui_user/features/push_notification/data/model/firebase_cache.dart'; +import 'package:tmail_ui_user/features/push_notification/data/model/fcm_token_cache.dart'; -class FirebaseCacheClient extends HiveCacheClient { +class FcmTokenCacheClient extends HiveCacheClient { @override - String get tableName => 'FirebaseCache'; + String get tableName => 'FCMTokenCache'; } \ No newline at end of file diff --git a/lib/features/caching/utils/caching_constants.dart b/lib/features/caching/utils/caching_constants.dart index 24450136b..0f9f61e1c 100644 --- a/lib/features/caching/utils/caching_constants.dart +++ b/lib/features/caching/utils/caching_constants.dart @@ -13,5 +13,5 @@ class CachingConstants { static const int AUTHENTICATION_INFO_HIVE_CACHE_IDENTIFY = 11; static const int RECENT_LOGIN_URL_HIVE_CACHE_IDENTITY = 12; static const int RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY = 13; - static const int FIREBASE_CONFIG_CACHE_IDENTITY = 14; + static const int FCM_TOKEN_CACHE_IDENTITY = 14; } \ No newline at end of file diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 63c39559f..056c6d092 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -14,7 +14,6 @@ import 'package:jmap_dart_client/jmap/core/unsigned_int.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; -import 'package:model/firebase/firebase_dto.dart'; import 'package:model/model.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:pointer_interceptor/pointer_interceptor.dart'; @@ -65,8 +64,6 @@ import 'package:tmail_ui_user/features/manage_account/presentation/extensions/va import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart'; import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart'; import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/presentation/notification_service.dart'; import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart'; import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart'; @@ -111,7 +108,6 @@ class MailboxDashBoardController extends ReloadableController { GetAllVacationInteractor? _getAllVacationInteractor; UpdateVacationInteractor? _updateVacationInteractor; - SaveFirebaseCacheInteractor? _saveFirebaseCacheInteractor; final scaffoldKey = GlobalKey(); final selectedMailbox = Rxn(); @@ -337,7 +333,7 @@ class MailboxDashBoardController extends ReloadableController { injectAutoCompleteBindings(sessionCurrent, accountId.value); injectRuleFilterBindings(sessionCurrent, accountId.value); injectVacationBindings(sessionCurrent, accountId.value); - injectFirebaseBindings(sessionCurrent, accountId.value); + injectFCMBindings(sessionCurrent, accountId.value); _getVacationResponse(); } else { reload(); @@ -355,21 +351,6 @@ class MailboxDashBoardController extends ReloadableController { } } - @override - Future injectFirebaseBindings(Session? session, AccountId? accountId) async { - try { - super.injectFirebaseBindings(session, accountId); - _saveFirebaseCacheInteractor = Get.find(); - await NotificationService.initializeNotificationService(); - NotificationService.onTokenRefresh.listen((token) { - _saveFirebaseCacheInteractor?.execute(FirebaseDto(token)); - }); - } catch (e) { - logError('MailboxDashBoardController::injectVacationBindings(): $e'); - } - } - - Future _getAppVersion() async { final info = await PackageInfo.fromPlatform(); log('MailboxDashBoardController::_getAppVersion(): ${info.version}'); diff --git a/lib/features/push_notification/data/datasource/fcm_datasource.dart b/lib/features/push_notification/data/datasource/fcm_datasource.dart new file mode 100644 index 000000000..2c148e08b --- /dev/null +++ b/lib/features/push_notification/data/datasource/fcm_datasource.dart @@ -0,0 +1,10 @@ + +import 'package:model/fcm/fcm_token_dto.dart'; + +abstract class FCMDatasource { + Future getFCMToken(String accountId); + + Future setFCMToken(FCMTokenDto fcmToken); + + Future deleteFCMToken(String accountId); +} \ No newline at end of file diff --git a/lib/features/push_notification/data/datasource/firebase_datasource.dart b/lib/features/push_notification/data/datasource/firebase_datasource.dart deleted file mode 100644 index a487128a6..000000000 --- a/lib/features/push_notification/data/datasource/firebase_datasource.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:model/firebase/firebase_dto.dart'; - -abstract class FirebaseDatasource { - Future getCurrentFirebase(); - - Future setCurrentFirebase(FirebaseDto newCurrentFirebase); - - Future deleteCurrentFirebase(String token); -} \ No newline at end of file diff --git a/lib/features/push_notification/data/datasource_impl/hive_account_datasource_impl.dart b/lib/features/push_notification/data/datasource_impl/hive_account_datasource_impl.dart deleted file mode 100644 index 6f5a19c35..000000000 --- a/lib/features/push_notification/data/datasource_impl/hive_account_datasource_impl.dart +++ /dev/null @@ -1,39 +0,0 @@ -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/data/datasource/firebase_datasource.dart'; -import 'package:tmail_ui_user/features/push_notification/data/local/firebase_cache_manager.dart'; -import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart'; - -class HiveFirebaseDatasourceImpl extends FirebaseDatasource { - - final FirebaseCacheManager _firebaseCacheManager; - final ExceptionThrower _exceptionThrower; - - HiveFirebaseDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower); - - @override - Future getCurrentFirebase() { - return Future.sync(() async { - return await _firebaseCacheManager.getFirebase(); - }).catchError((error) { - _exceptionThrower.throwException(error); - }); - } - - @override - Future setCurrentFirebase(FirebaseDto newCurrentFirebase) { - return Future.sync(() async { - return await _firebaseCacheManager.setFirebase(newCurrentFirebase); - }).catchError((error) { - _exceptionThrower.throwException(error); - }); - } - - @override - Future deleteCurrentFirebase(String token) { - return Future.sync(() async { - return await _firebaseCacheManager.deleteFirebase(token); - }).catchError((error) { - _exceptionThrower.throwException(error); - }); - } -} \ No newline at end of file diff --git a/lib/features/push_notification/data/datasource_impl/hive_fcm_datasource_impl.dart b/lib/features/push_notification/data/datasource_impl/hive_fcm_datasource_impl.dart new file mode 100644 index 000000000..b89b9f51a --- /dev/null +++ b/lib/features/push_notification/data/datasource_impl/hive_fcm_datasource_impl.dart @@ -0,0 +1,39 @@ +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart'; +import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart'; +import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart'; + +class HiveFCMDatasourceImpl extends FCMDatasource { + + final FCMCacheManager _firebaseCacheManager; + final ExceptionThrower _exceptionThrower; + + HiveFCMDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower); + + @override + Future getFCMToken(String accountId) { + return Future.sync(() async { + return await _firebaseCacheManager.getFCMToken(accountId); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); + } + + @override + Future setFCMToken(FCMTokenDto fcmToken) { + return Future.sync(() async { + return await _firebaseCacheManager.setFCMToken(fcmToken); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); + } + + @override + Future deleteFCMToken(String accountId) { + return Future.sync(() async { + return await _firebaseCacheManager.deleteFCMToken(accountId); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); + } +} \ No newline at end of file diff --git a/lib/features/push_notification/data/extensions/fcm_cache_extensions.dart b/lib/features/push_notification/data/extensions/fcm_cache_extensions.dart new file mode 100644 index 000000000..2e4302849 --- /dev/null +++ b/lib/features/push_notification/data/extensions/fcm_cache_extensions.dart @@ -0,0 +1,11 @@ +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/push_notification/data/model/fcm_token_cache.dart'; + +extension FCMCacheExtension on FCMTokenCache { + FCMTokenDto toFCMDto() { + return FCMTokenDto( + token, + accountId, + ); + } +} diff --git a/lib/features/push_notification/data/extensions/fcm_extensions.dart b/lib/features/push_notification/data/extensions/fcm_extensions.dart new file mode 100644 index 000000000..08e477c15 --- /dev/null +++ b/lib/features/push_notification/data/extensions/fcm_extensions.dart @@ -0,0 +1,11 @@ +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/push_notification/data/model/fcm_token_cache.dart'; + +extension FCMExtensions on FCMTokenDto { + FCMTokenCache toCache() { + return FCMTokenCache( + token, + accountId, + ); + } +} diff --git a/lib/features/push_notification/data/extensions/firebase_cache_extensions.dart b/lib/features/push_notification/data/extensions/firebase_cache_extensions.dart deleted file mode 100644 index dd0a956b6..000000000 --- a/lib/features/push_notification/data/extensions/firebase_cache_extensions.dart +++ /dev/null @@ -1,10 +0,0 @@ - -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/data/model/firebase_cache.dart'; - -extension FirebaseCacheExtension on FirebaseCache { - - FirebaseDto toFirebaseDto() { - return FirebaseDto(token); - } -} \ No newline at end of file diff --git a/lib/features/push_notification/data/extensions/firebase_extensions.dart b/lib/features/push_notification/data/extensions/firebase_extensions.dart deleted file mode 100644 index 93ea404b9..000000000 --- a/lib/features/push_notification/data/extensions/firebase_extensions.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/data/model/firebase_cache.dart'; - -extension FirebaseExtensions on FirebaseDto { - FirebaseCache toCache() { - return FirebaseCache(token); - } -} \ No newline at end of file diff --git a/lib/features/push_notification/data/local/fcm_cache_manager.dart b/lib/features/push_notification/data/local/fcm_cache_manager.dart new file mode 100644 index 000000000..cd991e8b4 --- /dev/null +++ b/lib/features/push_notification/data/local/fcm_cache_manager.dart @@ -0,0 +1,36 @@ +import 'package:core/utils/app_logger.dart'; +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/caching/fcm_token_cache_client.dart'; +import 'package:tmail_ui_user/features/push_notification/data/extensions/fcm_cache_extensions.dart'; +import 'package:tmail_ui_user/features/push_notification/data/extensions/fcm_extensions.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.dart'; + +class FCMCacheManager { + final FcmTokenCacheClient _fcmTokenCacheClient; + + FCMCacheManager(this._fcmTokenCacheClient); + + Future getFCMToken(String accountId) async { + try { + final firebase = await _fcmTokenCacheClient.getItem(accountId); + if(firebase != null ) { + return firebase.toFCMDto(); + } else { + throw NotFoundStoredFCMException(); + } + } catch (e) { + logError('FCMCacheManager::getFCM(): $e'); + throw NotFoundStoredFCMException(); + } + } + + Future setFCMToken(FCMTokenDto firebaseDto) { + log('FCMCacheManager::setFCM(): $_fcmTokenCacheClient'); + return _fcmTokenCacheClient.insertItem(firebaseDto.accountId, firebaseDto.toCache()); + } + + Future deleteFCMToken(String accountId) { + log('FCMCacheManager::deleteSelectedFCM(): $accountId'); + return _fcmTokenCacheClient.deleteItem(accountId); + } +} \ No newline at end of file diff --git a/lib/features/push_notification/data/local/firebase_cache_manager.dart b/lib/features/push_notification/data/local/firebase_cache_manager.dart deleted file mode 100644 index 227f1dd14..000000000 --- a/lib/features/push_notification/data/local/firebase_cache_manager.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:core/utils/app_logger.dart'; -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/caching/firebase_config_cache_client.dart'; -import 'package:tmail_ui_user/features/push_notification/data/extensions/firebase_extensions.dart'; -import 'package:tmail_ui_user/features/push_notification/data/model/firebase_cache.dart'; -import 'package:tmail_ui_user/features/push_notification/data/extensions/firebase_cache_extensions.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/exceptions/firebase_exception.dart'; - -class FirebaseCacheManager { - final FirebaseCacheClient _firebaseCacheClient; - - FirebaseCacheManager(this._firebaseCacheClient); - - Future getFirebase() async { - try { - final firebase = await _firebaseCacheClient.getItem(FirebaseCache.keyCacheValue); - if(firebase != null ) { - return firebase.toFirebaseDto(); - } else { - throw NotFoundStoredFirebaseException(); - } - } catch (e) { - logError('FirebaseCacheManager::getFirebase(): $e'); - throw NotFoundStoredFirebaseException(); - } - } - - Future setFirebase(FirebaseDto firebaseDto) { - log('FirebaseCacheManager::setFirebase(): $_firebaseCacheClient'); - return _firebaseCacheClient.insertItem(firebaseDto.token, firebaseDto.toCache()); - } - - Future deleteFirebase(String token) { - log('FirebaseCacheManager::deleteSelectedFirebase(): $token'); - return _firebaseCacheClient.deleteItem(token); - } -} \ No newline at end of file diff --git a/lib/features/push_notification/data/model/fcm_token_cache.dart b/lib/features/push_notification/data/model/fcm_token_cache.dart new file mode 100644 index 000000000..89ab810e9 --- /dev/null +++ b/lib/features/push_notification/data/model/fcm_token_cache.dart @@ -0,0 +1,22 @@ +import 'package:equatable/equatable.dart'; +import 'package:hive/hive.dart'; +import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart'; + +part 'fcm_token_cache.g.dart'; + +@HiveType(typeId: CachingConstants.FCM_TOKEN_CACHE_IDENTITY) +class FCMTokenCache extends HiveObject with EquatableMixin { + @HiveField(0) + final String token; + + @HiveField(1) + final String accountId; + + FCMTokenCache( + this.token, + this.accountId, + ); + + @override + List get props => [token]; +} diff --git a/lib/features/push_notification/data/model/firebase_cache.dart b/lib/features/push_notification/data/model/firebase_cache.dart deleted file mode 100644 index 2a5a8260b..000000000 --- a/lib/features/push_notification/data/model/firebase_cache.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:hive/hive.dart'; -import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart'; - -part 'firebase_cache.g.dart'; - -@HiveType(typeId: CachingConstants.FIREBASE_CONFIG_CACHE_IDENTITY) -class FirebaseCache extends HiveObject with EquatableMixin { - - static const String keyCacheValue = 'firebaseCache'; - - @HiveField(0) - final String token; - - FirebaseCache(this.token); - - @override - List get props => [token]; -} \ No newline at end of file diff --git a/lib/features/push_notification/data/repository/fcm_repository_impl.dart b/lib/features/push_notification/data/repository/fcm_repository_impl.dart new file mode 100644 index 000000000..118beeb84 --- /dev/null +++ b/lib/features/push_notification/data/repository/fcm_repository_impl.dart @@ -0,0 +1,27 @@ +import 'package:core/utils/app_logger.dart'; +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; + +class FCMRepositoryImpl extends FCMRepository { + + final FCMDatasource _fcmDatasource; + + FCMRepositoryImpl(this._fcmDatasource); + + @override + Future getFCMToken(String accountId) { + return _fcmDatasource.getFCMToken(accountId); + } + + @override + Future setFCMToken(FCMTokenDto fcmTokenDto) { + log('FCMRepositoryImpl::setCurrentFCM(): $fcmTokenDto'); + return _fcmDatasource.setFCMToken(fcmTokenDto); + } + + @override + Future deleteFCMToken(String accountId) { + return _fcmDatasource.deleteFCMToken(accountId); + } +} \ No newline at end of file diff --git a/lib/features/push_notification/data/repository/firebase_repository_impl.dart b/lib/features/push_notification/data/repository/firebase_repository_impl.dart deleted file mode 100644 index 737acc1c5..000000000 --- a/lib/features/push_notification/data/repository/firebase_repository_impl.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:core/utils/app_logger.dart'; -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/data/datasource/firebase_datasource.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart'; - -class FirebaseRepositoryImpl extends FirebaseRepository { - - final FirebaseDatasource _firebaseDatasource; - - FirebaseRepositoryImpl(this._firebaseDatasource); - - @override - Future getCurrentFirebase() { - return _firebaseDatasource.getCurrentFirebase(); - } - - @override - Future setCurrentFirebase(FirebaseDto newCurrentFirebase) { - log('FirebaseRepositoryImpl::setCurrentFirebase(): $newCurrentFirebase'); - return _firebaseDatasource.setCurrentFirebase(newCurrentFirebase); - } - - @override - Future deleteCurrentFirebase(String token) { - return _firebaseDatasource.deleteCurrentFirebase(token); - } -} \ No newline at end of file diff --git a/lib/features/push_notification/domain/exceptions/fcm_exception.dart b/lib/features/push_notification/domain/exceptions/fcm_exception.dart new file mode 100644 index 000000000..a2756d2cb --- /dev/null +++ b/lib/features/push_notification/domain/exceptions/fcm_exception.dart @@ -0,0 +1,5 @@ +class NotFoundStoredFCMException implements Exception {} + +class NotSupportFCMException implements Exception {} + + diff --git a/lib/features/push_notification/domain/exceptions/firebase_exception.dart b/lib/features/push_notification/domain/exceptions/firebase_exception.dart deleted file mode 100644 index 8ad5393f9..000000000 --- a/lib/features/push_notification/domain/exceptions/firebase_exception.dart +++ /dev/null @@ -1,2 +0,0 @@ -class NotFoundStoredFirebaseException implements Exception {} - diff --git a/lib/features/push_notification/domain/repository/fcm_repository.dart b/lib/features/push_notification/domain/repository/fcm_repository.dart new file mode 100644 index 000000000..f8b759d34 --- /dev/null +++ b/lib/features/push_notification/domain/repository/fcm_repository.dart @@ -0,0 +1,9 @@ +import 'package:model/fcm/fcm_token_dto.dart'; + +abstract class FCMRepository { + Future getFCMToken(String accountId); + + Future setFCMToken(FCMTokenDto fcmTokenDto); + + Future deleteFCMToken(String accountId); +} \ No newline at end of file diff --git a/lib/features/push_notification/domain/repository/firebase_repository.dart b/lib/features/push_notification/domain/repository/firebase_repository.dart deleted file mode 100644 index 52e4a1dac..000000000 --- a/lib/features/push_notification/domain/repository/firebase_repository.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:model/firebase/firebase_dto.dart'; - -abstract class FirebaseRepository { - Future getCurrentFirebase(); - - Future setCurrentFirebase(FirebaseDto newCurrentFirebase); - - Future deleteCurrentFirebase(String token); -} \ No newline at end of file diff --git a/lib/features/push_notification/domain/state/delete_firebase_state.dart b/lib/features/push_notification/domain/state/delete_fcm_token_state.dart similarity index 50% rename from lib/features/push_notification/domain/state/delete_firebase_state.dart rename to lib/features/push_notification/domain/state/delete_fcm_token_state.dart index 6c1c6d1d9..f5bc3b78c 100644 --- a/lib/features/push_notification/domain/state/delete_firebase_state.dart +++ b/lib/features/push_notification/domain/state/delete_fcm_token_state.dart @@ -1,18 +1,18 @@ import 'package:core/core.dart'; -class DeleteFirebaseSuccess extends UIState { +class DeleteFCMTokenSuccess extends UIState { - DeleteFirebaseSuccess(); + DeleteFCMTokenSuccess(); @override List get props => []; } -class DeleteFirebaseFailure extends FeatureFailure { +class DeleteFCMTokenFailure extends FeatureFailure { final dynamic exception; - DeleteFirebaseFailure(this.exception); + DeleteFCMTokenFailure(this.exception); @override List get props => [exception]; diff --git a/lib/features/push_notification/domain/state/get_fcm_token_state.dart b/lib/features/push_notification/domain/state/get_fcm_token_state.dart new file mode 100644 index 000000000..e17d2ebbf --- /dev/null +++ b/lib/features/push_notification/domain/state/get_fcm_token_state.dart @@ -0,0 +1,21 @@ +import 'package:core/core.dart'; +import 'package:model/fcm/fcm_token_dto.dart'; + +class GetFCMTokenSuccess extends UIState { + + final FCMTokenDto firebaseDto; + + GetFCMTokenSuccess(this.firebaseDto); + + @override + List get props => [firebaseDto]; +} + +class GetFCMTokenFailure extends FeatureFailure { + final dynamic exception; + + GetFCMTokenFailure(this.exception); + + @override + List get props => [exception]; +} \ No newline at end of file diff --git a/lib/features/push_notification/domain/state/get_firebase_state.dart b/lib/features/push_notification/domain/state/get_firebase_state.dart deleted file mode 100644 index 9978729bc..000000000 --- a/lib/features/push_notification/domain/state/get_firebase_state.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:core/core.dart'; -import 'package:model/firebase/firebase_dto.dart'; - -class GetFirebaseSuccess extends UIState { - - final FirebaseDto firebaseDto; - - GetFirebaseSuccess(this.firebaseDto); - - @override - List get props => [firebaseDto]; -} - -class GetFirebaseFailure extends FeatureFailure { - final dynamic exception; - - GetFirebaseFailure(this.exception); - - @override - List get props => [exception]; -} \ No newline at end of file diff --git a/lib/features/push_notification/domain/state/save_firebase_state.dart b/lib/features/push_notification/domain/state/save_fcm_token_state.dart similarity index 51% rename from lib/features/push_notification/domain/state/save_firebase_state.dart rename to lib/features/push_notification/domain/state/save_fcm_token_state.dart index 740395e8f..84ece486b 100644 --- a/lib/features/push_notification/domain/state/save_firebase_state.dart +++ b/lib/features/push_notification/domain/state/save_fcm_token_state.dart @@ -1,18 +1,18 @@ import 'package:core/core.dart'; -class SaveFirebaseSuccess extends UIState { +class SaveFCMTokenSuccess extends UIState { - SaveFirebaseSuccess(); + SaveFCMTokenSuccess(); @override List get props => []; } -class SaveFirebaseFailure extends FeatureFailure { +class SaveFCMTokenFailure extends FeatureFailure { final dynamic exception; - SaveFirebaseFailure(this.exception); + SaveFCMTokenFailure(this.exception); @override List get props => [exception]; diff --git a/lib/features/push_notification/domain/usecases/delete_fcm_token_cache_interactor.dart b/lib/features/push_notification/domain/usecases/delete_fcm_token_cache_interactor.dart new file mode 100644 index 000000000..ef0bdd94e --- /dev/null +++ b/lib/features/push_notification/domain/usecases/delete_fcm_token_cache_interactor.dart @@ -0,0 +1,20 @@ +import 'package:core/core.dart'; +import 'package:dartz/dartz.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/state/delete_fcm_token_state.dart'; + +class DeleteFCMTokenCacheInteractor { + final FCMRepository _fcmRepository; + + DeleteFCMTokenCacheInteractor(this._fcmRepository); + + Stream> execute(String accountId) async* { + try { + await _fcmRepository.deleteFCMToken(accountId); + yield Right(DeleteFCMTokenSuccess()); + } catch (e) { + logError('DeleteFirebaseCacheInteractor::execute(): $e'); + yield Left(DeleteFCMTokenFailure(e)); + } + } +} diff --git a/lib/features/push_notification/domain/usecases/delete_firebase_cache_interactor.dart b/lib/features/push_notification/domain/usecases/delete_firebase_cache_interactor.dart deleted file mode 100644 index 447e29cf4..000000000 --- a/lib/features/push_notification/domain/usecases/delete_firebase_cache_interactor.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:core/core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/state/delete_firebase_state.dart'; - -class DeleteFirebaseCacheInteractor { - final FirebaseRepository _firebaseRepository; - - DeleteFirebaseCacheInteractor(this._firebaseRepository); - - Future> execute(String token) async { - try { - await _firebaseRepository.deleteCurrentFirebase(token); - return Right(DeleteFirebaseSuccess()); - } catch (e) { - logError('DeleteFirebaseCacheInteractor::execute(): $e'); - return Left(DeleteFirebaseFailure(e)); - } - } -} diff --git a/lib/features/push_notification/domain/usecases/get_fcm_token_cache_interactor.dart b/lib/features/push_notification/domain/usecases/get_fcm_token_cache_interactor.dart new file mode 100644 index 000000000..408a69802 --- /dev/null +++ b/lib/features/push_notification/domain/usecases/get_fcm_token_cache_interactor.dart @@ -0,0 +1,23 @@ + +import 'package:core/core.dart'; +import 'package:dartz/dartz.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/state/get_fcm_token_state.dart'; + +class GetFCMTokenCacheInteractor { + + final FCMRepository _fcmRepository; + + GetFCMTokenCacheInteractor(this._fcmRepository); + + Stream> execute( + String accountId) async* { + try { + final fcmToken = await _fcmRepository.getFCMToken(accountId); + yield Right(GetFCMTokenSuccess(fcmToken)); + } catch (e) { + logError('GetFirebaseCacheInteractor::execute(): $e'); + yield Left(GetFCMTokenFailure(e)); + } + } +} \ No newline at end of file diff --git a/lib/features/push_notification/domain/usecases/get_firebase_cache_interactor.dart b/lib/features/push_notification/domain/usecases/get_firebase_cache_interactor.dart deleted file mode 100644 index bed918af0..000000000 --- a/lib/features/push_notification/domain/usecases/get_firebase_cache_interactor.dart +++ /dev/null @@ -1,25 +0,0 @@ - -import 'package:core/core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:model/model.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/state/get_firebase_state.dart'; - -class GetFirebaseCacheInteractor { - - final FirebaseRepository _firebaseRepository; - - GetFirebaseCacheInteractor(this._firebaseRepository); - - Future> execute( - OIDCConfiguration config, - String refreshToken) async { - try { - final firebase = await _firebaseRepository.getCurrentFirebase(); - return Right(GetFirebaseSuccess(firebase)); - } catch (e) { - logError('GetFirebaseCacheInteractor::execute(): $e'); - return Left(GetFirebaseFailure(e)); - } - } -} \ No newline at end of file diff --git a/lib/features/push_notification/domain/usecases/save_fcm_token_cache_interactor.dart b/lib/features/push_notification/domain/usecases/save_fcm_token_cache_interactor.dart new file mode 100644 index 000000000..bbcfd91db --- /dev/null +++ b/lib/features/push_notification/domain/usecases/save_fcm_token_cache_interactor.dart @@ -0,0 +1,21 @@ +import 'package:core/core.dart'; +import 'package:dartz/dartz.dart'; +import 'package:model/fcm/fcm_token_dto.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/state/save_fcm_token_state.dart'; + +class SaveFCMTokenCacheInteractor { + final FCMRepository _fcmRepository; + + SaveFCMTokenCacheInteractor(this._fcmRepository); + + Stream> execute(FCMTokenDto fcmTokenDto) async* { + try { + await _fcmRepository.setFCMToken(fcmTokenDto); + yield Right(SaveFCMTokenSuccess()); + } catch (e) { + logError('SaveFirebaseCacheInteractor::execute(): $e'); + yield Left(SaveFCMTokenFailure(e)); + } + } +} diff --git a/lib/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart b/lib/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart deleted file mode 100644 index 619b78106..000000000 --- a/lib/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:core/core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/state/save_firebase_state.dart'; - -class SaveFirebaseCacheInteractor { - final FirebaseRepository _firebaseRepository; - - SaveFirebaseCacheInteractor(this._firebaseRepository); - - Future> execute(FirebaseDto firebaseDto) async { - try { - await _firebaseRepository.setCurrentFirebase(firebaseDto); - return Right(SaveFirebaseSuccess()); - } catch (e) { - logError('SaveFirebaseCacheInteractor::execute(): $e'); - return Left(SaveFirebaseFailure(e)); - } - } -} diff --git a/lib/features/push_notification/presentation/firebase_bindings.dart b/lib/features/push_notification/presentation/firebase_bindings.dart index e01b83345..2d4ea898e 100644 --- a/lib/features/push_notification/presentation/firebase_bindings.dart +++ b/lib/features/push_notification/presentation/firebase_bindings.dart @@ -1,46 +1,46 @@ import 'package:get/get.dart'; import 'package:tmail_ui_user/features/base/base_bindings.dart'; -import 'package:tmail_ui_user/features/push_notification/data/datasource/firebase_datasource.dart'; -import 'package:tmail_ui_user/features/push_notification/data/datasource_impl/hive_account_datasource_impl.dart'; -import 'package:tmail_ui_user/features/push_notification/data/local/firebase_cache_manager.dart'; -import 'package:tmail_ui_user/features/push_notification/data/repository/firebase_repository_impl.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/repository/firebase_repository.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_firebase_cache_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_firebase_cache_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.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/hive_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/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_fcm_token_cache_interactor.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_fcm_token_cache_interactor.dart'; +import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_fcm_token_cache_interactor.dart'; import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart'; -class FireBaseBindings extends BaseBindings { +class FCMBindings extends BaseBindings { @override void bindingsController() {} @override void bindingsDataSource() { - Get.put(Get.find()); + Get.put(Get.find()); } @override void bindingsDataSourceImpl() { - Get.put(HiveFirebaseDatasourceImpl( - Get.find(), + Get.put(HiveFCMDatasourceImpl( + Get.find(), Get.find(), )); } @override void bindingsInteractor() { - Get.put(DeleteFirebaseCacheInteractor(Get.find())); - Get.put(SaveFirebaseCacheInteractor(Get.find())); - Get.put(GetFirebaseCacheInteractor(Get.find())); + Get.put(DeleteFCMTokenCacheInteractor(Get.find())); + Get.put(SaveFCMTokenCacheInteractor(Get.find())); + Get.put(GetFCMTokenCacheInteractor(Get.find())); } @override void bindingsRepository() { - Get.put(Get.find()); + Get.put(Get.find()); } @override void bindingsRepositoryImpl() { - Get.put(FirebaseRepositoryImpl(Get.find())); + Get.put(FCMRepositoryImpl(Get.find())); } } diff --git a/lib/features/push_notification/presentation/notification_service.dart b/lib/features/push_notification/presentation/notification_service.dart deleted file mode 100644 index 99245e8f9..000000000 --- a/lib/features/push_notification/presentation/notification_service.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:async'; - -import 'package:core/utils/app_logger.dart'; -import 'package:firebase_core/firebase_core.dart'; -import 'package:firebase_messaging/firebase_messaging.dart'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; -import 'package:get/get.dart'; -import 'package:model/firebase/firebase_dto.dart'; -import 'package:tmail_ui_user/features/push_notification/domain/usecases/save_firebase_cache_interactor.dart'; -import 'package:tmail_ui_user/features/push_notification/presentation/firebase_options.dart'; - -@pragma('vm:entry-point') -Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { - await dotenv.load(fileName: 'env.file'); - try { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); - } catch (e) { - log('NotificationService::initializeNotificationService(): $e'); - } - log('firebaseMessagingBackgroundHandler: ${message.data}'); -} - -class NotificationService { - factory NotificationService() => _instance; - - NotificationService._internal(); - - static final NotificationService _instance = NotificationService._internal(); - - static get _firebaseMessaging => FirebaseMessaging.instance; - - static Stream get onTokenRefresh => _firebaseMessaging.onTokenRefresh; - static bool _isFlutterLocalNotificationsInitialized = false; - - static Future initializeNotificationService() async { - try { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); - } catch (e) { - log('NotificationService::initializeNotificationService(): $e'); - } - FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); - if (_isFlutterLocalNotificationsInitialized) return; - final _saveFirebaseCacheInteractor = Get.find(); - final token = await _firebaseMessaging.getToken(); - _saveFirebaseCacheInteractor.execute(FirebaseDto(token)); - await _initFirebaseMessaging(); - _isFlutterLocalNotificationsInitialized = true; - } - - static Future _initFirebaseMessaging() async { - FirebaseMessaging.onMessage.listen(_handleIncomingForegroundNotification); - FirebaseMessaging.onMessageOpenedApp.listen(_handleOpenedAppNotification); - } - - static Future _handleIncomingForegroundNotification( - RemoteMessage remoteMessage, - ) async { - log('firebaseMessagingForegroundHandler: ${remoteMessage.data}'); - } - - static void _handleOpenedAppNotification(RemoteMessage remoteMessage) {} - - - static Future deleteToken() async => _firebaseMessaging.deleteToken(); -} diff --git a/lib/main.dart b/lib/main.dart index 6c7a85fea..6eeb9b775 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,11 +1,10 @@ import 'package:core/core.dart'; -import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:get/get.dart'; import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; -import 'package:tmail_ui_user/features/push_notification/presentation/firebase_options.dart'; import 'package:tmail_ui_user/main/bindings/main_bindings.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations_delegate.dart'; @@ -15,7 +14,6 @@ import 'package:tmail_ui_user/main/routes/app_routes.dart'; import 'package:worker_manager/worker_manager.dart'; void main() async { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); initLogger(() async { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( @@ -28,6 +26,7 @@ void main() async { await HiveCacheConfig().setUp(); await HiveCacheConfig.initializeEncryptionKey(); await Executor().warmUp(); + await dotenv.load(fileName: 'env.file'); runApp(const TMailApp()); }); } diff --git a/lib/main/bindings/local/local_bindings.dart b/lib/main/bindings/local/local_bindings.dart index 4dba52bae..bf02a7218 100644 --- a/lib/main/bindings/local/local_bindings.dart +++ b/lib/main/bindings/local/local_bindings.dart @@ -6,7 +6,7 @@ import 'package:tmail_ui_user/features/caching/authentication_info_cache_client. import 'package:tmail_ui_user/features/caching/caching_manager.dart'; import 'package:tmail_ui_user/features/caching/email_cache_client.dart'; import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart'; -import 'package:tmail_ui_user/features/caching/firebase_config_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/fcm_token_cache_client.dart'; import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; import 'package:tmail_ui_user/features/caching/recent_login_url_cache_client.dart'; import 'package:tmail_ui_user/features/caching/recent_login_username_cache_client.dart'; @@ -23,7 +23,7 @@ import 'package:tmail_ui_user/features/login/data/local/oidc_configuration_cache import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart'; -import 'package:tmail_ui_user/features/push_notification/data/local/firebase_cache_manager.dart'; +import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.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'; @@ -57,15 +57,15 @@ class LocalBindings extends Bindings { Get.put(RecentLoginUrlCacheManager((Get.find()))); Get.put(RecentLoginUsernameCacheClient()); Get.put(RecentLoginUsernameCacheManager(Get.find())); - Get.put(FirebaseCacheClient()); - Get.put(FirebaseCacheManager(Get.find())); + Get.put(FcmTokenCacheClient()); + Get.put(FCMCacheManager(Get.find())); Get.put(CachingManager( Get.find(), Get.find(), Get.find(), Get.find(), Get.find(), - Get.find(), + Get.find(), )); } diff --git a/lib/main/utils/app_config.dart b/lib/main/utils/app_config.dart index 8f1aa31ff..a841d28e2 100644 --- a/lib/main/utils/app_config.dart +++ b/lib/main/utils/app_config.dart @@ -12,4 +12,13 @@ class AppConfig { return false; } static String appDashboardConfigurationPath = "configurations/app_dashboard.json"; + static bool get appFCMAvailable { + final supported = dotenv.get('FCM_AVAILABLE', fallback: 'unsupported'); + if (supported == 'supported') { + return true; + } + return false; + } + static String appFCMConfigurationPath = "configurations/env.fcm"; + } \ No newline at end of file diff --git a/model/lib/fcm/fcm_token_dto.dart b/model/lib/fcm/fcm_token_dto.dart new file mode 100644 index 000000000..1061e724b --- /dev/null +++ b/model/lib/fcm/fcm_token_dto.dart @@ -0,0 +1,17 @@ +import 'package:equatable/equatable.dart'; + +class FCMTokenDto with EquatableMixin { + final String token; + final String accountId; + + FCMTokenDto( + this.token, + this.accountId, + ); + + @override + List get props => [ + token, + accountId, + ]; +} diff --git a/model/lib/firebase/firebase_dto.dart b/model/lib/firebase/firebase_dto.dart deleted file mode 100644 index 539543cf6..000000000 --- a/model/lib/firebase/firebase_dto.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:equatable/equatable.dart'; - -class FirebaseDto with EquatableMixin { - final String token; - - FirebaseDto(this.token); - - @override - List get props => [token]; -} \ No newline at end of file