From e992e72f4d8068e9134ab8c53475c7cde2109923 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 28 Nov 2023 22:17:01 -0500 Subject: [PATCH] Making sure the service manager stops the relay subscriptions before disconnecting. --- .../vitorpamplona/amethyst/ServiceManager.kt | 32 +++++++++---------- .../amethyst/service/NostrDataSource.kt | 10 ++++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ServiceManager.kt b/app/src/main/java/com/vitorpamplona/amethyst/ServiceManager.kt index 54fbbcb4a..36907086c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ServiceManager.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ServiceManager.kt @@ -102,23 +102,23 @@ class ServiceManager { private fun pause() { Log.d("ServiceManager", "Pausing Relay Services") - NostrAccountDataSource.stop() - NostrHomeDataSource.stop() - NostrChannelDataSource.stop() - NostrChatroomDataSource.stop() - NostrChatroomListDataSource.stop() - NostrDiscoveryDataSource.stop() + NostrAccountDataSource.stopSync() + NostrHomeDataSource.stopSync() + NostrChannelDataSource.stopSync() + NostrChatroomDataSource.stopSync() + NostrChatroomListDataSource.stopSync() + NostrDiscoveryDataSource.stopSync() - NostrCommunityDataSource.stop() - NostrHashtagDataSource.stop() - NostrGeohashDataSource.stop() - NostrSearchEventOrUserDataSource.stop() - NostrSingleChannelDataSource.stop() - NostrSingleEventDataSource.stop() - NostrSingleUserDataSource.stop() - NostrThreadDataSource.stop() - NostrUserProfileDataSource.stop() - NostrVideoDataSource.stop() + NostrCommunityDataSource.stopSync() + NostrHashtagDataSource.stopSync() + NostrGeohashDataSource.stopSync() + NostrSearchEventOrUserDataSource.stopSync() + NostrSingleChannelDataSource.stopSync() + NostrSingleEventDataSource.stopSync() + NostrSingleUserDataSource.stopSync() + NostrThreadDataSource.stopSync() + NostrUserProfileDataSource.stopSync() + NostrVideoDataSource.stopSync() Client.disconnect() isStarted = false diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt index d2c514a47..bff736a82 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt @@ -119,6 +119,16 @@ abstract class NostrDataSource(val debugName: String) { } } + open fun stopSync() { + active = false + println("DataSource: ${this.javaClass.simpleName} Stop") + + subscriptions.values.forEach { subscription -> + Client.close(subscription.id) + subscription.typedFilters = null + } + } + fun requestNewChannel(onEOSE: ((Long, String) -> Unit)? = null): Subscription { val newSubscription = Subscription(UUID.randomUUID().toString().substring(0, 4), onEOSE) subscriptions = subscriptions + Pair(newSubscription.id, newSubscription)