Use Set rather than List, to avoid duplication. Introduce follow sets flow, and use it in FollowSetsActionMenu.

This commit is contained in:
KotlinGeekDev
2025-03-22 21:02:10 +01:00
parent 1d90e37f71
commit 2ae9d272f4
3 changed files with 22 additions and 2 deletions
@@ -67,7 +67,7 @@ class User(
var latestMetadataRelay: String? = null
var latestContactList: ContactListEvent? = null
var latestBookmarkList: BookmarkListEvent? = null
var followSets: List<AddressableNote> = listOf()
var followSets: Set<AddressableNote> = setOf()
private set
var reports = mapOf<User, Set<Note>>()
@@ -166,6 +166,24 @@ class AccountViewModel(
emptySet(),
)
val followSetsFlow =
account
.userProfile()
.flow()
.followSets.stateFlow
.map { followSetsState ->
checkNotInMainThread()
account.getFollowSetNotes()
followSetsState.user.followSets.map {
account.mapNoteToFollowSet(it)
}
}.flowOn(Dispatchers.Default)
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(10000, 10000),
emptyList(),
)
val dmRelays: StateFlow<ChatMessageRelayListEvent?> = observeByAuthor(ChatMessageRelayListEvent.KIND, account.signer.pubKey)
val searchRelays: StateFlow<SearchRelayListEvent?> = observeByAuthor(SearchRelayListEvent.KIND, account.signer.pubKey)
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.header
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
@@ -39,6 +40,7 @@ fun ProfileActions(
nav: INav,
) {
val tempFollowLists = remember { generateFollowLists().toMutableStateList() }
val actualFollowLists by accountViewModel.followSetsFlow.collectAsState()
val isMe by
remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } }
@@ -56,7 +58,7 @@ fun ProfileActions(
FollowSetsActionMenu(
userHex = baseUser.pubkeyHex,
followLists = tempFollowLists,
followLists = actualFollowLists,
addUser = { index, list ->
Log.d("Amethyst", "ProfileActions: Updating list ...")
val newList = tempFollowLists[index].profileList + baseUser.pubkeyHex