Making sure the service manager stops the relay subscriptions before disconnecting.

This commit is contained in:
Vitor Pamplona
2023-11-28 22:17:01 -05:00
parent 1c545ee33a
commit e992e72f4d
2 changed files with 26 additions and 16 deletions
@@ -102,23 +102,23 @@ class ServiceManager {
private fun pause() { private fun pause() {
Log.d("ServiceManager", "Pausing Relay Services") Log.d("ServiceManager", "Pausing Relay Services")
NostrAccountDataSource.stop() NostrAccountDataSource.stopSync()
NostrHomeDataSource.stop() NostrHomeDataSource.stopSync()
NostrChannelDataSource.stop() NostrChannelDataSource.stopSync()
NostrChatroomDataSource.stop() NostrChatroomDataSource.stopSync()
NostrChatroomListDataSource.stop() NostrChatroomListDataSource.stopSync()
NostrDiscoveryDataSource.stop() NostrDiscoveryDataSource.stopSync()
NostrCommunityDataSource.stop() NostrCommunityDataSource.stopSync()
NostrHashtagDataSource.stop() NostrHashtagDataSource.stopSync()
NostrGeohashDataSource.stop() NostrGeohashDataSource.stopSync()
NostrSearchEventOrUserDataSource.stop() NostrSearchEventOrUserDataSource.stopSync()
NostrSingleChannelDataSource.stop() NostrSingleChannelDataSource.stopSync()
NostrSingleEventDataSource.stop() NostrSingleEventDataSource.stopSync()
NostrSingleUserDataSource.stop() NostrSingleUserDataSource.stopSync()
NostrThreadDataSource.stop() NostrThreadDataSource.stopSync()
NostrUserProfileDataSource.stop() NostrUserProfileDataSource.stopSync()
NostrVideoDataSource.stop() NostrVideoDataSource.stopSync()
Client.disconnect() Client.disconnect()
isStarted = false isStarted = false
@@ -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 { fun requestNewChannel(onEOSE: ((Long, String) -> Unit)? = null): Subscription {
val newSubscription = Subscription(UUID.randomUUID().toString().substring(0, 4), onEOSE) val newSubscription = Subscription(UUID.randomUUID().toString().substring(0, 4), onEOSE)
subscriptions = subscriptions + Pair(newSubscription.id, newSubscription) subscriptions = subscriptions + Pair(newSubscription.id, newSubscription)