diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/Note.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/Note.kt index 3e42a850f..a51bb17d8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/Note.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/Note.kt @@ -100,13 +100,13 @@ class Note(val idHex: String) { val live: NoteLiveData = NoteLiveData(this) // Refreshes observers in batches. - val scope = CoroutineScope(Job() + Dispatchers.Main) var handlerWaiting = false @Synchronized fun invalidateData() { if (handlerWaiting) return handlerWaiting = true + val scope = CoroutineScope(Job() + Dispatchers.Main) scope.launch { delay(100) live.refresh() diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt index 4c67fd08d..d8fb46170 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/User.kt @@ -113,13 +113,13 @@ class User(val pubkey: ByteArray) { val live: UserLiveData = UserLiveData(this) // Refreshes observers in batches. - val scope = CoroutineScope(Job() + Dispatchers.Main) var handlerWaiting = false @Synchronized fun invalidateData() { if (handlerWaiting) return handlerWaiting = true + val scope = CoroutineScope(Job() + Dispatchers.Main) scope.launch { delay(100) live.refresh() 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 9cc9e5bcc..b77cb42c1 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt @@ -148,21 +148,28 @@ abstract class NostrDataSource(val debugName: String) { channelIds.remove(channel.id) } - val scope = CoroutineScope(Job() + Dispatchers.IO) var handlerWaiting = false @Synchronized fun invalidateFilters() { if (handlerWaiting) return handlerWaiting = true + val scope = CoroutineScope(Job() + Dispatchers.IO) scope.launch { delay(200) - resetFilters() + resetFiltersSuspend() handlerWaiting = false } } fun resetFilters() { + val scope = CoroutineScope(Job() + Dispatchers.IO) + scope.launch { + resetFiltersSuspend() + } + } + + fun resetFiltersSuspend() { // saves the channels that are currently active val activeChannels = channels.filter { it.filter != null } // saves the current content to only update if it changes diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/RelayPool.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/RelayPool.kt index 405c3403f..fecb3d11e 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/RelayPool.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/RelayPool.kt @@ -3,6 +3,10 @@ package com.vitorpamplona.amethyst.service.relays import androidx.lifecycle.LiveData import com.vitorpamplona.amethyst.service.Constants import java.util.Collections +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch import nostr.postr.events.Event /** @@ -108,7 +112,10 @@ object RelayPool: Relay.Listener { val live: RelayPoolLiveData = RelayPoolLiveData(this) private fun refreshObservers() { - live.refresh() + val scope = CoroutineScope(Job() + Dispatchers.Main) + scope.launch { + live.refresh() + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt index 2d30f46d5..1b4193408 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt @@ -91,13 +91,13 @@ class CardFeedViewModel(val dataSource: NostrDataSource): ViewModel() { } } - val scope = CoroutineScope(Job() + Dispatchers.IO) var handlerWaiting = false @Synchronized fun invalidateData() { if (handlerWaiting) return handlerWaiting = true + val scope = CoroutineScope(Job() + Dispatchers.IO) scope.launch { delay(100) refresh() diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt index 992d43ebc..8e762defe 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt @@ -63,20 +63,13 @@ open class UserFeedViewModel(val dataSource: NostrDataSource): ViewModel() } } - fun refreshCurrentList() { - val state = feedContent.value - if (state is UserFeedState.Loaded) { - _feedContent.update { UserFeedState.Loaded(state.feed) } - } - } - - val scope = CoroutineScope(Job() + Dispatchers.IO) var handlerWaiting = false @Synchronized fun invalidateData() { if (handlerWaiting) return handlerWaiting = true + val scope = CoroutineScope(Job() + Dispatchers.IO) scope.launch { delay(100) refresh()