From 5eb3a350467e9697f15f3aa626c1225fb392757d Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Thu, 29 Dec 2022 17:03:25 +0700 Subject: [PATCH] TF-1289: [Data] Implement GetSubscription in fcm repository --- .../push_notification/data/local/fcm_cache_manager.dart | 9 +++++++++ .../data/repository/fcm_repository_impl.dart | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/lib/features/push_notification/data/local/fcm_cache_manager.dart b/lib/features/push_notification/data/local/fcm_cache_manager.dart index 7037005b1..06f4291d7 100644 --- a/lib/features/push_notification/data/local/fcm_cache_manager.dart +++ b/lib/features/push_notification/data/local/fcm_cache_manager.dart @@ -49,4 +49,13 @@ class FCMCacheManager { return _fcmSubscriptionCacheClient.insertItem( FCMSubscriptionCache.keyCacheValue, fcmSubscriptionCache); } + + Future getSubscription() async { + final _fcmSubscription = await _fcmSubscriptionCacheClient.getItem(FCMSubscriptionCache.keyCacheValue); + if (_fcmSubscription == null) { + throw NotFoundSubscriptionException(); + } else { + return _fcmSubscription; + } + } } \ 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 index cee7d8741..62843a1fd 100644 --- a/lib/features/push_notification/data/repository/fcm_repository_impl.dart +++ b/lib/features/push_notification/data/repository/fcm_repository_impl.dart @@ -85,6 +85,12 @@ class FCMRepositoryImpl extends FCMRepository { Future registerNewToken(RegisterNewTokenRequest newTokenRequest) { return _fcmDatasource[DataSourceType.network]!.registerNewToken(newTokenRequest); } + + @override + Future getSubscription() async { + final _fcmSubScription = await _fcmDatasource[DataSourceType.local]!.geSubscription(); + return FCMSubscription(_fcmSubScription.deviceId, _fcmSubScription.subscriptionId); + } @override Future storeSubscription(FCMSubscription fcmSubscription) {