diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt index 6ff2b403d..04eea40ce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt @@ -23,31 +23,24 @@ package com.vitorpamplona.amethyst.ui.dal import android.util.Log import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet -import kotlinx.coroutines.launch -import kotlin.coroutines.cancellation.CancellationException +import kotlinx.coroutines.runBlocking class FollowSetFeedFilter( val account: Account, ) : FeedFilter() { - override fun feedKey(): String = account.userProfile().pubkeyHex + override fun feedKey(): String = account.userProfile().pubkeyHex + "-followsets" - override fun feed(): List { - val followSetCache = mutableListOf() - account.scope.launch { - val userFollowSets = account.userProfile().followSetNotes - if (userFollowSets.isEmpty()) { - try { - account.getFollowSetNotes() - } catch (e: Exception) { - if (e is CancellationException) throw e - Log.e("HiddenAccountsFeedFilter", "Failed to load follow lists: ${e.message}") - null - } - } - userFollowSets.map { account.mapNoteToFollowSet(it) }.forEach { - followSetCache.add(it) + override fun feed(): List = + runBlocking(account.scope.coroutineContext) { + try { + val fetchedSets = account.getFollowSetNotes() + val followSets = fetchedSets.map { account.mapNoteToFollowSet(it) } + println("Updated follow set size for feed filter: ${followSets.size}") + followSets + } catch (e: Exception) { + // if (e is CancellationException) throw e + Log.e(this@FollowSetFeedFilter.javaClass.simpleName, "Failed to load follow lists: ${e.message}") + throw e } } - return followSetCache.toList() - } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSet.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSet.kt index b1c004bb9..16fa992f3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSet.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSet.kt @@ -24,6 +24,7 @@ import androidx.compose.runtime.Stable import com.vitorpamplona.quartz.nip01Core.core.value import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip51Lists.peopleList.PeopleListEvent +import kotlinx.coroutines.runBlocking @Stable data class FollowSet( @@ -34,7 +35,7 @@ data class FollowSet( val profileList: Set, ) : NostrList(listVisibility = visibility, content = profileList) { companion object { - suspend fun mapEventToSet( + fun mapEventToSet( event: PeopleListEvent, signer: NostrSigner, ): FollowSet { @@ -44,8 +45,7 @@ data class FollowSet( val listDescription = event.description() ?: "" val publicFollows = event.publicPeople().map { it.toTagArray() }.map { it.value() } val privateFollows = - event - .privatePeople(signer) + runBlocking { event.privatePeople(signer) } ?.map { it.toTagArray() } ?.map { it.value() } ?: emptyList() return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/FollowSetsActionMenu.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/FollowSetsActionMenu.kt index fe4669b94..43234dd0d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/FollowSetsActionMenu.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/FollowSetsActionMenu.kt @@ -49,9 +49,6 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -67,23 +64,21 @@ import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer import com.vitorpamplona.amethyst.ui.theme.ZeroPadding -import kotlinx.coroutines.launch import java.util.UUID @Composable fun FollowSetsActionMenu( + isMenuOpen: Boolean, + setMenuOpenState: () -> Unit, userHex: String, followLists: List, modifier: Modifier = Modifier, addUser: (followListItemIndex: Int, list: FollowSet) -> Unit, removeUser: (followListItemIndex: Int) -> Unit, ) { - val (isMenuOpen, setMenuValue) = remember { mutableStateOf(false) } - val uiScope = rememberCoroutineScope() - Column { TextButton( - onClick = { setMenuValue(true) }, + onClick = setMenuOpenState, shape = ButtonBorder.copy(topStart = CornerSize(0f), bottomStart = CornerSize(0f)), colors = ButtonDefaults @@ -118,11 +113,7 @@ fun FollowSetsActionMenu( DropdownMenu( expanded = isMenuOpen, - onDismissRequest = { - uiScope.launch { - setMenuValue(false) - } - }, + onDismissRequest = setMenuOpenState, modifier = Modifier.fillMaxWidth(), properties = PopupProperties(usePlatformDefaultWidth = true), ) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt index a8fc7f3ab..4bbee6bdd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/ProfileActions.kt @@ -25,13 +25,17 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.toMutableStateList import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.observeAccountIsHiddenUser import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.zaps.ShowUserButton +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch @Composable fun ProfileActions( @@ -41,6 +45,8 @@ fun ProfileActions( ) { val tempFollowLists = remember { generateFollowLists().toMutableStateList() } val actualFollowLists by accountViewModel.followSetsFlow.collectAsState() + val (isMenuOpen, setMenuValue) = remember { mutableStateOf(false) } + val uiScope = rememberCoroutineScope() val isMe by remember(accountViewModel) { derivedStateOf { accountViewModel.userProfile() == baseUser } } @@ -57,6 +63,13 @@ fun ProfileActions( } FollowSetsActionMenu( + isMenuOpen = isMenuOpen, + setMenuOpenState = { + uiScope.launch { + delay(100) + setMenuValue(!isMenuOpen) + } + }, userHex = baseUser.pubkeyHex, followLists = actualFollowLists, addUser = { index, list ->