mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 00:03:24 +02:00
Solves the hanging AccountViewModel scope when Amethyst is forced closed.
This commit is contained in:
@@ -30,7 +30,6 @@ import com.vitorpamplona.amethyst.ui.dal.FeedFilter
|
|||||||
import com.vitorpamplona.amethyst.ui.feeds.FeedContentState
|
import com.vitorpamplona.amethyst.ui.feeds.FeedContentState
|
||||||
import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent
|
import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@@ -48,11 +47,8 @@ abstract class FeedViewModel(
|
|||||||
|
|
||||||
override fun invalidateData(ignoreIfDoing: Boolean) = feedState.invalidateData(ignoreIfDoing)
|
override fun invalidateData(ignoreIfDoing: Boolean) = feedState.invalidateData(ignoreIfDoing)
|
||||||
|
|
||||||
private var collectorJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}")
|
Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}")
|
||||||
collectorJob =
|
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
LocalCache.live.newEventBundles.collect { newNotes ->
|
LocalCache.live.newEventBundles.collect { newNotes ->
|
||||||
Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}")
|
Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}")
|
||||||
@@ -63,7 +59,6 @@ abstract class FeedViewModel(
|
|||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
||||||
collectorJob?.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,6 @@ import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -99,17 +98,11 @@ open class UserFeedViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectorJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d("Init", "${this.javaClass.simpleName}")
|
Log.d("Init", "${this.javaClass.simpleName}")
|
||||||
collectorJob =
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
LocalCache.live.newEventBundles.collect { newNotes ->
|
LocalCache.live.newEventBundles.collect { newNotes ->
|
||||||
checkNotInMainThread()
|
Log.d("Rendering Metrics", "Update feeds: ${this@UserFeedViewModel.javaClass.simpleName} with ${newNotes.size}")
|
||||||
|
|
||||||
invalidateData()
|
invalidateData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +111,6 @@ open class UserFeedViewModel(
|
|||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
||||||
bundler.cancel()
|
bundler.cancel()
|
||||||
collectorJob?.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.CardFeedState
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.CombinedZap
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.CombinedZap
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
import com.vitorpamplona.amethyst.ui.tor.TorSettings
|
import com.vitorpamplona.amethyst.ui.tor.TorSettings
|
||||||
import com.vitorpamplona.ammolite.relays.BundledInsert
|
|
||||||
import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
|
import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
|
||||||
import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryBaseEvent
|
import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryBaseEvent
|
||||||
import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryReadingStateEvent
|
import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryReadingStateEvent
|
||||||
@@ -135,7 +134,6 @@ import kotlinx.collections.immutable.toImmutableSet
|
|||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -1224,13 +1222,8 @@ class AccountViewModel(
|
|||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = AccountViewModel(accountSettings, settings, app) as T
|
override fun <T : ViewModel> create(modelClass: Class<T>): T = AccountViewModel(accountSettings, settings, app) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
private var collectorJobNew: Job? = null
|
|
||||||
private var collectorJobDeleted: Job? = null
|
|
||||||
private val bundlerInsert = BundledInsert<Set<Note>>(3000, Dispatchers.Default)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d("Init", "AccountViewModel")
|
Log.d("Init", "AccountViewModel")
|
||||||
collectorJobNew =
|
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
feedStates.init()
|
feedStates.init()
|
||||||
// awaits for init to finish before starting to capture new events.
|
// awaits for init to finish before starting to capture new events.
|
||||||
@@ -1251,7 +1244,6 @@ class AccountViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collectorJobDeleted =
|
|
||||||
viewModelScope.launch(Dispatchers.Default) {
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
LocalCache.live.deletedEventBundles.collect { newNotes ->
|
LocalCache.live.deletedEventBundles.collect { newNotes ->
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
@@ -1270,9 +1262,6 @@ class AccountViewModel(
|
|||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
Log.d("Init", "AccountViewModel onCleared")
|
Log.d("Init", "AccountViewModel onCleared")
|
||||||
feedStates.destroy()
|
feedStates.destroy()
|
||||||
bundlerInsert.cancel()
|
|
||||||
collectorJobNew?.cancel()
|
|
||||||
collectorJobDeleted?.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,6 @@ import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -85,11 +84,8 @@ open class LnZapFeedViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectorJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d("Init", "${this.javaClass.simpleName}")
|
Log.d("Init", "${this.javaClass.simpleName}")
|
||||||
collectorJob =
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
@@ -104,7 +100,6 @@ open class LnZapFeedViewModel(
|
|||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
||||||
bundler.cancel()
|
bundler.cancel()
|
||||||
collectorJob?.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,6 @@ import com.vitorpamplona.ammolite.relays.BundledUpdate
|
|||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -98,17 +97,11 @@ open class StringFeedViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectorJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.d("Init", this.javaClass.simpleName)
|
Log.d("Init", this.javaClass.simpleName)
|
||||||
collectorJob =
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
LocalCache.live.newEventBundles.collect { newNotes ->
|
LocalCache.live.newEventBundles.collect { newNotes ->
|
||||||
checkNotInMainThread()
|
Log.d("Rendering Metrics", "Update feeds: ${this@StringFeedViewModel.javaClass.simpleName} with ${newNotes.size}")
|
||||||
|
|
||||||
invalidateData()
|
invalidateData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +110,6 @@ open class StringFeedViewModel(
|
|||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
Log.d("Init", "OnCleared: ${this.javaClass.simpleName}")
|
||||||
bundler.cancel()
|
bundler.cancel()
|
||||||
collectorJob?.cancel()
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user