Merge branch '10-fix_registration' into 'develop'

Fix registration on unified poc app

See merge request e/os/ntfy-android!10
This commit is contained in:
Mohammed Althaf Thayyil 2024-07-04 04:43:01 +00:00
commit 3e28ee2722
3 changed files with 20 additions and 6 deletions

View file

@ -40,6 +40,7 @@ import io.heckel.ntfy.msg.DownloadType
import io.heckel.ntfy.msg.NotificationDispatcher import io.heckel.ntfy.msg.NotificationDispatcher
import io.heckel.ntfy.service.SubscriberService import io.heckel.ntfy.service.SubscriberService
import io.heckel.ntfy.service.SubscriberServiceManager import io.heckel.ntfy.service.SubscriberServiceManager
import io.heckel.ntfy.up.TOPIC_MURENA
import io.heckel.ntfy.util.* import io.heckel.ntfy.util.*
import io.heckel.ntfy.work.DeleteWorker import io.heckel.ntfy.work.DeleteWorker
import io.heckel.ntfy.work.PollWorker import io.heckel.ntfy.work.PollWorker
@ -203,7 +204,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
val subscriptions = repository.getSubscriptions() val subscriptions = repository.getSubscriptions()
val defaultTopic = "murena_notification" val defaultTopic = TOPIC_MURENA
val hasTestTopic = subscriptions.any { it.topic == defaultTopic } val hasTestTopic = subscriptions.any { it.topic == defaultTopic }
if (hasTestTopic) { if (hasTestTopic) {
return@launch return@launch

View file

@ -69,12 +69,17 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
// Add subscription // Add subscription
val baseUrl = repository.getDefaultBaseUrl() ?: context.getString(R.string.app_base_url) val baseUrl = repository.getDefaultBaseUrl() ?: context.getString(R.string.app_base_url)
var topic = UP_PREFIX + randomString(TOPIC_RANDOM_ID_LENGTH) var topic = UP_PREFIX + randomString(TOPIC_RANDOM_ID_LENGTH)
if (appId == "foundation.e.unifiedpoc") { if (appId == PACKAGE_MURENA_UNIFIED_PUSH) {
topic = "murena_notification" topic = TOPIC_MURENA
} }
val endpoint = topicUrlUp(baseUrl, topic) 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( val subscription = Subscription(
id = randomSubscriptionId(), id = subscriptionId,
baseUrl = baseUrl, baseUrl = baseUrl,
topic = topic, topic = topic,
instant = true, // No Firebase, always instant! instant = true, // No Firebase, always instant!
@ -92,10 +97,15 @@ class BroadcastReceiver : android.content.BroadcastReceiver() {
newCount = 0, newCount = 0,
lastActive = Date().time/1000 lastActive = Date().time/1000
) )
Log.d(TAG, "Adding subscription with for app $appId (connectorToken $connectorToken): $subscription")
try { try {
// Note, this may fail due to a SQL constraint exception, see https://github.com/binwiederhier/ntfy/issues/185 // Note, this may fail due to a SQL constraint exception, see https://github.com/binwiederhier/ntfy/issues/185
repository.addSubscription(subscription) 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) distributor.sendEndpoint(appId, connectorToken, endpoint)
// Refresh (and maybe start) foreground service // Refresh (and maybe start) foreground service

View file

@ -20,3 +20,6 @@ const val EXTRA_TOKEN = "token"
const val EXTRA_ENDPOINT = "endpoint" const val EXTRA_ENDPOINT = "endpoint"
const val EXTRA_MESSAGE = "message" const val EXTRA_MESSAGE = "message"
const val EXTRA_BYTES_MESSAGE = "bytesMessage" const val EXTRA_BYTES_MESSAGE = "bytesMessage"
const val PACKAGE_MURENA_UNIFIED_PUSH = "foundation.e.unifiedpoc"
const val TOPIC_MURENA = "murena_notification"