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
@@ -1629,39 +1629,51 @@ object LocalCache {
} }
return notes.filter { _, note -> return notes.filter { _, note ->
( if (note.event is GenericRepostEvent ||
note.event !is GenericRepostEvent && note.event is RepostEvent ||
note.event !is RepostEvent && note.event is CommunityPostApprovalEvent ||
note.event !is CommunityPostApprovalEvent && note.event is ReactionEvent ||
note.event !is ReactionEvent && note.event is LnZapEvent ||
note.event !is GiftWrapEvent && note.event is LnZapRequestEvent
note.event !is SealedGossipEvent && ) {
note.event !is OtsEvent && return@filter false
note.event !is LnZapEvent && }
note.event !is LnZapRequestEvent
) && if (note.event?.matchTag1With(text) == true ||
( note.idHex.startsWith(text, true) ||
note.event?.content()?.contains(text, true) note.idNote().startsWith(text, true)
?: false || ) {
note.event?.matchTag1With(text) ?: false || return@filter true
note.idHex.startsWith(text, true) || }
note.idNote().startsWith(text, true)
) if (note.event?.isContentEncoded() == false) {
return@filter note.event?.content()?.contains(text, true) ?: false
}
return@filter false
} + } +
addressables.filter { _, addressable -> addressables.filter { _, addressable ->
( if (addressable.event is GenericRepostEvent ||
addressable.event !is GenericRepostEvent && addressable.event is RepostEvent ||
addressable.event !is RepostEvent && addressable.event is CommunityPostApprovalEvent ||
addressable.event !is CommunityPostApprovalEvent && addressable.event is ReactionEvent ||
addressable.event !is ReactionEvent && addressable.event is LnZapEvent ||
addressable.event !is GiftWrapEvent && addressable.event is LnZapRequestEvent
addressable.event !is LnZapEvent && ) {
addressable.event !is LnZapRequestEvent return@filter false
) && }
(
addressable.event?.content()?.contains(text, true) if (addressable.event?.matchTag1With(text) == true ||
?: false || addressable.event?.matchTag1With(text) ?: false || addressable.idHex.startsWith(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
} }
} }
@@ -54,6 +54,8 @@ open class Event(
val content: String, val content: String,
val sig: HexKey, val sig: HexKey,
) : EventInterface { ) : EventInterface {
override fun isContentEncoded() = false
override fun countMemory(): Long { override fun countMemory(): Long {
return 12L + return 12L +
id.bytesUsedInMemory() + id.bytesUsedInMemory() +
@@ -27,6 +27,8 @@ import java.math.BigDecimal
@Immutable @Immutable
interface EventInterface { interface EventInterface {
fun isContentEncoded(): Boolean
fun countMemory(): Long fun countMemory(): Long
fun id(): HexKey fun id(): HexKey
@@ -36,6 +36,8 @@ class FileStorageEvent(
content: String, content: String,
sig: HexKey, sig: HexKey,
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) { ) : 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 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]) } fun decryptKey() = tags.firstOrNull { it.size > 2 && it[0] == DECRYPT }?.let { AESGCM(it[1], it[2]) }
@@ -42,6 +42,8 @@ abstract class GeneralListEvent(
) : BaseAddressableEvent(id, pubKey, createdAt, kind, tags, content, sig) { ) : BaseAddressableEvent(id, pubKey, createdAt, kind, tags, content, sig) {
@Transient private var privateTagsCache: Array<Array<String>>? = null @Transient private var privateTagsCache: Array<Array<String>>? = null
override fun isContentEncoded() = true
fun category() = dTag() fun category() = dTag()
fun bookmarkedPosts() = taggedEvents() fun bookmarkedPosts() = taggedEvents()
@@ -38,6 +38,8 @@ class GiftWrapEvent(
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) { ) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf() @Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
override fun isContentEncoded() = true
fun preCachedGift(signer: NostrSigner): Event? { fun preCachedGift(signer: NostrSigner): Event? {
return cachedInnerEvent[signer.pubKey] return cachedInnerEvent[signer.pubKey]
} }
@@ -48,6 +48,8 @@ class OtsEvent(
@Transient @Transient
var verifiedTime: Long? = null var verifiedTime: Long? = null
override fun isContentEncoded() = true
fun digestEvent() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1) fun digestEvent() = tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
fun digest() = digestEvent()?.hexToByteArray() fun digest() = digestEvent()?.hexToByteArray()
@@ -40,6 +40,8 @@ class PrivateDmEvent(
) : Event(id, pubKey, createdAt, KIND, tags, content, sig), ChatroomKeyable { ) : Event(id, pubKey, createdAt, KIND, tags, content, sig), ChatroomKeyable {
@Transient private var decryptedContent: Map<HexKey, String> = mapOf() @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 * 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 * nip-04 EncryptedDmEvent but may omit the recipient, too. This value can be queried and used for
@@ -39,6 +39,8 @@ class SealedGossipEvent(
) : WrappedEvent(id, pubKey, createdAt, KIND, tags, content, sig) { ) : WrappedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf() @Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
override fun isContentEncoded() = true
fun preCachedGossip(signer: NostrSigner): Event? { fun preCachedGossip(signer: NostrSigner): Event? {
return cachedInnerEvent[signer.pubKey] return cachedInnerEvent[signer.pubKey]
} }