Growing the number of possibilities to download profile information from

This commit is contained in:
Vitor Pamplona
2025-08-14 19:47:20 -04:00
parent 25dec49e97
commit d8461c2a74
7 changed files with 60 additions and 24 deletions

View File

@@ -214,6 +214,7 @@ import kotlinx.coroutines.launch
import java.math.BigDecimal import java.math.BigDecimal
import java.util.Locale import java.util.Locale
import kotlin.collections.forEach import kotlin.collections.forEach
import kotlin.collections.ifEmpty
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
@Stable @Stable
@@ -536,7 +537,7 @@ class Account(
val zapRequest = val zapRequest =
LnZapRequestEvent.create( LnZapRequestEvent.create(
userHex = user.pubkeyHex, userHex = user.pubkeyHex,
relays = nip65RelayList.inboxFlow.value + user.inboxRelays(), relays = nip65RelayList.inboxFlow.value + (user.inboxRelays() ?: emptyList()),
signer = signer, signer = signer,
message = message, message = message,
zapType = zapType, zapType = zapType,
@@ -657,7 +658,8 @@ class Account(
if (replyToAuthor == userProfile()) { if (replyToAuthor == userProfile()) {
outboxRelays.flow.value outboxRelays.flow.value
} else { } else {
replyToAuthor.outboxRelays().ifEmpty { null }?.toSet() replyToAuthor.inboxRelays()?.ifEmpty { null }?.toSet()
?: replyToAuthor.relaysBeingUsed.keys.ifEmpty { null }
?: cache.relayHints ?: cache.relayHints
.hintsForKey(replyToAuthor.pubkeyHex) .hintsForKey(replyToAuthor.pubkeyHex)
.ifEmpty { null } .ifEmpty { null }
@@ -683,7 +685,7 @@ class Account(
if (user == userProfile()) { if (user == userProfile()) {
notificationRelays.flow.value notificationRelays.flow.value
} else { } else {
user.inboxRelays().ifEmpty { null }?.toSet() user.inboxRelays()?.ifEmpty { null }?.toSet()
?: (cache.relayHints.hintsForKey(user.pubkeyHex).toSet() + user.relaysBeingUsed.keys) ?: (cache.relayHints.hintsForKey(user.pubkeyHex).toSet() + user.relaysBeingUsed.keys)
} }
@@ -736,10 +738,12 @@ class Account(
if (author == userProfile()) { if (author == userProfile()) {
relayList.addAll(outboxRelays.flow.value) relayList.addAll(outboxRelays.flow.value)
} else { } else {
relayList.addAll( val relays =
author.outboxRelays().ifEmpty { null } author.outboxRelays()?.ifEmpty { null }
?: cache.relayHints.hintsForKey(author.pubkeyHex), ?: author.relaysBeingUsed.keys.ifEmpty { null }
) ?: cache.relayHints.hintsForKey(author.pubkeyHex)
relayList.addAll(relays)
} }
} else { } else {
relayList.addAll(cache.relayHints.hintsForKey(event.pubKey)) relayList.addAll(cache.relayHints.hintsForKey(event.pubKey))
@@ -1548,11 +1552,8 @@ class Account(
val request = NIP90ContentDiscoveryRequestEvent.create(dvmPublicKey.pubkeyHex, signer.pubKey, relays, signer) val request = NIP90ContentDiscoveryRequestEvent.create(dvmPublicKey.pubkeyHex, signer.pubKey, relays, signer)
val relayList = val relayList =
dvmPublicKey dvmPublicKey.inboxRelays()?.toSet()?.ifEmpty { null }
.inboxRelays() ?: (dvmPublicKey.relaysBeingUsed.keys + cache.relayHints.hintsForKey(dvmPublicKey.pubkeyHex))
.ifEmpty {
cache.relayHints.hintsForKey(dvmPublicKey.pubkeyHex) + dvmPublicKey.relaysBeingUsed.keys
}.toSet()
cache.justConsumeMyOwnEvent(request) cache.justConsumeMyOwnEvent(request)
onReady(request) onReady(request)

View File

@@ -78,11 +78,11 @@ class User(
fun toNProfile() = NProfile.create(pubkeyHex, relayHints()) fun toNProfile() = NProfile.create(pubkeyHex, relayHints())
fun outboxRelays() = authorRelayList()?.writeRelaysNorm() ?: listOfNotNull(latestMetadataRelay) fun outboxRelays() = authorRelayList()?.writeRelaysNorm()
fun relayHints() = authorRelayList()?.writeRelaysNorm()?.take(3) ?: listOfNotNull(latestMetadataRelay) fun relayHints() = authorRelayList()?.writeRelaysNorm()?.take(3) ?: listOfNotNull(latestMetadataRelay)
fun inboxRelays() = authorRelayList()?.readRelaysNorm() ?: listOfNotNull(latestMetadataRelay) fun inboxRelays() = authorRelayList()?.readRelaysNorm()
fun dmInboxRelays() = dmInboxRelayList()?.relays()?.ifEmpty { null } ?: inboxRelays() fun dmInboxRelays() = dmInboxRelayList()?.relays()?.ifEmpty { null } ?: inboxRelays()

View File

@@ -20,6 +20,7 @@
*/ */
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
@@ -31,8 +32,13 @@ val UserProfileFollowersKinds = listOf(ContactListEvent.KIND)
fun filterUserProfileFollowers( fun filterUserProfileFollowers(
user: User, user: User,
since: SincePerRelayMap?, since: SincePerRelayMap?,
): List<RelayBasedFilter> = ): List<RelayBasedFilter> {
user.inboxRelays().map { val relays =
user.inboxRelays()?.ifEmpty { null }
?: user.relaysBeingUsed.keys.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(user.pubkeyHex)
return relays.map {
RelayBasedFilter( RelayBasedFilter(
relay = it, relay = it,
filter = filter =
@@ -43,3 +49,4 @@ fun filterUserProfileFollowers(
), ),
) )
} }
}

View File

@@ -20,6 +20,7 @@
*/ */
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent import com.vitorpamplona.quartz.experimental.profileGallery.ProfileGalleryEntryEvent
@@ -40,8 +41,13 @@ val UserProfileMediaKinds =
fun filterUserProfileMedia( fun filterUserProfileMedia(
user: User, user: User,
since: SincePerRelayMap?, since: SincePerRelayMap?,
): List<RelayBasedFilter> = ): List<RelayBasedFilter> {
user.outboxRelays().map { relay -> val relays =
user.outboxRelays()?.ifEmpty { null }
?: user.relaysBeingUsed.keys.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(user.pubkeyHex)
return relays.map { relay ->
RelayBasedFilter( RelayBasedFilter(
relay = relay, relay = relay,
filter = filter =
@@ -53,3 +59,4 @@ fun filterUserProfileMedia(
), ),
) )
} }
}

View File

@@ -20,6 +20,7 @@
*/ */
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryPrologueEvent import com.vitorpamplona.quartz.experimental.interactiveStories.InteractiveStoryPrologueEvent
@@ -66,9 +67,13 @@ val UserProfilePostKinds2 =
fun filterUserProfilePosts( fun filterUserProfilePosts(
user: User, user: User,
since: SincePerRelayMap?, since: SincePerRelayMap?,
): List<RelayBasedFilter> = ): List<RelayBasedFilter> {
user val relays =
.outboxRelays() user.outboxRelays()?.ifEmpty { null }
?: user.relaysBeingUsed.keys.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(user.pubkeyHex)
return relays
.map { relay -> .map { relay ->
listOf( listOf(
RelayBasedFilter( RelayBasedFilter(
@@ -93,3 +98,4 @@ fun filterUserProfilePosts(
), ),
) )
}.flatten() }.flatten()
}

View File

@@ -20,19 +20,26 @@
*/ */
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent
import kotlin.collections.ifEmpty
val UserProfileZapReceiverKinds = listOf(LnZapEvent.KIND) val UserProfileZapReceiverKinds = listOf(LnZapEvent.KIND)
fun filterUserProfileZapsReceived( fun filterUserProfileZapsReceived(
user: User, user: User,
since: SincePerRelayMap?, since: SincePerRelayMap?,
): List<RelayBasedFilter> = ): List<RelayBasedFilter> {
user.inboxRelays().map { relay -> val relays =
user.inboxRelays()?.ifEmpty { null }
?: user.relaysBeingUsed.keys.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(user.pubkeyHex)
return relays.map { relay ->
RelayBasedFilter( RelayBasedFilter(
relay = relay, relay = relay,
filter = filter =
@@ -44,3 +51,4 @@ fun filterUserProfileZapsReceived(
), ),
) )
} }
}

View File

@@ -20,11 +20,13 @@
*/ */
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile.datasource
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.service.relayClient.eoseManagers.SingleSubEoseManager import com.vitorpamplona.amethyst.service.relayClient.eoseManagers.SingleSubEoseManager
import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap import com.vitorpamplona.amethyst.service.relays.SincePerRelayMap
import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient import com.vitorpamplona.quartz.nip01Core.relay.client.NostrClient
import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
import com.vitorpamplona.quartz.utils.mapOfSet import com.vitorpamplona.quartz.utils.mapOfSet
import kotlin.collections.ifEmpty
class UserProfileMetadataFilterSubAssembler( class UserProfileMetadataFilterSubAssembler(
client: NostrClient, client: NostrClient,
@@ -37,7 +39,12 @@ class UserProfileMetadataFilterSubAssembler(
val userPerRelay = val userPerRelay =
mapOfSet { mapOfSet {
keys.mapTo(mutableSetOf()) { key -> key.user }.forEach { user -> keys.mapTo(mutableSetOf()) { key -> key.user }.forEach { user ->
user.outboxRelays().forEach { relay -> val relays =
user.outboxRelays()?.ifEmpty { null }
?: user.relaysBeingUsed.keys.ifEmpty { null }
?: LocalCache.relayHints.hintsForKey(user.pubkeyHex)
relays.forEach { relay ->
add(relay, user.pubkeyHex) add(relay, user.pubkeyHex)
} }
} }