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 8e0b94646a
2 changed files with 31 additions and 24 deletions
@@ -61,7 +61,6 @@ import com.vitorpamplona.amethyst.model.serverList.MergedServerListState
import com.vitorpamplona.amethyst.model.serverList.TrustedRelayListsState
import com.vitorpamplona.amethyst.model.topNavFeeds.FeedTopNavFilterState
import com.vitorpamplona.amethyst.model.topNavFeeds.IFeedTopNavFilter
import com.vitorpamplona.amethyst.model.topNavFeeds.MergedTopFeedAuthorListsState
import com.vitorpamplona.amethyst.model.topNavFeeds.OutboxLoaderState
import com.vitorpamplona.amethyst.model.torState.TorRelayState
import com.vitorpamplona.amethyst.service.location.LocationState
@@ -277,7 +276,7 @@ class Account(
// Follows Relays
val followOutboxes = FollowListOutboxRelays(kind3FollowList, blockedRelayList, cache, scope)
val followPlusAllMine = MergedFollowPlusMineRelayListsState(followOutboxes, nip65RelayList, privateStorageRelayList, localRelayList, scope)
val followPlusAllMine = MergedFollowPlusMineRelayListsState(followOutboxes, nip65RelayList, privateStorageRelayList, localRelayList, trustedRelayList, scope)
// keeps a cache of the outbox relays for each author
val followsPerRelay = FollowsPerOutboxRelay(kind3FollowList, blockedRelayList, cache, scope).flow
@@ -338,6 +337,7 @@ class Account(
val liveNotificationFollowListsPerRelay = OutboxLoaderState(liveNotificationFollowLists, cache, scope).flow
/*
val mergedTopFeedAuthorLists =
MergedTopFeedAuthorListsState(
liveHomeFollowListsPerRelay,
@@ -347,6 +347,8 @@ class Account(
scope,
).flow
*/
val torRelayState = TorRelayState(trustedRelays, dmRelayList, settings, scope)
fun decryptPeopleList(
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.model.serverList
import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListState
import com.vitorpamplona.amethyst.model.localRelays.LocalRelayListState
import com.vitorpamplona.amethyst.model.nip02FollowLists.FollowListOutboxRelays
import com.vitorpamplona.amethyst.model.nip51Lists.TrustedRelayListState
import com.vitorpamplona.amethyst.model.nip65RelayList.Nip65RelayListState
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import kotlinx.coroutines.CoroutineScope
@@ -39,32 +40,33 @@ class MergedFollowPlusMineRelayListsState(
val nip65RelayList: Nip65RelayListState,
val privateOutboxRelayList: PrivateStorageRelayListState,
val localRelayList: LocalRelayListState,
val trustedRelayList: TrustedRelayListState,
val scope: CoroutineScope,
) {
fun mergeLists(
kind3: Set<NormalizedRelayUrl>,
outbox: Set<NormalizedRelayUrl>,
inbox: Set<NormalizedRelayUrl>,
private: Set<NormalizedRelayUrl>,
local: Set<NormalizedRelayUrl>,
): Set<NormalizedRelayUrl> = kind3 + outbox + inbox + private + local
fun mergeLists(lists: Array<Set<NormalizedRelayUrl>>): Set<NormalizedRelayUrl> = lists.reduce { acc, set -> acc + set }
val flow: StateFlow<Set<NormalizedRelayUrl>> =
combine(
followsOutboxRelayList.flow,
nip65RelayList.outboxFlow,
nip65RelayList.inboxFlow,
privateOutboxRelayList.flow,
localRelayList.flow,
listOf(
followsOutboxRelayList.flow,
nip65RelayList.outboxFlow,
nip65RelayList.inboxFlow,
privateOutboxRelayList.flow,
localRelayList.flow,
trustedRelayList.flow,
),
::mergeLists,
).onStart {
emit(
mergeLists(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
arrayOf(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
trustedRelayList.flow.value,
),
),
)
}.flowOn(Dispatchers.Default)
@@ -72,11 +74,14 @@ class MergedFollowPlusMineRelayListsState(
scope,
SharingStarted.Eagerly,
mergeLists(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
arrayOf(
followsOutboxRelayList.flow.value,
nip65RelayList.outboxFlow.value,
nip65RelayList.inboxFlow.value,
privateOutboxRelayList.flow.value,
localRelayList.flow.value,
trustedRelayList.flow.value,
),
),
)
}