Fix registration on unified poc app
This commit is contained in:
parent
125fe48297
commit
a6cd89247c
3 changed files with 20 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
|
||||
// Refresh (and maybe start) foreground service
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue