Fixes binary payloads in the search results.

This commit is contained in:
Vitor Pamplona 2024-03-19 11:49:03 -04:00
parent 99270662ee
commit 410d6bd690
9 changed files with 59 additions and 31 deletions

View File

@ -1629,39 +1629,51 @@ object LocalCache {
}
return notes.filter { _, note ->
(
note.event !is GenericRepostEvent &&
note.event !is RepostEvent &&
note.event !is CommunityPostApprovalEvent &&
note.event !is ReactionEvent &&
note.event !is GiftWrapEvent &&
note.event !is SealedGossipEvent &&
note.event !is OtsEvent &&
note.event !is LnZapEvent &&
note.event !is LnZapRequestEvent
) &&
(
note.event?.content()?.contains(text, true)
?: false ||
note.event?.matchTag1With(text) ?: false ||
note.idHex.startsWith(text, true) ||
note.idNote().startsWith(text, true)
)
if (note.event is GenericRepostEvent ||
note.event is RepostEvent ||
note.event is CommunityPostApprovalEvent ||
note.event is ReactionEvent ||
note.event is LnZapEvent ||
note.event is LnZapRequestEvent
) {
return@filter false
}
if (note.event?.matchTag1With(text) == true ||
note.idHex.startsWith(text, true) ||
note.idNote().startsWith(text, true)
) {
return@filter true
}
if (note.event?.isContentEncoded() == false) {
return@filter note.event?.content()?.contains(text, true) ?: false
}
return@filter false
} +
addressables.filter { _, addressable ->
(
addressable.event !is GenericRepostEvent &&
addressable.event !is RepostEvent &&
addressable.event !is CommunityPostApprovalEvent &&
addressable.event !is ReactionEvent &&
addressable.event !is GiftWrapEvent &&
addressable.event !is LnZapEvent &&
addressable.event !is LnZapRequestEvent
) &&
(
addressable.event?.content()?.contains(text, true)
?: false || addressable.event?.matchTag1With(text) ?: false || addressable.idHex.startsWith(text, true)
)
if (addressable.event is GenericRepostEvent ||
addressable.event is RepostEvent ||
addressable.event is CommunityPostApprovalEvent ||
addressable.event is ReactionEvent ||
addressable.event is LnZapEvent ||
addressable.event is LnZapRequestEvent
) {
return@filter false
}
if (addressable.event?.matchTag1With(text) == true ||
addressable.idHex.startsWith(text, true)
) {
return@filter true
}
if (addressable.event?.isContentEncoded() == false) {
return@filter addressable.event?.content()?.contains(text, true) ?: false
}
return@filter false
}
}

View File

@ -54,6 +54,8 @@ open class Event(
val content: String,
val sig: HexKey,
) : EventInterface {
override fun isContentEncoded() = false
override fun countMemory(): Long {
return 12L +
id.bytesUsedInMemory() +

View File

@ -27,6 +27,8 @@ import java.math.BigDecimal
@Immutable
interface EventInterface {
fun isContentEncoded(): Boolean
fun countMemory(): Long
fun id(): HexKey

View File

@ -36,6 +36,8 @@ class FileStorageEvent(
content: String,
sig: HexKey,
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
override fun isContentEncoded() = true
fun type() = tags.firstOrNull { it.size > 1 && it[0] == TYPE }?.get(1)
fun decryptKey() = tags.firstOrNull { it.size > 2 && it[0] == DECRYPT }?.let { AESGCM(it[1], it[2]) }

View File

@ -42,6 +42,8 @@ abstract class GeneralListEvent(
) : BaseAddressableEvent(id, pubKey, createdAt, kind, tags, content, sig) {
@Transient private var privateTagsCache: Array<Array<String>>? = null
override fun isContentEncoded() = true
fun category() = dTag()
fun bookmarkedPosts() = taggedEvents()

View File

@ -38,6 +38,8 @@ class GiftWrapEvent(
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
override fun isContentEncoded() = true
fun preCachedGift(signer: NostrSigner): Event? {
return cachedInnerEvent[signer.pubKey]
}

View File

@ -48,6 +48,8 @@ class OtsEvent(
@Transient
var verifiedTime: Long? = null
override fun isContentEncoded() = true
fun digestEvent() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
fun digest() = digestEvent()?.hexToByteArray()

View File

@ -40,6 +40,8 @@ class PrivateDmEvent(
) : Event(id, pubKey, createdAt, KIND, tags, content, sig), ChatroomKeyable {
@Transient private var decryptedContent: Map<HexKey, String> = mapOf()
override fun isContentEncoded() = true
/**
* This may or may not be the actual recipient's pub key. The event is intended to look like a
* nip-04 EncryptedDmEvent but may omit the recipient, too. This value can be queried and used for

View File

@ -39,6 +39,8 @@ class SealedGossipEvent(
) : WrappedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
override fun isContentEncoded() = true
fun preCachedGossip(signer: NostrSigner): Event? {
return cachedInnerEvent[signer.pubKey]
}