diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppTopBar.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppTopBar.kt index 353bdb82e..fa8bb7b82 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppTopBar.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppTopBar.kt @@ -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> by lazy { + flow { + checkNotInMainThread() + + emit(getPeopleLists()) + emitAll(livePeopleListsFlowObservable) + } + } + + fun getPeopleLists(): List = + 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> = + val livePeopleListsFlowObservable: Flow> = 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> = account.userProfile().flow().follows.stateFlow.transformLatest { - val communities = it.user.cachedFollowingCommunitiesSet().mapNotNull { LocalCache.checkGetOrCreateAddressableNote(it)?.let { communityNote ->