avoids using broadcasting relays to build filters to download home data

This commit is contained in:
Vitor Pamplona
2025-08-13 19:11:54 -04:00
parent 4c0f223673
commit f5881d4248
4 changed files with 58 additions and 4 deletions
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.model.nip01UserMetadata
import com.vitorpamplona.amethyst.model.edits.PrivateStorageRelayListState
import com.vitorpamplona.amethyst.model.localRelays.LocalRelayListState
import com.vitorpamplona.amethyst.model.nip65RelayList.Nip65RelayListState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.stateIn
class AccountHomeRelayState(
nip65: Nip65RelayListState,
privateStorage: PrivateStorageRelayListState,
local: LocalRelayListState,
scope: CoroutineScope,
) {
val flow =
combine(
nip65.outboxFlow,
privateStorage.flow,
local.flow,
) { nip65Outbox, privateOutBox, localRelays ->
nip65Outbox + privateOutBox + localRelays
}.flowOn(Dispatchers.Default)
.stateIn(
scope,
SharingStarted.Eagerly,
nip65.outboxFlow.value +
privateStorage.flow.value +
local.flow.value,
)
}
@@ -39,7 +39,7 @@ class AccountMetadataEoseManager(
) : PerUserEoseManager<AccountQueryState>(client, allKeys) {
override fun user(key: AccountQueryState) = key.account.userProfile()
fun relayFlow(query: AccountQueryState) = query.account.outboxRelays.flow
fun relayFlow(query: AccountQueryState) = query.account.homeRelays.flow
override fun updateFilter(
key: AccountQueryState,
@@ -37,7 +37,7 @@ fun filterNip04DMs(
): List<RelayBasedFilter>? {
if (group == null || group.isEmpty() || account == null) return null
val userOutboxRelays = account.outboxRelays.flow.value
val userOutboxRelays = account.homeRelays.flow.value
val userInboxRelays = account.dmRelays.flow.value
val groupOutboxRelays = mutableSetOf<NormalizedRelayUrl>()
@@ -40,7 +40,7 @@ class DMsFromUserFilterSubAssembler(
key: ChatroomListState,
since: SincePerRelayMap?,
): List<RelayBasedFilter>? =
key.account.outboxRelays.flow.value.map {
key.account.homeRelays.flow.value.map {
filterNip04DMsFromMe(key.account.userProfile(), it, since?.get(it)?.time)
} +
key.account.dmRelays.flow.value.map {
@@ -58,7 +58,7 @@ class DMsFromUserFilterSubAssembler(
userJobMap[user] =
listOf(
key.account.scope.launch(Dispatchers.Default) {
key.account.outboxRelays.flow.collectLatest {
key.account.homeRelays.flow.collectLatest {
invalidateFilters()
}
},