Fixes TopNav people lists not loading
This commit is contained in:
@@ -152,6 +152,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combineTransform
|
import kotlinx.coroutines.flow.combineTransform
|
||||||
|
import kotlinx.coroutines.flow.emitAll
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.transformLatest
|
import kotlinx.coroutines.flow.transformLatest
|
||||||
@@ -699,8 +701,33 @@ class FollowListViewModel(
|
|||||||
)
|
)
|
||||||
val defaultLists = persistentListOf(kind3Follow, globalFollow, muteListFollow)
|
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)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
val livePeopleListsFlow: Flow<List<CodeName>> =
|
val livePeopleListsFlowObservable: Flow<List<CodeName>> =
|
||||||
LocalCache.live.newEventBundles.transformLatest { newNotes ->
|
LocalCache.live.newEventBundles.transformLatest { newNotes ->
|
||||||
val hasNewList =
|
val hasNewList =
|
||||||
newNotes.any {
|
newNotes.any {
|
||||||
@@ -728,30 +755,13 @@ class FollowListViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasNewList) {
|
if (hasNewList) {
|
||||||
val newFollowLists =
|
emit(getPeopleLists())
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
val liveKind3FollowsFlow: Flow<List<CodeName>> =
|
val liveKind3FollowsFlow: Flow<List<CodeName>> =
|
||||||
account.userProfile().flow().follows.stateFlow.transformLatest {
|
account.userProfile().flow().follows.stateFlow.transformLatest {
|
||||||
|
|
||||||
val communities =
|
val communities =
|
||||||
it.user.cachedFollowingCommunitiesSet().mapNotNull {
|
it.user.cachedFollowingCommunitiesSet().mapNotNull {
|
||||||
LocalCache.checkGetOrCreateAddressableNote(it)?.let { communityNote ->
|
LocalCache.checkGetOrCreateAddressableNote(it)?.let { communityNote ->
|
||||||
|
|||||||
Reference in New Issue
Block a user