Includes Trusted Relays in all my relays

This commit is contained in:
Vitor Pamplona
2025-07-08 17:25:52 -04:00
parent e89a04eb56
commit 8c4ec1dc7d
2 changed files with 28 additions and 23 deletions

View File

@@ -277,7 +277,7 @@ class Account(
// Follows Relays // Follows Relays
val followOutboxes = FollowListOutboxRelays(kind3FollowList, blockedRelayList, cache, scope) val followOutboxes = FollowListOutboxRelays(kind3FollowList, blockedRelayList, cache, scope)
val followPlusAllMine = MergedFollowPlusMineRelayListsState(followOutboxes, nip65RelayList, privateStorageRelayList, localRelayList, scope) val followPlusAllMine = MergedFollowPlusMineRelayListsState(followOutboxes, nip65RelayList, privateStorageRelayList, trustedRelayList, localRelayList, scope)
// keeps a cache of the outbox relays for each author // keeps a cache of the outbox relays for each author
val followsPerRelay = FollowsPerOutboxRelay(kind3FollowList, blockedRelayList, cache, scope).flow val followsPerRelay = FollowsPerOutboxRelay(kind3FollowList, blockedRelayList, cache, scope).flow

View File

@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.model.serverList
import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListState import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListState
import com.vitorpamplona.amethyst.model.localRelays.LocalRelayListState import com.vitorpamplona.amethyst.model.localRelays.LocalRelayListState
import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListOutboxRelays import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListOutboxRelays
import com.vitorpamplona.amethyst.model.nip51Lists.TrustedRelayListState
import com.vitorpamplona.amethyst.model.nip65RelayList.Nip65RelayListState import com.vitorpamplona.amethyst.model.nip65RelayList.Nip65RelayListState
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -39,32 +40,33 @@ class MergedFollowPlusMineRelayListsState(
val nip65RelayList: Nip65RelayListState, val nip65RelayList: Nip65RelayListState,
val privateOutboxRelayList: PrivateStorageRelayListState, val privateOutboxRelayList: PrivateStorageRelayListState,
val localRelayList: LocalRelayListState, val localRelayList: LocalRelayListState,
val trustedRelayList: TrustedRelayListState,
val scope: CoroutineScope, val scope: CoroutineScope,
) { ) {
fun mergeLists( fun mergeLists(lists: Array<Set<NormalizedRelayUrl>>): Set<NormalizedRelayUrl> = lists.reduce { acc, set -> acc + set }
kind3: Set<NormalizedRelayUrl>,
outbox: Set<NormalizedRelayUrl>,
inbox: Set<NormalizedRelayUrl>,
private: Set<NormalizedRelayUrl>,
local: Set<NormalizedRelayUrl>,
): Set<NormalizedRelayUrl> = kind3 + outbox + inbox + private + local
val flow: StateFlow<Set<NormalizedRelayUrl>> = val flow: StateFlow<Set<NormalizedRelayUrl>> =
combine( combine(
followsOutboxRelayList.flow, listOf(
nip65RelayList.outboxFlow, followsOutboxRelayList.flow,
nip65RelayList.inboxFlow, nip65RelayList.outboxFlow,
privateOutboxRelayList.flow, nip65RelayList.inboxFlow,
localRelayList.flow, privateOutboxRelayList.flow,
localRelayList.flow,
trustedRelayList.flow,
),
::mergeLists, ::mergeLists,
).onStart { ).onStart {
emit( emit(
mergeLists( mergeLists(
followsOutboxRelayList.flow.value, arrayOf(
nip65RelayList.outboxFlow.value, followsOutboxRelayList.flow.value,
nip65RelayList.inboxFlow.value, nip65RelayList.outboxFlow.value,
privateOutboxRelayList.flow.value, nip65RelayList.inboxFlow.value,
localRelayList.flow.value, privateOutboxRelayList.flow.value,
localRelayList.flow.value,
trustedRelayList.flow.value,
),
), ),
) )
}.flowOn(Dispatchers.Default) }.flowOn(Dispatchers.Default)
@@ -72,11 +74,14 @@ class MergedFollowPlusMineRelayListsState(
scope, scope,
SharingStarted.Eagerly, SharingStarted.Eagerly,
mergeLists( mergeLists(
followsOutboxRelayList.flow.value, arrayOf(
nip65RelayList.outboxFlow.value, followsOutboxRelayList.flow.value,
nip65RelayList.inboxFlow.value, nip65RelayList.outboxFlow.value,
privateOutboxRelayList.flow.value, nip65RelayList.inboxFlow.value,
localRelayList.flow.value, privateOutboxRelayList.flow.value,
localRelayList.flow.value,
trustedRelayList.flow.value,
),
), ),
) )
} }