Fixes TopNav people lists not loading

This commit is contained in:
Vitor Pamplona 2024-07-17 17:24:06 -04:00
parent 0477f390c2
commit d30e613b17

View File

@ -152,6 +152,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combineTransform
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.transformLatest
@ -699,8 +701,33 @@ class FollowListViewModel(
)
val defaultLists = persistentListOf(kind3Follow, globalFollow, muteListFollow)
val livePeopleListsFlow: Flow<List<CodeName>> by lazy {
flow {
checkNotInMainThread()
emit(getPeopleLists())
emitAll(livePeopleListsFlowObservable)
}
}
fun getPeopleLists(): List<CodeName> =
LocalCache.addressables
.mapNotNull { _, addressableNote ->
val event = (addressableNote.event as? PeopleListEvent)
// Has to have an list
if (
event != null &&
event.pubKey == account.userProfile().pubkeyHex &&
(event.tags.size > 1 || event.content.length > 50)
) {
CodeName(event.address().toTag(), PeopleListName(addressableNote), CodeNameType.PEOPLE_LIST)
} else {
null
}
}.sortedBy { it.name.name() }
@OptIn(ExperimentalCoroutinesApi::class)
val livePeopleListsFlow: Flow<List<CodeName>> =
val livePeopleListsFlowObservable: Flow<List<CodeName>> =
LocalCache.live.newEventBundles.transformLatest { newNotes ->
val hasNewList =
newNotes.any {
@ -728,30 +755,13 @@ class FollowListViewModel(
}
if (hasNewList) {
val newFollowLists =
LocalCache.addressables
.mapNotNull { _, addressableNote ->
val event = (addressableNote.event as? PeopleListEvent)
// Has to have an list
if (
event != null &&
event.pubKey == account.userProfile().pubkeyHex &&
(event.tags.size > 1 || event.content.length > 50)
) {
CodeName(event.address().toTag(), PeopleListName(addressableNote), CodeNameType.PEOPLE_LIST)
} else {
null
}
}.sortedBy { it.name.name() }
emit(newFollowLists)
emit(getPeopleLists())
}
}
@OptIn(ExperimentalCoroutinesApi::class)
val liveKind3FollowsFlow: Flow<List<CodeName>> =
account.userProfile().flow().follows.stateFlow.transformLatest {
val communities =
it.user.cachedFollowingCommunitiesSet().mapNotNull {
LocalCache.checkGetOrCreateAddressableNote(it)?.let { communityNote ->