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