mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-26 17:52:29 +01:00
Renames the MinimumRelayList to RecommendationProcessor
This commit is contained in:
parent
c17e1f0e1f
commit
2b1e3cfc93
@ -108,7 +108,7 @@ import com.vitorpamplona.quartz.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.signers.NostrSignerExternal
|
||||
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
||||
import com.vitorpamplona.quartz.utils.DualCase
|
||||
import com.vitorpamplona.quartz.utils.MinimumRelayListProcessor
|
||||
import com.vitorpamplona.quartz.utils.RelayListRecommendationProcessor
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -121,7 +121,6 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.combineTransform
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.transformLatest
|
||||
@ -500,13 +499,13 @@ class Account(
|
||||
fun relaysFromPeopleListFlows(
|
||||
currentFollowList: LiveFollowLists,
|
||||
relayUrlsToIgnore: Set<String>,
|
||||
): Flow<List<MinimumRelayListProcessor.RelayRecommendation>> =
|
||||
): Flow<List<RelayListRecommendationProcessor.RelayRecommendation>> =
|
||||
combine(
|
||||
currentFollowList.users.map {
|
||||
getNIP65RelayListFlow(it)
|
||||
},
|
||||
) { followsNIP65RelayLists ->
|
||||
MinimumRelayListProcessor
|
||||
RelayListRecommendationProcessor
|
||||
.reliableRelaySetFor(
|
||||
followsNIP65RelayLists.mapNotNull {
|
||||
(it.note.event as? AdvertisedRelayListEvent)
|
||||
@ -517,7 +516,7 @@ class Account(
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
val liveHomeFollowRelayFlow: Flow<List<MinimumRelayListProcessor.RelayRecommendation>> by lazy {
|
||||
val liveHomeFollowRelayFlow: Flow<List<RelayListRecommendationProcessor.RelayRecommendation>> by lazy {
|
||||
combineTransform(liveHomeFollowListFlow, connectToRelaysFlow) { followList, existing ->
|
||||
if (followList != null) {
|
||||
emit(
|
||||
@ -540,7 +539,7 @@ class Account(
|
||||
}
|
||||
}
|
||||
|
||||
val liveHomeFollowRelays: StateFlow<List<MinimumRelayListProcessor.RelayRecommendation>> by lazy {
|
||||
val liveHomeFollowRelays: StateFlow<List<RelayListRecommendationProcessor.RelayRecommendation>> by lazy {
|
||||
liveHomeFollowRelayFlow.stateIn(scope, SharingStarted.Eagerly, emptyList())
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import com.vitorpamplona.ammolite.relays.FeedType
|
||||
import com.vitorpamplona.ammolite.relays.RelaySetupInfo
|
||||
import com.vitorpamplona.ammolite.relays.RelayStats
|
||||
import com.vitorpamplona.quartz.encoders.RelayUrlFormatter
|
||||
import com.vitorpamplona.quartz.utils.MinimumRelayListProcessor
|
||||
import com.vitorpamplona.quartz.utils.RelayListRecommendationProcessor
|
||||
import kotlinx.collections.immutable.toImmutableSet
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@ -140,7 +140,7 @@ class Kind3RelayListViewModel : ViewModel() {
|
||||
private fun refreshProposals() {
|
||||
_proposedRelays.update {
|
||||
val proposed =
|
||||
MinimumRelayListProcessor
|
||||
RelayListRecommendationProcessor
|
||||
.reliableRelaySetFor(
|
||||
account.liveKind3Follows.value.users.mapNotNull {
|
||||
account.getNIP65RelayList(it)
|
||||
|
@ -24,9 +24,9 @@ import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.encoders.RelayUrlFormatter
|
||||
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
||||
|
||||
class MinimumRelayListProcessor {
|
||||
class RelayListRecommendationProcessor {
|
||||
companion object {
|
||||
fun transpose(
|
||||
private fun transpose(
|
||||
userList: Map<HexKey, MutableSet<String>>,
|
||||
ignore: Set<String> = setOf(),
|
||||
): Map<String, MutableSet<HexKey>> {
|
||||
@ -52,7 +52,7 @@ class MinimumRelayListProcessor {
|
||||
* filter onion and local host from write relays
|
||||
* for each user pubkey, a list of valid relays.
|
||||
*/
|
||||
fun filterValidRelays(
|
||||
private fun filterValidRelays(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
hasOnionConnection: Boolean = false,
|
||||
): MutableMap<HexKey, MutableSet<String>> {
|
||||
@ -76,17 +76,7 @@ class MinimumRelayListProcessor {
|
||||
return validWriteRelayUrls
|
||||
}
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
hasOnionConnection: Boolean = false,
|
||||
): Set<RelayRecommendation> =
|
||||
reliableRelaySetFor(
|
||||
filterValidRelays(userList, hasOnionConnection),
|
||||
relayUrlsToIgnore,
|
||||
)
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
private fun reliableRelaySetFor(
|
||||
usersAndRelays: MutableMap<HexKey, MutableSet<String>>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
): Set<RelayRecommendation> {
|
||||
@ -154,6 +144,16 @@ class MinimumRelayListProcessor {
|
||||
|
||||
return returningSet
|
||||
}
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
relayUrlsToIgnore: Set<String> = emptySet(),
|
||||
hasOnionConnection: Boolean = false,
|
||||
): Set<RelayRecommendation> =
|
||||
reliableRelaySetFor(
|
||||
filterValidRelays(userList, hasOnionConnection),
|
||||
relayUrlsToIgnore,
|
||||
)
|
||||
}
|
||||
|
||||
class RelayRecommendation(
|
@ -24,7 +24,7 @@ import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class MinimumRelayListProcessorTest {
|
||||
class RelayListRecommendationProcessorTest {
|
||||
val userList =
|
||||
mutableMapOf(
|
||||
"User1" to mutableSetOf("wss://relay1.com", "wss://relay2.com", "wss://relay3.com"),
|
||||
@ -44,13 +44,13 @@ class MinimumRelayListProcessorTest {
|
||||
"wss://relay5.com" to listOf("User2"),
|
||||
"wss://relay6.com" to listOf("User2", "User3"),
|
||||
).toString(),
|
||||
MinimumRelayListProcessor.transpose(userList).toString(),
|
||||
RelayListRecommendationProcessor.transpose(userList).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProcessor() {
|
||||
val recommendations = MinimumRelayListProcessor.reliableRelaySetFor(userList).toList()
|
||||
val recommendations = RelayListRecommendationProcessor.reliableRelaySetFor(userList).toList()
|
||||
|
||||
val rec1 = recommendations[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user