Loading app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading Loading @@ -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) { Loading app/src/main/java/io/heckel/ntfy/up/Constants.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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" app/src/main/java/io/heckel/ntfy/up/Distributor.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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) } Loading app/src/main/java/io/heckel/ntfy/util/Util.kt +12 −4 Original line number Diff line number Diff line Loading @@ -170,16 +170,24 @@ 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) } /** Loading Loading
app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading Loading @@ -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) { Loading
app/src/main/java/io/heckel/ntfy/up/Constants.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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"
app/src/main/java/io/heckel/ntfy/up/Distributor.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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) } Loading
app/src/main/java/io/heckel/ntfy/util/Util.kt +12 −4 Original line number Diff line number Diff line Loading @@ -170,16 +170,24 @@ 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) } /** Loading