TF-1205: rename class
This commit is contained in:
@@ -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<void> 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');
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+3
-3
@@ -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<FirebaseCache> {
|
||||
class FcmTokenCacheClient extends HiveCacheClient<FCMTokenCache> {
|
||||
|
||||
@override
|
||||
String get tableName => 'FirebaseCache';
|
||||
String get tableName => 'FCMTokenCache';
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+1
-20
@@ -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<ScaffoldState>();
|
||||
final selectedMailbox = Rxn<PresentationMailbox>();
|
||||
@@ -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<void> injectFirebaseBindings(Session? session, AccountId? accountId) async {
|
||||
try {
|
||||
super.injectFirebaseBindings(session, accountId);
|
||||
_saveFirebaseCacheInteractor = Get.find<SaveFirebaseCacheInteractor>();
|
||||
await NotificationService.initializeNotificationService();
|
||||
NotificationService.onTokenRefresh.listen((token) {
|
||||
_saveFirebaseCacheInteractor?.execute(FirebaseDto(token));
|
||||
});
|
||||
} catch (e) {
|
||||
logError('MailboxDashBoardController::injectVacationBindings(): $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> _getAppVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
log('MailboxDashBoardController::_getAppVersion(): ${info.version}');
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
import 'package:model/fcm/fcm_token_dto.dart';
|
||||
|
||||
abstract class FCMDatasource {
|
||||
Future<FCMTokenDto> getFCMToken(String accountId);
|
||||
|
||||
Future<void> setFCMToken(FCMTokenDto fcmToken);
|
||||
|
||||
Future<void> deleteFCMToken(String accountId);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'package:model/firebase/firebase_dto.dart';
|
||||
|
||||
abstract class FirebaseDatasource {
|
||||
Future<FirebaseDto> getCurrentFirebase();
|
||||
|
||||
Future<void> setCurrentFirebase(FirebaseDto newCurrentFirebase);
|
||||
|
||||
Future<void> deleteCurrentFirebase(String token);
|
||||
}
|
||||
@@ -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<FirebaseDto> getCurrentFirebase() {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.getFirebase();
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentFirebase(FirebaseDto newCurrentFirebase) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.setFirebase(newCurrentFirebase);
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteCurrentFirebase(String token) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.deleteFirebase(token);
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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<FCMTokenDto> getFCMToken(String accountId) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.getFCMToken(accountId);
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setFCMToken(FCMTokenDto fcmToken) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.setFCMToken(fcmToken);
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteFCMToken(String accountId) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.deleteFCMToken(accountId);
|
||||
}).catchError((error) {
|
||||
_exceptionThrower.throwException(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<FCMTokenDto> 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<void> setFCMToken(FCMTokenDto firebaseDto) {
|
||||
log('FCMCacheManager::setFCM(): $_fcmTokenCacheClient');
|
||||
return _fcmTokenCacheClient.insertItem(firebaseDto.accountId, firebaseDto.toCache());
|
||||
}
|
||||
|
||||
Future<void> deleteFCMToken(String accountId) {
|
||||
log('FCMCacheManager::deleteSelectedFCM(): $accountId');
|
||||
return _fcmTokenCacheClient.deleteItem(accountId);
|
||||
}
|
||||
}
|
||||
@@ -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<FirebaseDto> 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<void> setFirebase(FirebaseDto firebaseDto) {
|
||||
log('FirebaseCacheManager::setFirebase(): $_firebaseCacheClient');
|
||||
return _firebaseCacheClient.insertItem(firebaseDto.token, firebaseDto.toCache());
|
||||
}
|
||||
|
||||
Future<void> deleteFirebase(String token) {
|
||||
log('FirebaseCacheManager::deleteSelectedFirebase(): $token');
|
||||
return _firebaseCacheClient.deleteItem(token);
|
||||
}
|
||||
}
|
||||
@@ -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<Object?> get props => [token];
|
||||
}
|
||||
@@ -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<Object?> get props => [token];
|
||||
}
|
||||
@@ -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<FCMTokenDto> getFCMToken(String accountId) {
|
||||
return _fcmDatasource.getFCMToken(accountId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setFCMToken(FCMTokenDto fcmTokenDto) {
|
||||
log('FCMRepositoryImpl::setCurrentFCM(): $fcmTokenDto');
|
||||
return _fcmDatasource.setFCMToken(fcmTokenDto);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteFCMToken(String accountId) {
|
||||
return _fcmDatasource.deleteFCMToken(accountId);
|
||||
}
|
||||
}
|
||||
@@ -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<FirebaseDto> getCurrentFirebase() {
|
||||
return _firebaseDatasource.getCurrentFirebase();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setCurrentFirebase(FirebaseDto newCurrentFirebase) {
|
||||
log('FirebaseRepositoryImpl::setCurrentFirebase(): $newCurrentFirebase');
|
||||
return _firebaseDatasource.setCurrentFirebase(newCurrentFirebase);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteCurrentFirebase(String token) {
|
||||
return _firebaseDatasource.deleteCurrentFirebase(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class NotFoundStoredFCMException implements Exception {}
|
||||
|
||||
class NotSupportFCMException implements Exception {}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
class NotFoundStoredFirebaseException implements Exception {}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:model/fcm/fcm_token_dto.dart';
|
||||
|
||||
abstract class FCMRepository {
|
||||
Future<FCMTokenDto> getFCMToken(String accountId);
|
||||
|
||||
Future<void> setFCMToken(FCMTokenDto fcmTokenDto);
|
||||
|
||||
Future<void> deleteFCMToken(String accountId);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'package:model/firebase/firebase_dto.dart';
|
||||
|
||||
abstract class FirebaseRepository {
|
||||
Future<FirebaseDto> getCurrentFirebase();
|
||||
|
||||
Future<void> setCurrentFirebase(FirebaseDto newCurrentFirebase);
|
||||
|
||||
Future<void> deleteCurrentFirebase(String token);
|
||||
}
|
||||
+4
-4
@@ -1,18 +1,18 @@
|
||||
import 'package:core/core.dart';
|
||||
|
||||
class DeleteFirebaseSuccess extends UIState {
|
||||
class DeleteFCMTokenSuccess extends UIState {
|
||||
|
||||
|
||||
DeleteFirebaseSuccess();
|
||||
DeleteFCMTokenSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DeleteFirebaseFailure extends FeatureFailure {
|
||||
class DeleteFCMTokenFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
DeleteFirebaseFailure(this.exception);
|
||||
DeleteFCMTokenFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
@@ -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<Object> get props => [firebaseDto];
|
||||
}
|
||||
|
||||
class GetFCMTokenFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetFCMTokenFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -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<Object> get props => [firebaseDto];
|
||||
}
|
||||
|
||||
class GetFirebaseFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetFirebaseFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
+4
-4
@@ -1,18 +1,18 @@
|
||||
import 'package:core/core.dart';
|
||||
|
||||
class SaveFirebaseSuccess extends UIState {
|
||||
class SaveFCMTokenSuccess extends UIState {
|
||||
|
||||
|
||||
SaveFirebaseSuccess();
|
||||
SaveFCMTokenSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SaveFirebaseFailure extends FeatureFailure {
|
||||
class SaveFCMTokenFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
SaveFirebaseFailure(this.exception);
|
||||
SaveFCMTokenFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
@@ -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<Either<Failure, Success>> execute(String accountId) async* {
|
||||
try {
|
||||
await _fcmRepository.deleteFCMToken(accountId);
|
||||
yield Right<Failure, Success>(DeleteFCMTokenSuccess());
|
||||
} catch (e) {
|
||||
logError('DeleteFirebaseCacheInteractor::execute(): $e');
|
||||
yield Left<Failure, Success>(DeleteFCMTokenFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> execute(String token) async {
|
||||
try {
|
||||
await _firebaseRepository.deleteCurrentFirebase(token);
|
||||
return Right<Failure, Success>(DeleteFirebaseSuccess());
|
||||
} catch (e) {
|
||||
logError('DeleteFirebaseCacheInteractor::execute(): $e');
|
||||
return Left<Failure, Success>(DeleteFirebaseFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> execute(
|
||||
String accountId) async* {
|
||||
try {
|
||||
final fcmToken = await _fcmRepository.getFCMToken(accountId);
|
||||
yield Right<Failure, Success>(GetFCMTokenSuccess(fcmToken));
|
||||
} catch (e) {
|
||||
logError('GetFirebaseCacheInteractor::execute(): $e');
|
||||
yield Left<Failure, Success>(GetFCMTokenFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> execute(
|
||||
OIDCConfiguration config,
|
||||
String refreshToken) async {
|
||||
try {
|
||||
final firebase = await _firebaseRepository.getCurrentFirebase();
|
||||
return Right<Failure, Success>(GetFirebaseSuccess(firebase));
|
||||
} catch (e) {
|
||||
logError('GetFirebaseCacheInteractor::execute(): $e');
|
||||
return Left<Failure, Success>(GetFirebaseFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> execute(FCMTokenDto fcmTokenDto) async* {
|
||||
try {
|
||||
await _fcmRepository.setFCMToken(fcmTokenDto);
|
||||
yield Right<Failure, Success>(SaveFCMTokenSuccess());
|
||||
} catch (e) {
|
||||
logError('SaveFirebaseCacheInteractor::execute(): $e');
|
||||
yield Left<Failure, Success>(SaveFCMTokenFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Either<Failure, Success>> execute(FirebaseDto firebaseDto) async {
|
||||
try {
|
||||
await _firebaseRepository.setCurrentFirebase(firebaseDto);
|
||||
return Right<Failure, Success>(SaveFirebaseSuccess());
|
||||
} catch (e) {
|
||||
logError('SaveFirebaseCacheInteractor::execute(): $e');
|
||||
return Left<Failure, Success>(SaveFirebaseFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<FirebaseDatasource>(Get.find<HiveFirebaseDatasourceImpl>());
|
||||
Get.put<FCMDatasource>(Get.find<HiveFCMDatasourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.put(HiveFirebaseDatasourceImpl(
|
||||
Get.find<FirebaseCacheManager>(),
|
||||
Get.put(HiveFCMDatasourceImpl(
|
||||
Get.find<FCMCacheManager>(),
|
||||
Get.find<CacheExceptionThrower>(),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.put(DeleteFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(SaveFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(GetFirebaseCacheInteractor(Get.find<FirebaseRepositoryImpl>()));
|
||||
Get.put(DeleteFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.put(SaveFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
Get.put(GetFCMTokenCacheInteractor(Get.find<FCMRepositoryImpl>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {
|
||||
Get.put<FirebaseRepository>(Get.find<FirebaseRepositoryImpl>());
|
||||
Get.put<FCMRepository>(Get.find<FCMRepositoryImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {
|
||||
Get.put(FirebaseRepositoryImpl(Get.find<FirebaseDatasource>()));
|
||||
Get.put(FCMRepositoryImpl(Get.find<FCMDatasource>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<void> 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<String> get onTokenRefresh => _firebaseMessaging.onTokenRefresh;
|
||||
static bool _isFlutterLocalNotificationsInitialized = false;
|
||||
|
||||
static Future<void> 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<SaveFirebaseCacheInteractor>();
|
||||
final token = await _firebaseMessaging.getToken();
|
||||
_saveFirebaseCacheInteractor.execute(FirebaseDto(token));
|
||||
await _initFirebaseMessaging();
|
||||
_isFlutterLocalNotificationsInitialized = true;
|
||||
}
|
||||
|
||||
static Future<void> _initFirebaseMessaging() async {
|
||||
FirebaseMessaging.onMessage.listen(_handleIncomingForegroundNotification);
|
||||
FirebaseMessaging.onMessageOpenedApp.listen(_handleOpenedAppNotification);
|
||||
}
|
||||
|
||||
static Future<void> _handleIncomingForegroundNotification(
|
||||
RemoteMessage remoteMessage,
|
||||
) async {
|
||||
log('firebaseMessagingForegroundHandler: ${remoteMessage.data}');
|
||||
}
|
||||
|
||||
static void _handleOpenedAppNotification(RemoteMessage remoteMessage) {}
|
||||
|
||||
|
||||
static Future<void> deleteToken() async => _firebaseMessaging.deleteToken();
|
||||
}
|
||||
Reference in New Issue
Block a user