Skip to content

Commit

Permalink
[push,gateway] fix device registration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Mar 15, 2024
1 parent f2d8441 commit a67b794
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions app/src/main/java/me/capcom/smsgateway/services/PushService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.gateway.PullMessagesWorker
import me.capcom.smsgateway.modules.gateway.RegistrationWorker
Expand All @@ -19,25 +16,15 @@ class PushService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
settingsHelper.fcmToken = token

scope.launch {
RegistrationWorker.start(this@PushService, token)
}
RegistrationWorker.start(this@PushService, token)
}

override fun onMessageReceived(message: RemoteMessage) {
Log.d(this.javaClass.name, message.data.toString())
PullMessagesWorker.start(this)
}

override fun onDestroy() {
job.cancel()
super.onDestroy()
}

companion object {
private val job = SupervisorJob()
private val scope = CoroutineScope(job)

fun register(context: Context): Unit {
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Expand All @@ -49,9 +36,7 @@ class PushService : FirebaseMessagingService() {
val token = task.result

// Log and toast
scope.launch {
RegistrationWorker.start(context, token)
}
RegistrationWorker.start(context, token)
})
}
}
Expand Down

0 comments on commit a67b794

Please sign in to comment.