Avoiding feed jitter when pressing the notification button twice.

This commit is contained in:
Vitor Pamplona
2024-04-04 10:03:28 -04:00
parent 621d1c7731
commit e1c134830e
3 changed files with 3 additions and 16 deletions
@@ -240,11 +240,7 @@ class Account(
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
private val liveHomeList: Flow<ListNameNotePair> by lazy { private val liveHomeList: Flow<ListNameNotePair> by lazy {
defaultHomeFollowList.flatMapLatest { listName -> defaultHomeFollowList.flatMapLatest { listName ->
println("AABBCC liveHomeList $listName changed")
loadPeopleListFlowFromListName(listName) loadPeopleListFlowFromListName(listName)
}.transformLatest {
println("AABBCC liveHomeList after FlattenMerge")
emit(it)
} }
} }
@@ -252,12 +248,8 @@ class Account(
fun loadPeopleListFlowFromListName(listName: String): Flow<ListNameNotePair> { fun loadPeopleListFlowFromListName(listName: String): Flow<ListNameNotePair> {
return if (listName != GLOBAL_FOLLOWS && listName != KIND3_FOLLOWS) { return if (listName != GLOBAL_FOLLOWS && listName != KIND3_FOLLOWS) {
val note = LocalCache.checkGetOrCreateAddressableNote(listName) val note = LocalCache.checkGetOrCreateAddressableNote(listName)
println("AABBCC loadPeopleListFlowFromListName $listName ${note?.idHex} ${note?.flow()?.metadata?.stateFlow?.subscriptionCount?.value}")
note?.flow()?.metadata?.stateFlow?.mapLatest { note?.flow()?.metadata?.stateFlow?.mapLatest {
println("AABBCC loadPeopleListFlowFromListName running")
val noteEvent = it.note.event as? GeneralListEvent val noteEvent = it.note.event as? GeneralListEvent
println("AABBCC loadPeopleListFlowFromListName emitting ${noteEvent?.id}")
ListNameNotePair(listName, noteEvent) ListNameNotePair(listName, noteEvent)
} ?: MutableStateFlow(ListNameNotePair(listName, null)) } ?: MutableStateFlow(ListNameNotePair(listName, null))
} else { } else {
@@ -271,19 +263,14 @@ class Account(
): Flow<LiveFollowLists?> { ): Flow<LiveFollowLists?> {
return combineTransform(kind3FollowsSource, peopleListFollowsSource) { kind3Follows, peopleListFollows -> return combineTransform(kind3FollowsSource, peopleListFollowsSource) { kind3Follows, peopleListFollows ->
if (peopleListFollows.listName == GLOBAL_FOLLOWS) { if (peopleListFollows.listName == GLOBAL_FOLLOWS) {
println("AABBCC combinePeopleListFlows ${peopleListFollows.listName} Global")
emit(null) emit(null)
} else if (peopleListFollows.listName == KIND3_FOLLOWS) { } else if (peopleListFollows.listName == KIND3_FOLLOWS) {
println("AABBCC combinePeopleListFlows ${peopleListFollows.listName} Kind 3")
emit(kind3Follows) emit(kind3Follows)
} else if (peopleListFollows.event == null) { } else if (peopleListFollows.event == null) {
println("AABBCC combinePeopleListFlows ${peopleListFollows.listName} Note is null")
emit(LiveFollowLists()) emit(LiveFollowLists())
} else { } else {
println("AABBCC combinePeopleListFlows ${peopleListFollows.listName} ${peopleListFollows.event.id}")
val result = waitToDecrypt(peopleListFollows.event) val result = waitToDecrypt(peopleListFollows.event)
if (result == null) { if (result == null) {
println("AABBCC combinePeopleListFlows ${peopleListFollows.listName} returning null")
emit(LiveFollowLists()) emit(LiveFollowLists())
} else { } else {
emit(result) emit(result)
@@ -367,9 +367,9 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel(), I
} }
} }
fun invalidateDataAndSendToTop() { fun invalidateDataAndSendToTop(ignoreIfDoing: Boolean) {
clear() clear()
bundler.invalidate(false) { bundler.invalidate(ignoreIfDoing) {
// adds the time to perform the refresh into this delay // adds the time to perform the refresh into this delay
// holding off new updates in case of heavy refresh routines. // holding off new updates in case of heavy refresh routines.
val (value, elapsed) = val (value, elapsed) =
@@ -276,7 +276,7 @@ fun MainScreen(
discoveryChatFeedViewModel.sendToTop() discoveryChatFeedViewModel.sendToTop()
} }
Route.Notification.base -> { Route.Notification.base -> {
notifFeedViewModel.invalidateDataAndSendToTop() notifFeedViewModel.invalidateDataAndSendToTop(true)
} }
} }