Adds a Deletion event cache.

This commit is contained in:
Vitor Pamplona
2024-04-05 11:19:15 -04:00
parent 1b7ba3de01
commit 7bb72d0c2d
6 changed files with 106 additions and 3 deletions
@@ -25,7 +25,7 @@ import androidx.compose.runtime.Immutable
@Immutable
data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val relay: String?) {
fun toTag() = "$kind:$pubKeyHex:$dTag"
fun toTag() = assembleATag(kind, pubKeyHex, dTag)
fun toNAddr(): String {
return TlvBuilder()
@@ -40,6 +40,12 @@ data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val rela
}
companion object {
fun assembleATag(
kind: Int,
pubKeyHex: String,
dTag: String,
) = "$kind:$pubKeyHex:$dTag"
fun isATag(key: String): Boolean {
return key.startsWith("naddr1") || key.contains(":")
}
@@ -514,6 +514,8 @@ interface AddressableEvent {
fun dTag(): String
fun address(): ATag
fun addressTag(): String
}
@Immutable
@@ -529,6 +531,11 @@ open class BaseAddressableEvent(
override fun dTag() = tags.firstOrNull { it.size > 1 && it[0] == "d" }?.get(1) ?: ""
override fun address() = ATag(kind, pubKey, dTag(), null)
/**
* Creates the tag in a memory effecient way (without creating the ATag class
*/
override fun addressTag() = ATag.assembleATag(kind, pubKey, dTag())
}
fun String.bytesUsedInMemory(): Int {
@@ -39,6 +39,8 @@ class LongTextNoteEvent(
override fun address() = ATag(kind, pubKey, dTag(), null)
override fun addressTag() = ATag.assembleATag(kind, pubKey, dTag())
fun topics() = hashtags()
fun title() = tags.firstOrNull { it.size > 1 && it[0] == "title" }?.get(1)
@@ -39,6 +39,8 @@ class WikiNoteEvent(
override fun address() = ATag(kind, pubKey, dTag(), null)
override fun addressTag() = ATag.assembleATag(kind, pubKey, dTag())
fun topics() = hashtags()
fun title() = tags.firstOrNull { it.size > 1 && it[0] == "title" }?.get(1)