Refactoring

This commit is contained in:
Vitor Pamplona 2024-06-11 18:19:07 -04:00
parent b785e0d505
commit cafad6a003
5 changed files with 10 additions and 10 deletions

View File

@ -209,13 +209,13 @@ object LocalCache {
} as LatestByKindAndAuthor<T>
}
fun updateObservables(event: Event) {
val observablesOfKind = observablesByKindAndETag[event.kind()] ?: return
private fun updateObservables(event: Event) {
val observablesOfKind = observablesByKindAndETag[event.kind] ?: return
event.forEachTaggedEvent {
observablesOfKind[it]?.updateIfMatches(event)
}
observablesByKindAndAuthor[event.kind()]?.get(event.pubKey)?.updateIfMatches(event)
observablesByKindAndAuthor[event.kind]?.get(event.pubKey)?.updateIfMatches(event)
}
fun checkGetOrCreateUser(key: String): User? {

View File

@ -30,8 +30,8 @@ import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.events.RelayAuthEvent
import com.vitorpamplona.quartz.events.bytesUsedInMemory
import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import kotlinx.coroutines.CancellationException
import okhttp3.Request
import okhttp3.Response

View File

@ -193,8 +193,7 @@ open class BaseTextNoteEvent(
val repliesTo = replyTos()
val tagAddresses =
taggedAddresses().filter {
it.kind != CommunityDefinitionEvent.KIND &&
(kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
it.kind != CommunityDefinitionEvent.KIND && (kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
// removes forks from itself.
}.map { it.toTag() }
if (repliesTo.isEmpty() && tagAddresses.isEmpty()) return emptyList()

View File

@ -43,6 +43,7 @@ import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
import java.math.BigDecimal
import java.security.MessageDigest
@ -564,10 +565,6 @@ open class BaseAddressableEvent(
override fun addressTag() = ATag.assembleATag(kind, pubKey, dTag())
}
fun String.bytesUsedInMemory(): Int {
return (8 * ((((this.length) * 2) + 45) / 8))
}
data class ZapSplitSetup(
val lnAddressOrPubKeyHex: String,
val relay: String?,

View File

@ -22,6 +22,10 @@ package com.vitorpamplona.quartz.utils
import kotlin.math.min
fun String.bytesUsedInMemory(): Int {
return (8 * ((((this.length) * 2) + 45) / 8))
}
fun String.containsIgnoreCase(term: String): Boolean {
if (term.isEmpty()) return true // Empty string is contained