From b4a74b0470326c89c8d18492056b47fcaab489fb Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 21 Jan 2025 23:30:40 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[FEATURE]#217=20:=20FCM=20Token=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20/=20=EC=98=A4=ED=86=A0=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=EC=84=A4=EC=A0=95=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/firebase/messaging/MessagingDataSource.kt | 4 ++++ .../firebase/messaging/MessagingDataSourceImpl.kt | 10 ++++++++++ .../firebase/messaging/MessagingRepositoryImpl.kt | 4 ++++ .../firebase/messaging/MessagingRepository.kt | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt index 9756cc9a..d56cda4d 100644 --- a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt +++ b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt @@ -2,4 +2,8 @@ package com.bff.wespot.data.remote.source.firebase.messaging interface MessagingDataSource { suspend fun getFcmToken(): String + + suspend fun removeFcmToken() + + suspend fun initMessaging() } diff --git a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt index 9f9b891e..02b49ed8 100644 --- a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt +++ b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt @@ -1,5 +1,6 @@ package com.bff.wespot.data.remote.source.firebase.messaging +import com.bff.wespot.data.remote.extensions.await import com.google.firebase.messaging.FirebaseMessaging import kotlinx.coroutines.suspendCancellableCoroutine import timber.log.Timber @@ -17,4 +18,13 @@ class MessagingDataSourceImpl @Inject constructor( } } } + + override suspend fun removeFcmToken() { + messaging.isAutoInitEnabled = false + messaging.deleteToken().await() + } + + override suspend fun initMessaging() { + messaging.isAutoInitEnabled = true + } } diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt index 4fe352bb..7eeab0a4 100644 --- a/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt +++ b/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt @@ -8,4 +8,8 @@ class MessagingRepositoryImpl @Inject constructor( private val messagingDataSource: MessagingDataSource, ): MessagingRepository { override suspend fun getFcmToken(): String = messagingDataSource.getFcmToken() + + override suspend fun removeFcmToken() = messagingDataSource.removeFcmToken() + + override suspend fun initMessaging() = messagingDataSource.initMessaging() } diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt b/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt index 95721f29..b157a68d 100644 --- a/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt +++ b/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt @@ -2,4 +2,8 @@ package com.bff.wespot.domain.repository.firebase.messaging interface MessagingRepository { suspend fun getFcmToken(): String + + suspend fun removeFcmToken() + + suspend fun initMessaging() } From 5bdc548f4ea9ed75a75ec007ff1d60e618760179 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 21 Jan 2025 23:31:04 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[FEATURE]#217=20:=20SuspendCoroutine=20?= =?UTF-8?q?=EC=9D=B5=EC=8A=A4=ED=85=90=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/remote/extensions/TaskExtensions.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 data-remote/src/main/kotlin/com/bff/wespot/data/remote/extensions/TaskExtensions.kt diff --git a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/extensions/TaskExtensions.kt b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/extensions/TaskExtensions.kt new file mode 100644 index 00000000..2d75d57d --- /dev/null +++ b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/extensions/TaskExtensions.kt @@ -0,0 +1,23 @@ +package com.bff.wespot.data.remote.extensions + +import com.google.android.gms.tasks.Task +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.suspendCancellableCoroutine +import timber.log.Timber +import kotlin.coroutines.resumeWithException + +@OptIn(ExperimentalCoroutinesApi::class) +suspend fun Task.await(): T { + return suspendCancellableCoroutine { cont -> + addOnCompleteListener { + val exception = it.exception + if (exception != null) { + cont.resumeWithException(exception) + Timber.e(exception) + } else { + cont.resume(it.result, null) + Timber.d(it.result.toString()) + } + } + } +} From c9a283da4f3eab2e1b6fc19111b658fd459bee62 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 21 Jan 2025 23:32:04 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[FEATURE]#217=20:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83/=ED=83=88=ED=87=B4=EC=8B=9C=20FCM=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=82=AD=EC=A0=9C=20=EC=A0=81=EC=9A=A9=20?= =?UTF-8?q?/=20supervisorScope=EC=97=90=EC=84=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bff/wespot/entire/viewmodel/EntireViewModel.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/feature/entire/src/main/java/com/bff/wespot/entire/viewmodel/EntireViewModel.kt b/feature/entire/src/main/java/com/bff/wespot/entire/viewmodel/EntireViewModel.kt index 4a8a2a13..7f43e644 100644 --- a/feature/entire/src/main/java/com/bff/wespot/entire/viewmodel/EntireViewModel.kt +++ b/feature/entire/src/main/java/com/bff/wespot/entire/viewmodel/EntireViewModel.kt @@ -7,6 +7,7 @@ import com.bff.wespot.domain.repository.BasePagingRepository import com.bff.wespot.domain.repository.DataStoreRepository import com.bff.wespot.domain.repository.auth.AuthRepository import com.bff.wespot.domain.repository.firebase.config.RemoteConfigRepository +import com.bff.wespot.domain.repository.firebase.messaging.MessagingRepository import com.bff.wespot.domain.repository.message.MessageStorageRepository import com.bff.wespot.domain.repository.user.ProfileRepository import com.bff.wespot.domain.util.RemoteConfigKey @@ -22,6 +23,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch +import kotlinx.coroutines.supervisorScope import org.orbitmvi.orbit.ContainerHost import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect @@ -35,6 +37,7 @@ class EntireViewModel @Inject constructor( private val profileRepository: ProfileRepository, private val authRepository: AuthRepository, private val remoteConfigRepository: RemoteConfigRepository, + private val messagingRepository: MessagingRepository, private val messageStorageRepository: MessageStorageRepository, private val dataStoreRepository: DataStoreRepository, private val messageBlockedRepository: BasePagingRepository>, @@ -124,9 +127,12 @@ class EntireViewModel @Inject constructor( } private fun clearCachedData() { - viewModelScope.launch { - launch { dataStoreRepository.clear() } - launch { profileRepository.clearProfile() } + viewModelScope.launch(coroutineDispatcher) { + supervisorScope { + launch { dataStoreRepository.clear() } + launch { profileRepository.clearProfile() } + launch { messagingRepository.removeFcmToken() } + } } } From e225abf586bed2d1ba39ce6f22432261a6d241a8 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 21 Jan 2025 23:32:50 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[CHORE]#217=20:=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=B3=80=EC=88=98=20=20minVersion=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/bff/wespot/splash/SplashViewModel.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/bff/wespot/splash/SplashViewModel.kt b/app/src/main/kotlin/com/bff/wespot/splash/SplashViewModel.kt index fe5b65b1..6e256519 100644 --- a/app/src/main/kotlin/com/bff/wespot/splash/SplashViewModel.kt +++ b/app/src/main/kotlin/com/bff/wespot/splash/SplashViewModel.kt @@ -3,7 +3,6 @@ package com.bff.wespot.splash import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.bff.wespot.domain.repository.firebase.config.RemoteConfigRepository -import com.bff.wespot.domain.util.RemoteConfigKey import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -12,20 +11,14 @@ import javax.inject.Inject @HiltViewModel class SplashViewModel @Inject constructor( - private val dataSource: RemoteConfigRepository + private val remoteConfigRepository: RemoteConfigRepository, ) : ViewModel() { private val _start = MutableStateFlow(false) val start = _start.asStateFlow() - private val _minVersion = MutableStateFlow("") - val minVersion = _minVersion.asStateFlow() - init { viewModelScope.launch { - _start.value = dataSource.startRemoteConfig() - if (_start.value) { - _minVersion.emit(dataSource.fetchFromRemoteConfig(RemoteConfigKey.MIN_VERSION)) - } + _start.value = remoteConfigRepository.startRemoteConfig() } } -} \ No newline at end of file +} From 43b32b6cdfad042f3e7bc4fd5965f0b2b8f28b6a Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 21 Jan 2025 23:35:00 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[CHORE]#217=20:=20FCM=20=ED=86=A0=ED=81=B0?= =?UTF-8?q?=20=EB=A1=9C=EB=93=9C=20=EC=8B=9C=EC=97=90,=20initRefresh=20?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/messaging/MessagingDataSource.kt | 2 -- .../firebase/messaging/MessagingDataSourceImpl.kt | 15 ++------------- .../firebase/messaging/MessagingRepositoryImpl.kt | 2 -- .../firebase/messaging/MessagingRepository.kt | 2 -- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt index d56cda4d..7949b3b1 100644 --- a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt +++ b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSource.kt @@ -4,6 +4,4 @@ interface MessagingDataSource { suspend fun getFcmToken(): String suspend fun removeFcmToken() - - suspend fun initMessaging() } diff --git a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt index 02b49ed8..654a195c 100644 --- a/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt +++ b/data-remote/src/main/kotlin/com/bff/wespot/data/remote/source/firebase/messaging/MessagingDataSourceImpl.kt @@ -2,29 +2,18 @@ package com.bff.wespot.data.remote.source.firebase.messaging import com.bff.wespot.data.remote.extensions.await import com.google.firebase.messaging.FirebaseMessaging -import kotlinx.coroutines.suspendCancellableCoroutine -import timber.log.Timber import javax.inject.Inject class MessagingDataSourceImpl @Inject constructor( private val messaging: FirebaseMessaging, ) : MessagingDataSource { override suspend fun getFcmToken(): String { - return suspendCancellableCoroutine { continuation -> - messaging.token.addOnCompleteListener { - continuation.resumeWith(Result.success(it.result)) - }.addOnFailureListener { - Timber.e("Update FcmToken Failed Exception : ", it) - } - } + messaging.isAutoInitEnabled = true + return messaging.token.await() } override suspend fun removeFcmToken() { messaging.isAutoInitEnabled = false messaging.deleteToken().await() } - - override suspend fun initMessaging() { - messaging.isAutoInitEnabled = true - } } diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt index 7eeab0a4..e6684a1b 100644 --- a/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt +++ b/data/src/main/kotlin/com/bff/wespot/data/repository/firebase/messaging/MessagingRepositoryImpl.kt @@ -10,6 +10,4 @@ class MessagingRepositoryImpl @Inject constructor( override suspend fun getFcmToken(): String = messagingDataSource.getFcmToken() override suspend fun removeFcmToken() = messagingDataSource.removeFcmToken() - - override suspend fun initMessaging() = messagingDataSource.initMessaging() } diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt b/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt index b157a68d..6ce15e40 100644 --- a/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt +++ b/domain/src/main/kotlin/com/bff/wespot/domain/repository/firebase/messaging/MessagingRepository.kt @@ -4,6 +4,4 @@ interface MessagingRepository { suspend fun getFcmToken(): String suspend fun removeFcmToken() - - suspend fun initMessaging() }