From 182819670be31c0ff4e0a46c204850d80ff205d0 Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 3 Jul 2024 11:16:01 +0530 Subject: [PATCH] subscribe to a topic by default --- .../java/io/heckel/ntfy/ui/MainActivity.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index ea43f08..bcab10a 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -207,6 +207,36 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc // Permissions maybeRequestNotificationPermission() + + lifecycleScope.launch(Dispatchers.IO) { + val subscriptions = repository.getSubscriptions() + val defaultTopic = "murena_notification" + val hasTestTopic = subscriptions.any { it.topic == defaultTopic } + if (hasTestTopic) { + return@launch + } + + val subscription = Subscription( + id = randomSubscriptionId(), + baseUrl = appBaseUrl!!, + topic = defaultTopic, + instant = true, + dedicatedChannels = false, + mutedUntil = 0, + minPriority = Repository.MIN_PRIORITY_USE_GLOBAL, + autoDelete = Repository.AUTO_DELETE_USE_GLOBAL, + insistent = Repository.INSISTENT_MAX_PRIORITY_USE_GLOBAL, + lastNotificationId = null, + icon = null, + upAppId = null, + upConnectorToken = null, + displayName = null, + totalCount = 0, + newCount = 0, + lastActive = Date().time / 1000 + ) + viewModel.add(subscription) + } } private fun maybeRequestNotificationPermission() {