Skip to content

Commit

Permalink
[push] add registration process logs
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Jan 4, 2025
1 parent 141c23e commit fc991b2
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions app/src/main/java/me/capcom/smsgateway/services/PushService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.events.EventBus
import me.capcom.smsgateway.modules.gateway.workers.RegistrationWorker
import me.capcom.smsgateway.modules.gateway.workers.WebhooksUpdateWorker
import me.capcom.smsgateway.modules.logs.LogsService
import me.capcom.smsgateway.modules.logs.db.LogEntry
import me.capcom.smsgateway.modules.push.Event
import me.capcom.smsgateway.modules.push.events.PushMessageEnqueuedEvent
import me.capcom.smsgateway.modules.push.payloads.MessagesExportRequestedPayload
Expand Down Expand Up @@ -68,26 +70,40 @@ class PushService : FirebaseMessagingService(), KoinComponent {
super.onDestroy()
}

companion object {
companion object : KoinComponent {
fun register(context: Context): Unit {
val logger = get<LogsService>()

logger.insert(
priority = LogEntry.Priority.INFO,
module = PushService::class.java.simpleName,
message = "FCM registration started"
)
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Toast.makeText(
context,
"Fetching FCM registration token failed: ${task.exception}",
Toast.LENGTH_LONG
).show()
Log.w(
this::class.java.name,
"Fetching FCM registration token failed",
task.exception
logger.insert(
priority = LogEntry.Priority.ERROR,
module = PushService::class.java.simpleName,
message = "Fetching FCM registration token failed: ${task.exception}"
)
return@OnCompleteListener
}

// Get new FCM registration token
val token = task.result

logger.insert(
priority = LogEntry.Priority.INFO,
module = PushService::class.java.simpleName,
message = "FCM registration successful",
mapOf("token" to token)
)

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

0 comments on commit fc991b2

Please sign in to comment.