Reformats due to new lint
This commit is contained in:
+2
-3
@@ -33,11 +33,10 @@ class RelayBasedFilter(
|
||||
// This only exists because some relays confuse empty lists with null lists
|
||||
fun isValidFor(relay: NormalizedRelayUrl) = relay == this.relay
|
||||
|
||||
fun toFilter(relay: NormalizedRelayUrl): Filter? {
|
||||
return if (isValidFor(relay)) {
|
||||
fun toFilter(relay: NormalizedRelayUrl): Filter? =
|
||||
if (isValidFor(relay)) {
|
||||
filter
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -29,7 +29,9 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.single.IRelayClient
|
||||
import com.vitorpamplona.quartz.nip42RelayAuth.RelayAuthEvent
|
||||
import com.vitorpamplona.quartz.utils.LargeCache
|
||||
|
||||
class OutboxProtector(listener: IRelayClientListener) : RedirectRelayClientListener(listener) {
|
||||
class OutboxProtector(
|
||||
listener: IRelayClientListener,
|
||||
) : RedirectRelayClientListener(listener) {
|
||||
/**
|
||||
* Auth procedures require us to keep track of the outgoing events
|
||||
* to make sure the relay waits for the auth to finish and send them.
|
||||
|
||||
+3
-1
@@ -20,7 +20,9 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip01Core.relay.normalizer
|
||||
|
||||
data class NormalizedRelayUrl(val url: String) : Comparable<NormalizedRelayUrl> {
|
||||
data class NormalizedRelayUrl(
|
||||
val url: String,
|
||||
) : Comparable<NormalizedRelayUrl> {
|
||||
override fun compareTo(other: NormalizedRelayUrl) = url.compareTo(other.url)
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -31,7 +31,14 @@ class RelayUrlNormalizer {
|
||||
|
||||
fun isOnion(url: String) = url.endsWith(".onion") || url.endsWith(".onion/")
|
||||
|
||||
private fun norm(url: String) = NormalizedRelayUrl(URIReference.parse(url).normalize().toString().intern())
|
||||
private fun norm(url: String) =
|
||||
NormalizedRelayUrl(
|
||||
URIReference
|
||||
.parse(url)
|
||||
.normalize()
|
||||
.toString()
|
||||
.intern(),
|
||||
)
|
||||
|
||||
fun fix(url: String): String {
|
||||
val trimmed = url.trim()
|
||||
|
||||
@@ -59,15 +59,14 @@ data class MarkedETag(
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun parse(code: String): MARKER? {
|
||||
return when (code) {
|
||||
fun parse(code: String): MARKER? =
|
||||
when (code) {
|
||||
ROOT.code -> ROOT
|
||||
REPLY.code -> REPLY
|
||||
MENTION.code -> MENTION
|
||||
FORK.code -> FORK
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -58,8 +58,7 @@ class ChatMessageRelayListEvent(
|
||||
RelayTag.assemble(it)
|
||||
}.plusElement(
|
||||
AltTag.assemble("Relay list to receive private messages"),
|
||||
)
|
||||
.toTypedArray()
|
||||
).toTypedArray()
|
||||
|
||||
fun updateRelayList(
|
||||
earlierVersion: ChatMessageRelayListEvent,
|
||||
@@ -69,7 +68,8 @@ class ChatMessageRelayListEvent(
|
||||
onReady: (ChatMessageRelayListEvent) -> Unit,
|
||||
) {
|
||||
val tags =
|
||||
earlierVersion.tags.filter(RelayTag::notMatch)
|
||||
earlierVersion.tags
|
||||
.filter(RelayTag::notMatch)
|
||||
.plus(
|
||||
relays.map {
|
||||
RelayTag.assemble(it)
|
||||
|
||||
+4
-5
@@ -46,16 +46,15 @@ class ChannelCreateEvent(
|
||||
sig: HexKey,
|
||||
) : Event(id, pubKey, createdAt, KIND, tags, content, sig),
|
||||
EventHintProvider {
|
||||
override fun eventHints() = channelInfo().relays?.mapNotNull { EventIdHint(id, it) } ?: emptyList()
|
||||
override fun eventHints() = channelInfo().relays?.map { EventIdHint(id, it) } ?: emptyList()
|
||||
|
||||
fun channelInfo(): ChannelDataNorm {
|
||||
return try {
|
||||
fun channelInfo(): ChannelDataNorm =
|
||||
try {
|
||||
ChannelData.parse(content)?.normalize() ?: ChannelDataNorm()
|
||||
} catch (e: JsonParseException) {
|
||||
Log.e("ChannelCreateEvent", "Failure to parse ${this.toJson()}", e)
|
||||
Log.w("ChannelCreateEvent", "Failure to parse ${this.toJson()}", e)
|
||||
ChannelDataNorm()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 40
|
||||
|
||||
+4
-5
@@ -48,16 +48,15 @@ class ChannelMetadataEvent(
|
||||
sig: HexKey,
|
||||
) : BasePublicChatEvent(id, pubKey, createdAt, KIND, tags, content, sig),
|
||||
EventHintProvider {
|
||||
override fun eventHints() = channelInfo().relays?.mapNotNull { EventIdHint(id, it) } ?: emptyList()
|
||||
override fun eventHints() = channelInfo().relays?.map { EventIdHint(id, it) } ?: emptyList()
|
||||
|
||||
fun channelInfo(): ChannelDataNorm {
|
||||
return try {
|
||||
fun channelInfo(): ChannelDataNorm =
|
||||
try {
|
||||
ChannelData.parse(content)?.normalize() ?: ChannelDataNorm()
|
||||
} catch (e: JsonParseException) {
|
||||
Log.e("ChannelCreateEvent", "Failure to parse ${this.toJson()}", e)
|
||||
Log.w("ChannelCreateEvent", "Failure to parse ${this.toJson()}", e)
|
||||
ChannelDataNorm()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 41
|
||||
|
||||
@@ -61,13 +61,12 @@ class MuteListEvent(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun publicAndPrivateUsersAndWords(signer: NostrSigner): UsersAndWords? {
|
||||
return tryAndWait { continuation ->
|
||||
suspend fun publicAndPrivateUsersAndWords(signer: NostrSigner): UsersAndWords? =
|
||||
tryAndWait { continuation ->
|
||||
publicAndPrivateUsersAndWords(signer) { privateTagList ->
|
||||
continuation.resume(privateTagList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 10000
|
||||
|
||||
@@ -64,13 +64,12 @@ class PeopleListEvent(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun publicAndPrivateUsersAndWords(signer: NostrSigner): UsersAndWords? {
|
||||
return tryAndWait { continuation ->
|
||||
suspend fun publicAndPrivateUsersAndWords(signer: NostrSigner): UsersAndWords? =
|
||||
tryAndWait { continuation ->
|
||||
publicAndPrivateUsersAndWords(signer) { privateTagList ->
|
||||
continuation.resume(privateTagList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isTaggedWord(
|
||||
word: String,
|
||||
|
||||
+4
-6
@@ -31,8 +31,8 @@ class RelayListRecommendationProcessor {
|
||||
fun transpose(
|
||||
userList: Map<HexKey, Set<NormalizedRelayUrl>>,
|
||||
ignore: Set<NormalizedRelayUrl> = setOf(),
|
||||
): Map<NormalizedRelayUrl, Set<HexKey>> {
|
||||
return mapOfSet {
|
||||
): Map<NormalizedRelayUrl, Set<HexKey>> =
|
||||
mapOfSet {
|
||||
userList.forEach { event ->
|
||||
event.value.forEach { relay ->
|
||||
if (relay !in ignore) {
|
||||
@@ -41,7 +41,6 @@ class RelayListRecommendationProcessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* filter onion and local host from write relays
|
||||
@@ -50,8 +49,8 @@ class RelayListRecommendationProcessor {
|
||||
private fun filterValidRelays(
|
||||
userList: List<AdvertisedRelayListEvent>,
|
||||
hasOnionConnection: Boolean = false,
|
||||
): Map<HexKey, Set<NormalizedRelayUrl>> {
|
||||
return mapOfSet {
|
||||
): Map<HexKey, Set<NormalizedRelayUrl>> =
|
||||
mapOfSet {
|
||||
userList.forEach { event ->
|
||||
event.writeRelaysNorm()?.forEach { relay ->
|
||||
if (!relay.isLocalHost() && (hasOnionConnection || !relay.isOnion())) {
|
||||
@@ -60,7 +59,6 @@ class RelayListRecommendationProcessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun reliableRelaySetFor(
|
||||
usersAndRelays: Map<HexKey, Set<NormalizedRelayUrl>>,
|
||||
|
||||
+2
-3
@@ -94,13 +94,12 @@ class AdvertisedRelayInfo(
|
||||
fun assemble(
|
||||
relay: NormalizedRelayUrl,
|
||||
type: AdvertisedRelayType,
|
||||
): Array<String> {
|
||||
return if (type == AdvertisedRelayType.BOTH) {
|
||||
): Array<String> =
|
||||
if (type == AdvertisedRelayType.BOTH) {
|
||||
arrayOf(TAG_NAME, relay.url)
|
||||
} else {
|
||||
arrayOf(TAG_NAME, relay.url, type.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,23 +70,21 @@ class HashtagId(
|
||||
return encoded.indexOf(value, 1) > 0
|
||||
}
|
||||
|
||||
fun parse(encoded: String): String? {
|
||||
return if (encoded.length > 1 && encoded[0] == KIND_CHR) {
|
||||
fun parse(encoded: String): String? =
|
||||
if (encoded.length > 1 && encoded[0] == KIND_CHR) {
|
||||
encoded.substring(1)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun parse(
|
||||
encoded: String,
|
||||
hint: String?,
|
||||
): HashtagId? {
|
||||
return if (encoded.length > 1 && encoded[0] == KIND_CHR) {
|
||||
): HashtagId? =
|
||||
if (encoded.length > 1 && encoded[0] == KIND_CHR) {
|
||||
HashtagId(encoded.substring(1), hint)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,10 +64,9 @@ fun <K, V> mapOfSet(init: MapOfSetBuilder<K, V>.() -> Unit): Map<K, Set<V>> {
|
||||
return data.build()
|
||||
}
|
||||
|
||||
fun <K, V> merge(maps: List<Map<K, Set<V>>>): Map<K, Set<V>> {
|
||||
return mapOfSet {
|
||||
fun <K, V> merge(maps: List<Map<K, Set<V>>>): Map<K, Set<V>> =
|
||||
mapOfSet {
|
||||
maps.forEach { map ->
|
||||
add(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ class HintIndexerTest {
|
||||
.getResourceAsStream("relayDB.txt")
|
||||
?.readAllBytes()
|
||||
.toString()
|
||||
.split("\n").mapNotNull { RelayUrlNormalizer.normalizeOrNull(it) }
|
||||
.split("\n")
|
||||
.mapNotNull { RelayUrlNormalizer.normalizeOrNull(it) }
|
||||
|
||||
val indexer by lazy {
|
||||
System.gc()
|
||||
|
||||
Reference in New Issue
Block a user