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 Dec 25, 2024
1 parent a867675 commit e2966b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 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 @@ -55,7 +55,7 @@ class PushService : FirebaseMessagingService(), KoinComponent {
companion object {
fun register(context: Context): Unit {
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 Down

0 comments on commit e2966b7

Please sign in to comment.