From d7d8554626a2fa3522be24500ce0774322d2b421 Mon Sep 17 00:00:00 2001 From: KotlinGeekDev Date: Mon, 31 Mar 2025 21:15:06 +0100 Subject: [PATCH] Make naming clearer. Some refactoring. Add a function to retrieve the not corresponding to a follow set. --- .../com/vitorpamplona/amethyst/model/Account.kt | 4 ++-- .../vitorpamplona/amethyst/model/LocalCache.kt | 2 +- .../com/vitorpamplona/amethyst/model/User.kt | 6 +++--- .../amethyst/ui/screen/FeedViewModel.kt | 1 + .../ui/screen/loggedIn/AccountViewModel.kt | 2 +- .../loggedIn/lists/FollowSetFeedViewModel.kt | 16 +++++++++++++--- .../profile/header/FollowSetsActionMenu.kt | 6 ++++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 96e6975b9..a77c7f864 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -3067,8 +3067,8 @@ class Account( suspend fun getFollowSetNotes() = withContext(Dispatchers.Default) { - val followSetNotes = LocalCache.getFollowSetsFor(userProfile()) - userProfile().updateFollowSets(followSetNotes) + val followSetNotes = LocalCache.getFollowSetNotesFor(userProfile()) + userProfile().updateFollowSetNotes(followSetNotes) // userProfile().followSets = followSetNotes println("Number of follow sets: ${followSetNotes.size}") } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index d2c852d9d..a32c70589 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -1961,7 +1961,7 @@ object LocalCache { } } - fun getFollowSetsFor(user: User): List { + fun getFollowSetNotesFor(user: User): List { checkNotInMainThread() return addressables diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt index 4dfb4ec30..eeef874ce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt @@ -67,7 +67,7 @@ class User( var latestMetadataRelay: String? = null var latestContactList: ContactListEvent? = null var latestBookmarkList: BookmarkListEvent? = null - var followSets: Set = setOf() + var followSetNotes: Set = setOf() private set var reports = mapOf>() @@ -168,8 +168,8 @@ class User( flowSet?.relays?.invalidateData() } - fun updateFollowSets(sets: List) { - followSets = followSets + sets + fun updateFollowSetNotes(setNotes: List) { + followSetNotes = followSetNotes + setNotes } fun addReport(note: Note) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index 07289fa55..869d4ba11 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -162,6 +162,7 @@ class NostrBookmarkPrivateFeedViewModel( } } +@Stable class NostrUserFollowSetFeedViewModel( val account: Account, ) : FollowSetFeedViewModel(FollowSetFeedFilter(account)) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index e2e5212a6..767192e35 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -175,7 +175,7 @@ class AccountViewModel( .map { followSetsState -> checkNotInMainThread() account.getFollowSetNotes() - followSetsState.user.followSets.map { + followSetsState.user.followSetNotes.map { account.mapNoteToFollowSet(it) } }.flowOn(Dispatchers.Default) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt index bc2ce78de..ebf33560f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt @@ -22,16 +22,18 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists import android.util.Log import androidx.compose.runtime.MutableState -import androidx.compose.runtime.Stable import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.vitorpamplona.amethyst.model.Account +import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.ui.dal.FeedFilter import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.equalImmutableLists import com.vitorpamplona.ammolite.relays.BundledUpdate +import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers @@ -41,8 +43,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch -@Stable -open class FollowSetFeedViewModel( +abstract class FollowSetFeedViewModel( val dataSource: FeedFilter, ) : ViewModel(), InvalidatableContent { @@ -55,6 +56,15 @@ open class FollowSetFeedViewModel( } } + fun getFollowSetAddressable( + addressValue: String, + account: Account, + ): AddressableNote? { + checkNotInMainThread() + val potentialNote = LocalCache.getAddressableNoteIfExists(Address.parse(addressValue)!!) + return potentialNote + } + override val isRefreshing: MutableState = mutableStateOf(false) private fun refreshSuspended() { 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 150fd8755..6366643d6 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 @@ -68,6 +68,7 @@ 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( @@ -174,14 +175,15 @@ private fun DropDownMenuHeader( fun generateFollowLists(): List = List(10) { index: Int -> FollowSet( + identifierTag = UUID.randomUUID().toString(), + title = "List No $index", + description = null, visibility = when { index % 2 == 0 -> ListVisibility.Private index in listOf(3, 7, 9) -> ListVisibility.Mixed else -> ListVisibility.Public }, - title = "List No $index", - description = null, profileList = emptySet(), ) }