Android-side fix for binary unifiedpush messages #101
This commit is contained in:
parent
0968a39420
commit
5fb3ae0536
4 changed files with 22 additions and 8 deletions
|
@ -57,13 +57,12 @@ class Log(private val logsDao: LogsDao) {
|
|||
return getInstance()?.record?.get() ?: false
|
||||
}
|
||||
|
||||
fun init(context: Context): Log {
|
||||
fun init(context: Context) {
|
||||
return synchronized(Log::class) {
|
||||
if (instance == null) {
|
||||
val database = Database.getInstance(context.applicationContext)
|
||||
instance = Log(database.logsDao())
|
||||
}
|
||||
instance!!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ data class Message(
|
|||
val click: String?,
|
||||
val title: String?,
|
||||
val message: String,
|
||||
val encoding: String?,
|
||||
val attachment: MessageAttachment?,
|
||||
)
|
||||
|
||||
|
@ -26,3 +27,5 @@ data class MessageAttachment(
|
|||
val expires: Long?,
|
||||
val url: String,
|
||||
)
|
||||
|
||||
const val MESSAGE_ENCODING_BASE64 = "base64"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.heckel.ntfy.msg
|
||||
|
||||
import android.util.Base64
|
||||
import com.google.gson.Gson
|
||||
import io.heckel.ntfy.data.Attachment
|
||||
import io.heckel.ntfy.data.Notification
|
||||
|
@ -19,6 +20,11 @@ class NotificationParser {
|
|||
if (message.event != ApiService.EVENT_MESSAGE) {
|
||||
return null
|
||||
}
|
||||
val decodedMessage = if (message.encoding == MESSAGE_ENCODING_BASE64) {
|
||||
String(Base64.decode(message.message, Base64.DEFAULT))
|
||||
} else {
|
||||
message.message
|
||||
}
|
||||
val attachment = if (message.attachment?.url != null) {
|
||||
Attachment(
|
||||
name = message.attachment.name,
|
||||
|
@ -33,7 +39,7 @@ class NotificationParser {
|
|||
subscriptionId = subscriptionId,
|
||||
timestamp = message.time,
|
||||
title = message.title ?: "",
|
||||
message = message.message,
|
||||
message = decodedMessage,
|
||||
priority = toPriority(message.priority),
|
||||
tags = joinTags(message.tags),
|
||||
click = message.click ?: "",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.heckel.ntfy.firebase
|
||||
|
||||
import android.content.Intent
|
||||
import android.util.Base64
|
||||
import com.google.firebase.messaging.FirebaseMessagingService
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import io.heckel.ntfy.R
|
||||
|
@ -23,11 +24,10 @@ class FirebaseService : FirebaseMessagingService() {
|
|||
private val job = SupervisorJob()
|
||||
private val messenger = FirebaseMessenger()
|
||||
|
||||
init {
|
||||
Log.init(this) // Init in all entrypoints
|
||||
}
|
||||
|
||||
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
||||
// Init log (this is done in all entrypoints)
|
||||
Log.init(this)
|
||||
|
||||
// We only process data messages
|
||||
if (remoteMessage.data.isEmpty()) {
|
||||
Log.d(TAG, "Discarding unexpected message (1): from=${remoteMessage.from}")
|
||||
|
@ -63,6 +63,7 @@ class FirebaseService : FirebaseMessagingService() {
|
|||
val priority = data["priority"]?.toIntOrNull()
|
||||
val tags = data["tags"]
|
||||
val click = data["click"]
|
||||
val encoding = data["encoding"]
|
||||
val attachmentName = data["attachment_name"] ?: "attachment.bin"
|
||||
val attachmentType = data["attachment_type"]
|
||||
val attachmentSize = data["attachment_size"]?.toLongOrNull()
|
||||
|
@ -86,6 +87,11 @@ class FirebaseService : FirebaseMessagingService() {
|
|||
}
|
||||
|
||||
// Add notification
|
||||
val decodedMessage = if (encoding == MESSAGE_ENCODING_BASE64) {
|
||||
String(Base64.decode(message, Base64.DEFAULT))
|
||||
} else {
|
||||
message
|
||||
}
|
||||
val attachment = if (attachmentUrl != null) {
|
||||
Attachment(
|
||||
name = attachmentName,
|
||||
|
@ -100,7 +106,7 @@ class FirebaseService : FirebaseMessagingService() {
|
|||
subscriptionId = subscription.id,
|
||||
timestamp = timestamp,
|
||||
title = title ?: "",
|
||||
message = message,
|
||||
message = decodedMessage,
|
||||
priority = toPriority(priority),
|
||||
tags = tags ?: "",
|
||||
click = click ?: "",
|
||||
|
|
Loading…
Reference in a new issue