diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt index 3afabdb..d79424b 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt @@ -7,6 +7,7 @@ import io.heckel.ntfy.db.Subscription import io.heckel.ntfy.util.Log import io.heckel.ntfy.up.Distributor import io.heckel.ntfy.util.decodeBytesMessage +import io.heckel.ntfy.util.decodeBytesTitle import io.heckel.ntfy.util.safeLet /** @@ -39,7 +40,12 @@ class NotificationDispatcher(val context: Context, val repository: Repository) { } if (distribute) { safeLet(subscription.upAppId, subscription.upConnectorToken) { appId, connectorToken -> - distributor.sendMessage(appId, connectorToken, decodeBytesMessage(notification)) + distributor.sendMessage( + appId, + connectorToken, + decodeBytesMessage(notification), + decodeBytesTitle(notification), + ) } } if (downloadAttachment && downloadIcon) { diff --git a/app/src/main/java/io/heckel/ntfy/up/Constants.kt b/app/src/main/java/io/heckel/ntfy/up/Constants.kt index a94fc56..ab7c990 100644 --- a/app/src/main/java/io/heckel/ntfy/up/Constants.kt +++ b/app/src/main/java/io/heckel/ntfy/up/Constants.kt @@ -19,7 +19,9 @@ const val EXTRA_APPLICATION = "application" const val EXTRA_TOKEN = "token" const val EXTRA_ENDPOINT = "endpoint" const val EXTRA_MESSAGE = "message" +const val EXTRA_TITLE = "title" const val EXTRA_BYTES_MESSAGE = "bytesMessage" +const val EXTRA_BYTES_TITLE = "bytesTitle" const val PACKAGE_MURENA_UNIFIED_PUSH = "foundation.e.unifiedpoc" const val TOPIC_MURENA = "murena_notification" diff --git a/app/src/main/java/io/heckel/ntfy/up/Distributor.kt b/app/src/main/java/io/heckel/ntfy/up/Distributor.kt index b6f9cce..195f8af 100644 --- a/app/src/main/java/io/heckel/ntfy/up/Distributor.kt +++ b/app/src/main/java/io/heckel/ntfy/up/Distributor.kt @@ -9,14 +9,16 @@ import io.heckel.ntfy.util.Log * See https://unifiedpush.org/spec/android/ for details. */ class Distributor(val context: Context) { - fun sendMessage(app: String, connectorToken: String, message: ByteArray) { + fun sendMessage(app: String, connectorToken: String, message: ByteArray, title: ByteArray) { Log.d(TAG, "Sending MESSAGE to $app (token=$connectorToken): ${message.size} bytes") val broadcastIntent = Intent() broadcastIntent.`package` = app broadcastIntent.action = ACTION_MESSAGE broadcastIntent.putExtra(EXTRA_TOKEN, connectorToken) broadcastIntent.putExtra(EXTRA_MESSAGE, String(message)) // UTF-8 + broadcastIntent.putExtra(EXTRA_TITLE, String(title)) // UTF-8 broadcastIntent.putExtra(EXTRA_BYTES_MESSAGE, message) + broadcastIntent.putExtra(EXTRA_BYTES_TITLE, title) context.sendBroadcast(broadcastIntent) } diff --git a/app/src/main/java/io/heckel/ntfy/util/Util.kt b/app/src/main/java/io/heckel/ntfy/util/Util.kt index 2ffbb76..820828f 100644 --- a/app/src/main/java/io/heckel/ntfy/util/Util.kt +++ b/app/src/main/java/io/heckel/ntfy/util/Util.kt @@ -170,18 +170,26 @@ fun decodeMessage(notification: Notification): String { } } -fun decodeBytesMessage(notification: Notification): ByteArray { +fun decodeBytes(notification: Notification, string: String): ByteArray { return try { if (notification.encoding == MESSAGE_ENCODING_BASE64) { - Base64.decode(notification.message, Base64.DEFAULT) + Base64.decode(string, Base64.DEFAULT) } else { - notification.message.toByteArray() + string.toByteArray() } } catch (e: IllegalArgumentException) { - notification.message.toByteArray() + string.toByteArray() } } +fun decodeBytesMessage(notification: Notification): ByteArray { + return decodeBytes(notification, notification.message) +} + +fun decodeBytesTitle(notification: Notification): ByteArray { + return decodeBytes(notification, notification.title) +} + /** * See above; prepend emojis to title if the title is non-empty. * Otherwise, they are prepended to the message.