Skip to content

Commit

Permalink
[fcm] allow empty token
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Jan 6, 2025
1 parent fc991b2 commit 755f353
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class GatewayService(
)
}

internal suspend fun registerFcmToken(pushToken: String) {
internal suspend fun registerFcmToken(pushToken: String?) {
if (!settings.enabled) return

val settings = settings.registrationInfo
Expand All @@ -126,13 +126,15 @@ class GatewayService(
if (accessToken != null) {
// if there's an access token, try to update push token
try {
api.devicePatch(
accessToken,
GatewayApi.DevicePatchRequest(
settings.id,
pushToken
pushToken?.let {
api.devicePatch(
accessToken,
GatewayApi.DevicePatchRequest(
settings.id,
it
)
)
)
}
events.emit(
DeviceRegisteredEvent(
api.hostname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RegistrationWorker(

override suspend fun doWork(): Result {
try {
val token = inputData.getString(DATA_TOKEN) ?: return Result.failure()
val token = inputData.getString(DATA_TOKEN)

App.instance.gatewayService.registerFcmToken(token)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PushService : FirebaseMessagingService(), KoinComponent {
message = "FCM registration started"
)
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
if (!task.isSuccessful || task.isCanceled) {
Toast.makeText(
context,
"Fetching FCM registration token failed: ${task.exception}",
Expand All @@ -91,7 +91,6 @@ class PushService : FirebaseMessagingService(), KoinComponent {
module = PushService::class.java.simpleName,
message = "Fetching FCM registration token failed: ${task.exception}"
)
return@OnCompleteListener
}

// Get new FCM registration token
Expand Down

0 comments on commit 755f353

Please sign in to comment.