Fix FirebaseService

This commit is contained in:
Philipp Heckel 2022-09-07 16:51:09 -04:00
parent 433fad761a
commit 35ea6de6f8

View file

@ -1,17 +1,16 @@
package io.heckel.ntfy.firebase package io.heckel.ntfy.firebase
import android.content.Intent import android.content.Intent
import android.util.Base64
import androidx.work.* import androidx.work.*
import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage import com.google.firebase.messaging.RemoteMessage
import io.heckel.ntfy.R import io.heckel.ntfy.R
import io.heckel.ntfy.app.Application import io.heckel.ntfy.app.Application
import io.heckel.ntfy.db.Attachment import io.heckel.ntfy.db.Attachment
import io.heckel.ntfy.db.Icon
import io.heckel.ntfy.db.Notification import io.heckel.ntfy.db.Notification
import io.heckel.ntfy.util.Log import io.heckel.ntfy.util.Log
import io.heckel.ntfy.msg.ApiService import io.heckel.ntfy.msg.ApiService
import io.heckel.ntfy.msg.MESSAGE_ENCODING_BASE64
import io.heckel.ntfy.msg.NotificationDispatcher import io.heckel.ntfy.msg.NotificationDispatcher
import io.heckel.ntfy.msg.NotificationParser import io.heckel.ntfy.msg.NotificationParser
import io.heckel.ntfy.service.SubscriberService import io.heckel.ntfy.service.SubscriberService
@ -90,6 +89,7 @@ class FirebaseService : FirebaseMessagingService() {
val priority = data["priority"]?.toIntOrNull() val priority = data["priority"]?.toIntOrNull()
val tags = data["tags"] val tags = data["tags"]
val click = data["click"] val click = data["click"]
val iconUrl = data["icon"]
val actions = data["actions"] // JSON array as string, sigh ... val actions = data["actions"] // JSON array as string, sigh ...
val encoding = data["encoding"] val encoding = data["encoding"]
val attachmentName = data["attachment_name"] ?: "attachment.bin" val attachmentName = data["attachment_name"] ?: "attachment.bin"
@ -124,6 +124,7 @@ class FirebaseService : FirebaseMessagingService() {
url = attachmentUrl, url = attachmentUrl,
) )
} else null } else null
val icon: Icon? = iconUrl?.let { Icon(url = it) }
val notification = Notification( val notification = Notification(
id = id, id = id,
subscriptionId = subscription.id, subscriptionId = subscription.id,
@ -134,6 +135,7 @@ class FirebaseService : FirebaseMessagingService() {
priority = toPriority(priority), priority = toPriority(priority),
tags = tags ?: "", tags = tags ?: "",
click = click ?: "", click = click ?: "",
icon = icon,
actions = parser.parseActions(actions), actions = parser.parseActions(actions),
attachment = attachment, attachment = attachment,
notificationId = Random.nextInt(), notificationId = Random.nextInt(),