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

Commit a6cd8924 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury Committed by Mohammed Althaf T
Browse files

Fix registration on unified poc app

parent 125fe482
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import io.heckel.ntfy.msg.DownloadType
import io.heckel.ntfy.msg.NotificationDispatcher
import io.heckel.ntfy.service.SubscriberService
import io.heckel.ntfy.service.SubscriberServiceManager
import io.heckel.ntfy.up.TOPIC_MURENA
import io.heckel.ntfy.util.*
import io.heckel.ntfy.work.DeleteWorker
import io.heckel.ntfy.work.PollWorker
@@ -203,7 +204,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc

        lifecycleScope.launch(Dispatchers.IO) {
            val subscriptions = repository.getSubscriptions()
            val defaultTopic = "murena_notification"
            val defaultTopic = TOPIC_MURENA
            val hasTestTopic = subscriptions.any { it.topic == defaultTopic }
            if (hasTestTopic) {
                return@launch
+15 −5
Original line number Diff line number Diff line
@@ -69,12 +69,17 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
                // Add subscription
                val baseUrl = repository.getDefaultBaseUrl() ?: context.getString(R.string.app_base_url)
                var topic = UP_PREFIX + randomString(TOPIC_RANDOM_ID_LENGTH)
                if (appId == "foundation.e.unifiedpoc") {
                    topic = "murena_notification"
                if (appId == PACKAGE_MURENA_UNIFIED_PUSH) {
                    topic = TOPIC_MURENA
                }
                val endpoint = topicUrlUp(baseUrl, topic)
                val subscriptionId =
                    appId.takeIf { it == PACKAGE_MURENA_UNIFIED_PUSH }?.run {
                        repository.getSubscriptions()
                            .find { it.baseUrl == baseUrl && it.topic == topic }?.id
                    } ?: randomSubscriptionId()
                val subscription = Subscription(
                    id = randomSubscriptionId(),
                    id = subscriptionId,
                    baseUrl = baseUrl,
                    topic = topic,
                    instant = true, // No Firebase, always instant!
@@ -92,10 +97,15 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
                    newCount = 0,
                    lastActive = Date().time/1000
                )
                Log.d(TAG, "Adding subscription with for app $appId (connectorToken $connectorToken): $subscription")
                try {
                    // Note, this may fail due to a SQL constraint exception, see https://github.com/binwiederhier/ntfy/issues/185
                    if (appId == PACKAGE_MURENA_UNIFIED_PUSH) {
                        Log.d(TAG, "Updating subscription with for app $appId (connectorToken $connectorToken): $subscription")
                        repository.updateSubscription(subscription)
                    } else {
                        Log.d(TAG, "Adding subscription with for app $appId (connectorToken $connectorToken): $subscription")
                        repository.addSubscription(subscription)
                    }
                    distributor.sendEndpoint(appId, connectorToken, endpoint)

                    // Refresh (and maybe start) foreground service
+3 −0
Original line number Diff line number Diff line
@@ -20,3 +20,6 @@ const val EXTRA_TOKEN = "token"
const val EXTRA_ENDPOINT = "endpoint"
const val EXTRA_MESSAGE = "message"
const val EXTRA_BYTES_MESSAGE = "bytesMessage"

const val PACKAGE_MURENA_UNIFIED_PUSH = "foundation.e.unifiedpoc"
const val TOPIC_MURENA = "murena_notification"