Separates init and restart from observables.

This commit is contained in:
Vitor Pamplona
2024-07-17 16:35:48 -04:00
parent 45446b4125
commit b1399d1c13
2 changed files with 16 additions and 4 deletions
@@ -46,7 +46,7 @@ class LatestByKindAndAuthor<T : Event>(
fun canDelete(): Boolean = _latest.subscriptionCount.value == 0
suspend fun init() {
fun restart() {
val latestNote =
if ((kind in 10000..19999) || (kind in 30000..39999)) {
LocalCache.addressables
@@ -70,6 +70,12 @@ class LatestByKindAndAuthor<T : Event>(
)?.event as? T
}
_latest.tryEmit(latestNote)
if (_latest.value != latestNote) {
_latest.tryEmit(latestNote)
}
}
suspend fun init() {
restart()
}
}
@@ -45,7 +45,7 @@ class LatestByKindWithETag<T : Event>(
fun canDelete(): Boolean = _latest.subscriptionCount.value == 0
suspend fun init() {
fun restart() {
val latestNote =
LocalCache.notes
.maxOrNullOf(
@@ -57,6 +57,12 @@ class LatestByKindWithETag<T : Event>(
comparator = CreatedAtComparator,
)?.event as? T
_latest.tryEmit(latestNote)
if (_latest.value != latestNote) {
_latest.tryEmit(latestNote)
}
}
suspend fun init() {
restart()
}
}