Skip to content

Commit

Permalink
refactor: runBlocking -> launch로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimhm0728 committed Jan 4, 2025
1 parent cd9811f commit d38b6ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@ package com.mulberry.ody.data.local.service
import android.content.Context
import com.mulberry.ody.data.local.db.OdyDatastore
import com.mulberry.ody.domain.common.toMilliSeconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
import java.time.LocalDateTime
import javax.inject.Inject

class EtaDashboard
@Inject
constructor(
val context: Context,
val odyDatastore: OdyDatastore,
@Inject
constructor(
val context: Context,
val odyDatastore: OdyDatastore,
) {
fun open(
meetingId: Long,
meetingTime: LocalDateTime,
) {
fun open(
meetingId: Long,
meetingTime: LocalDateTime,
) {
CoroutineScope(Dispatchers.Default).launch {
if (!isLoggedIn()) {
return
return@launch
}
val meetingTimeMills = meetingTime.toMilliSeconds()
val serviceIntent = EtaDashboardService.getIntent(context, meetingId, meetingTimeMills, isOpen = true)
context.startForegroundService(serviceIntent)
}

private fun isLoggedIn(): Boolean {
return runBlocking { odyDatastore.getAuthToken().first().isSuccess }
startEtaDashboardService(meetingId, meetingTime)
}
}

private suspend fun isLoggedIn(): Boolean {
return coroutineScope { odyDatastore.getAuthToken().first().isSuccess }
}

private fun startEtaDashboardService(
meetingId: Long,
meetingTime: LocalDateTime,
) {
val meetingTimeMills = meetingTime.toMilliSeconds()
val serviceIntent = EtaDashboardService.getIntent(context, meetingId, meetingTimeMills, isOpen = true)
context.startForegroundService(serviceIntent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.mulberry.ody.domain.model.FCMNotificationType
import com.mulberry.ody.domain.model.FCMType
import com.mulberry.ody.presentation.notification.FCMNotification
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject
Expand Down Expand Up @@ -42,7 +44,7 @@ class FCMService : FirebaseMessagingService() {
}

override fun onNewToken(token: String) {
runBlocking {
CoroutineScope(Dispatchers.Default).launch {
odyDatastore.setFCMToken(token)
}
}
Expand Down

0 comments on commit d38b6ed

Please sign in to comment.