Skip to content

Commit

Permalink
Bump minimum relays up by 1. Try to make sure we find the author meta…
Browse files Browse the repository at this point in the history
…data if we dont succeed with the tried relays.
  • Loading branch information
KotlinGeekDev committed Jan 3, 2025
1 parent 6a0d6c8 commit 6973d76
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/src/main/java/com/nononsenseapps/feeder/model/FeedParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import rust.nostr.sdk.KindEnum
import rust.nostr.sdk.Nip19Profile
import rust.nostr.sdk.Nip21
import rust.nostr.sdk.Nip21Enum
import rust.nostr.sdk.NostrSdkException
import rust.nostr.sdk.PublicKey
import rust.nostr.sdk.RelayMetadata
import rust.nostr.sdk.SingleLetterTag
Expand Down Expand Up @@ -272,10 +273,20 @@ class FeedParser(override val di: DI) : DIAware {
}
nostrClient.connect()
val profileInfo =
nostrClient.fetchMetadata(
publicKey = publicKey,
timeout = Duration.ofSeconds(5L),
)
try {
nostrClient.fetchMetadata(
publicKey = publicKey,
timeout = Duration.ofSeconds(5L),
)
} catch (e: NostrSdkException) {
//We will use a default relay regardless of whether it is added above, to keep things simple.
nostrClient.addReadRelay(defaultFetchRelays.random())
nostrClient.connect()
nostrClient.fetchMetadata(
publicKey = publicKey,
timeout = Duration.ofSeconds(5L),
)
}
logDebug(LOG_TAG, profileInfo.asPrettyJson())

// Check if all relays in relaylist can be connected to
Expand Down Expand Up @@ -333,7 +344,7 @@ class FeedParser(override val di: DI) : DIAware {

nostrClient.removeAllRelays()
val relaysToUse =
relays.take(2).plus(defaultArticleFetchRelays.random())
relays.take(3).plus(defaultArticleFetchRelays.random())
.ifEmpty { defaultFetchRelays }
relaysToUse.forEach { relay -> nostrClient.addReadRelay(relay) }
nostrClient.connect()
Expand Down

0 comments on commit 6973d76

Please sign in to comment.