Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2318e28f authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '11-get_title' into 'develop'

add title in notificationDispatcher

See merge request !11
parents 6f9d4bff bb6adde0
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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) {
+2 −0
Original line number Diff line number Diff line
@@ -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"
+3 −1
Original line number Diff line number Diff line
@@ -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)
    }

+12 −4
Original line number Diff line number Diff line
@@ -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)
}

/**