First hack for bolting follow sets onto follows, for determining if a user follows another.

This commit is contained in:
KotlinGeekDev
2025-09-25 18:24:31 +01:00
parent 6ac2a7150f
commit ba0fc67a94
2 changed files with 25 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.model package com.vitorpamplona.amethyst.model
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import androidx.compose.ui.util.fastAny
import com.vitorpamplona.amethyst.BuildConfig import com.vitorpamplona.amethyst.BuildConfig
import com.vitorpamplona.amethyst.LocalPreferences import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
@@ -119,6 +120,7 @@ import com.vitorpamplona.quartz.experimental.profileGallery.mimeType
import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent
import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.core.value
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.hints.AddressHintProvider import com.vitorpamplona.quartz.nip01Core.hints.AddressHintProvider
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
@@ -215,6 +217,7 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.math.BigDecimal import java.math.BigDecimal
import java.util.Locale import java.util.Locale
@@ -838,6 +841,23 @@ class Account(
return@withContext followSetNotes return@withContext followSetNotes
} }
fun isUserInFollowSets(user: User): Boolean =
runBlocking(scope.coroutineContext) {
LocalCache.getFollowSetNotesFor(userProfile()).fastAny { it ->
val listEvent = it.event as PeopleListEvent
val isInPublicSets =
listEvent
.publicPeople()
.fastAny { it.toTagArray().value() == user.pubkeyHex }
val isInPrivateSets =
listEvent
.privatePeople(signer)
?.fastAny { it.toTagArray().value() == user.pubkeyHex } ?: false
isInPublicSets || isInPrivateSets
}
}
fun mapNoteToFollowSet(note: Note): FollowSet = fun mapNoteToFollowSet(note: Note): FollowSet =
FollowSet FollowSet
.mapEventToSet( .mapEventToSet(

View File

@@ -420,12 +420,15 @@ fun observeUserIsFollowing(
.follows.stateFlow .follows.stateFlow
.sample(1000) .sample(1000)
.mapLatest { userState -> .mapLatest { userState ->
userState.user.isFollowing(user2) userState.user.isFollowing(user2) ||
accountViewModel.account.isUserInFollowSets(user2)
}.distinctUntilChanged() }.distinctUntilChanged()
.flowOn(Dispatchers.Default) .flowOn(Dispatchers.Default)
} }
return flow.collectAsStateWithLifecycle(user1.isFollowing(user2)) return flow.collectAsStateWithLifecycle(
user1.isFollowing(user2) || accountViewModel.account.isUserInFollowSets(user2),
)
} }
@SuppressLint("StateFlowValueCalledInComposition") @SuppressLint("StateFlowValueCalledInComposition")