Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fcm] allow empty token #163

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading