In case a user does not have an outbox list, defaults to all hints seen for that user.

This commit is contained in:
Vitor Pamplona
2025-08-22 12:42:40 -04:00
parent 3df7129f00
commit e0ffa6d4fb
5 changed files with 19 additions and 7 deletions

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.model.nip02FollowLists
import com.vitorpamplona.amethyst.model.AddressableNote
import com.vitorpamplona.amethyst.model.Constants
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.NoteState
import com.vitorpamplona.amethyst.model.nip51Lists.blockedRelays.BlockedRelayListState
@@ -45,6 +46,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.transformLatest
import kotlin.collections.ifEmpty
class FollowsPerOutboxRelay(
kind3Follows: FollowListState,
@@ -68,7 +70,11 @@ class FollowsPerOutboxRelay(
mapOfSet {
relayListNotes.forEach { noteState ->
noteState.note.author?.pubkeyHex?.let { authorHex ->
(noteState.note.event as? AdvertisedRelayListEvent)?.writeRelaysNorm()?.forEach { relay ->
val outboxRelayList =
getNIP65RelayList(authorHex)?.writeRelaysNorm()
?: LocalCache.relayHints.hintsForKey(authorHex).ifEmpty { null }
?: Constants.eventFinderRelays
outboxRelayList.forEach { relay ->
add(relay, authorHex)
}
}
@@ -85,7 +91,11 @@ class FollowsPerOutboxRelay(
emit(
mapOfSet {
kind3Follows.flow.value.authors.map { authorHex ->
getNIP65RelayList(authorHex)?.writeRelaysNorm()?.forEach { relay ->
val outboxRelayList =
getNIP65RelayList(authorHex)?.writeRelaysNorm()
?: LocalCache.relayHints.hintsForKey(authorHex).ifEmpty { null }
?: Constants.eventFinderRelays
outboxRelayList.forEach { relay ->
add(relay, authorHex)
}
}

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.model.topNavFeeds
import com.vitorpamplona.amethyst.model.AddressableNote
import com.vitorpamplona.amethyst.model.Constants
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.NoteState
import com.vitorpamplona.quartz.nip01Core.core.HexKey
@@ -50,8 +51,9 @@ class OutboxRelayLoader {
if (authorHex != null) {
val relays =
(outboxNote.note.event as? AdvertisedRelayListEvent)?.writeRelaysNorm()?.ifEmpty { null }
?: cache.relayHints.hintsForKey(authorHex)
(outboxNote.note.event as? AdvertisedRelayListEvent)?.writeRelaysNorm()
?: cache.relayHints.hintsForKey(authorHex).ifEmpty { null }
?: Constants.eventFinderRelays
relays.forEach {
add(it, authorHex)

View File

@@ -52,7 +52,7 @@ fun filterFindUserMetadataForKey(
mapOfSet {
authors.forEach { key ->
val relays =
key.authorRelayList()?.writeRelaysNorm()?.ifEmpty { null }
key.authorRelayList()?.writeRelaysNorm()
?: LocalCache.relayHints.hintsForKey(key.pubkeyHex).ifEmpty { null }
?: (key.relaysBeingUsed.keys + defaultRelays).toList()

View File

@@ -50,7 +50,7 @@ fun filterUserMetadataForKey(
val authorHomeRelayEventAddress = AdvertisedRelayListEvent.createAddressTag(it)
val authorHomeRelayEvent = (LocalCache.getAddressableNoteIfExists(authorHomeRelayEventAddress)?.event as? AdvertisedRelayListEvent)
authorHomeRelayEvent?.writeRelaysNorm()?.ifEmpty { null }
authorHomeRelayEvent?.writeRelaysNorm()
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
?: listOfNotNull(LocalCache.getUserIfExists(it)?.latestMetadataRelay)
}.flatten()

View File

@@ -48,7 +48,7 @@ fun filterNip04DMs(
val authorHomeRelayEvent = (LocalCache.getAddressableNoteIfExists(authorHomeRelayEventAddress)?.event as? AdvertisedRelayListEvent)
val outbox =
authorHomeRelayEvent?.writeRelaysNorm()?.ifEmpty { null }
authorHomeRelayEvent?.writeRelaysNorm()
?: LocalCache.relayHints.hintsForKey(it).ifEmpty { null }
?: listOfNotNull(LocalCache.getUserIfExists(it)?.latestMetadataRelay)