Adds a normalized parser to all nip65 relays

This commit is contained in:
Vitor Pamplona
2025-08-30 12:45:32 -04:00
parent 4c34c6b8e3
commit a063107a15
2 changed files with 9 additions and 0 deletions

View File

@@ -41,6 +41,8 @@ class AdvertisedRelayListEvent(
) : BaseReplaceableEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
fun relays() = tags.mapNotNull(AdvertisedRelayInfo::parse)
fun relaysNorm() = tags.mapNotNull(AdvertisedRelayInfo::parseNorm)
fun readRelays() = tags.mapNotNull(AdvertisedRelayInfo::parseRead).ifEmpty { null }
fun readRelaysNorm() = tags.mapNotNull(AdvertisedRelayInfo::parseReadNorm).ifEmpty { null }

View File

@@ -58,6 +58,13 @@ class AdvertisedRelayInfo(
return AdvertisedRelayInfo(normalizedUrl, type)
}
@JvmStatic
fun parseNorm(tag: Array<String>): NormalizedRelayUrl? {
ensure(match(tag)) { return null }
val normalizedUrl = RelayUrlNormalizer.normalizeOrNull(tag[1])
return normalizedUrl
}
@JvmStatic
fun parseRead(tag: Array<String>): String? {
ensure(match(tag)) { return null }