Migrates LocalCache from being based on ATags to Addresses, removing the need to use memory space to store relay hints
This commit is contained in:
@@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -50,6 +51,8 @@ class BlossomServersEvent(
|
||||
const val KIND = 10063
|
||||
const val ALT = "File servers used by the author"
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
+3
@@ -29,6 +29,7 @@ import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip21UriScheme.toNostrUri
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@@ -102,6 +103,8 @@ class PrivateOutboxRelayListEvent(
|
||||
const val KIND = 10013
|
||||
val TAGS = arrayOf(AltTag.assemble("Relay list to store private content from this author"))
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
+2
-4
@@ -21,7 +21,7 @@
|
||||
package com.vitorpamplona.quartz.experimental.forks
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
|
||||
import com.vitorpamplona.quartz.nip10Notes.tags.MarkedETag
|
||||
|
||||
@@ -30,9 +30,7 @@ fun BaseThreadedEvent.isAFork() = tags.any { it.size > 3 && (it[0] == "a" || it[
|
||||
fun BaseThreadedEvent.forkFromAddress() =
|
||||
tags.firstOrNull { it.size > 3 && it[0] == "a" && it[3] == "fork" }?.let {
|
||||
val aTagValue = it[1]
|
||||
val relay = it.getOrNull(2)
|
||||
|
||||
ATag.parse(aTagValue, relay)
|
||||
Address.parse(aTagValue)
|
||||
}
|
||||
|
||||
fun BaseThreadedEvent.forkFromVersion() = tags.firstNotNullOfOrNull(MarkedETag::parseFork)
|
||||
|
||||
+7
-1
@@ -30,6 +30,7 @@ import com.vitorpamplona.quartz.nip01Core.core.builder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
|
||||
import com.vitorpamplona.quartz.nip23LongContent.tags.ImageTag
|
||||
import com.vitorpamplona.quartz.nip23LongContent.tags.TitleTag
|
||||
@@ -57,13 +58,18 @@ class InteractiveStoryReadingStateEvent(
|
||||
|
||||
fun root() = tags.firstNotNullOfOrNull(RootSceneTag::parse)
|
||||
|
||||
fun currentScene() = tags.firstNotNullOfOrNull(ATag::parse)
|
||||
fun currentScene() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
|
||||
companion object {
|
||||
const val KIND = 30298
|
||||
const val ALT1 = "Interactive Story Reading state"
|
||||
const val ALT2 = "The reading state of "
|
||||
|
||||
fun createAddress(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
): Address = Address(KIND, pubKey, dtag)
|
||||
|
||||
fun createAddressATag(
|
||||
pubKey: HexKey,
|
||||
dtag: String,
|
||||
|
||||
+11
-6
@@ -20,14 +20,16 @@
|
||||
*/
|
||||
package com.vitorpamplona.quartz.experimental.interactiveStories.tags
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip46RemoteSigner.getOrNull
|
||||
import com.vitorpamplona.quartz.utils.arrayOfNotNull
|
||||
|
||||
class StoryOptionTag(
|
||||
val option: String,
|
||||
val address: ATag,
|
||||
val address: Address,
|
||||
val relay: String?,
|
||||
) {
|
||||
fun toTagArray() = assemble(option, address)
|
||||
fun toTagArray() = assemble(option, address, relay)
|
||||
|
||||
companion object {
|
||||
const val TAG_NAME = "option"
|
||||
@@ -37,13 +39,16 @@ class StoryOptionTag(
|
||||
fun parse(tag: Array<String>): StoryOptionTag? {
|
||||
if (tag.size < TAG_SIZE || tag[0] != TAG_NAME) return null
|
||||
|
||||
return ATag.parse(tag[2], tag.getOrNull(3))?.let { StoryOptionTag(tag[1], it) }
|
||||
val address = Address.parse(tag[2]) ?: return null
|
||||
|
||||
return StoryOptionTag(tag[1], address, tag.getOrNull(3))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
title: String,
|
||||
destination: ATag,
|
||||
) = arrayOfNotNull(TAG_NAME, title, destination.toTag(), destination.relay)
|
||||
address: Address,
|
||||
relay: String?,
|
||||
) = arrayOfNotNull(TAG_NAME, title, address.toValue(), relay)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,5 +46,5 @@ open class BaseAddressableEvent(
|
||||
/**
|
||||
* Creates the tag in a memory efficient way (without creating the ATag class
|
||||
*/
|
||||
override fun addressTag() = ATag.assembleATagId(kind, pubKey, dTag())
|
||||
override fun addressTag() = Address.assemble(kind, pubKey, dTag())
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ open class BaseReplaceableEvent(
|
||||
/**
|
||||
* Creates the tag in a memory efficient way (without creating the ATag class
|
||||
*/
|
||||
override fun addressTag() = ATag.assembleATagId(kind, pubKey, FIXED_D_TAG)
|
||||
override fun addressTag() = Address.assemble(kind, pubKey, dTag())
|
||||
|
||||
companion object {
|
||||
const val FIXED_D_TAG = ""
|
||||
|
||||
@@ -34,19 +34,9 @@ data class ATag(
|
||||
val kind: Int,
|
||||
val pubKeyHex: String,
|
||||
val dTag: String,
|
||||
val relay: String? = null,
|
||||
) {
|
||||
var relay: String? = null
|
||||
|
||||
constructor(address: Address) : this(address.kind, address.pubKeyHex, address.dTag)
|
||||
|
||||
constructor(
|
||||
kind: Int,
|
||||
pubKeyHex: HexKey,
|
||||
dTag: String,
|
||||
relayHint: String?,
|
||||
) : this(kind, pubKeyHex, dTag) {
|
||||
this.relay = relayHint
|
||||
}
|
||||
constructor(address: Address, relayHint: String? = null) : this(address.kind, address.pubKeyHex, address.dTag, relayHint)
|
||||
|
||||
fun countMemory(): Long =
|
||||
5 * pointerSizeInBytes + // 7 fields, 4 bytes each reference (32bit)
|
||||
@@ -129,6 +119,9 @@ data class ATag(
|
||||
@JvmStatic
|
||||
fun parseAddress(tag: Array<String>) = ATagParser.parseAddress(TAG_NAME, tag)
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddressId(tag: Array<String>) = ATagParser.parseAddressId(TAG_NAME, tag)
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(
|
||||
aTagId: HexKey,
|
||||
|
||||
+9
@@ -99,6 +99,15 @@ class ATagParser {
|
||||
fun parseAddress(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): Address? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return Address.parse(tag[1])
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun parseAddressId(
|
||||
tagName: String,
|
||||
tag: Array<String>,
|
||||
): String? {
|
||||
if (tag.isNotName(tagName, TAG_SIZE)) return null
|
||||
return tag[1]
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import com.vitorpamplona.quartz.utils.Hex
|
||||
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
import com.vitorpamplona.quartz.utils.pointerSizeInBytes
|
||||
|
||||
class Address(
|
||||
data class Address(
|
||||
val kind: Int,
|
||||
val pubKeyHex: HexKey,
|
||||
val dTag: String,
|
||||
|
||||
@@ -34,6 +34,10 @@ fun Event.isTaggedAddressableKind(kind: Int) = tags.isTaggedAddressableKind(kind
|
||||
|
||||
fun Event.getTagOfAddressableKind(kind: Int) = tags.getTagOfAddressableKind(kind)
|
||||
|
||||
fun Event.taggedATags() = tags.taggedATags()
|
||||
|
||||
fun Event.firstTaggedATag() = tags.firstTaggedATag()
|
||||
|
||||
fun Event.taggedAddresses() = tags.taggedAddresses()
|
||||
|
||||
fun Event.firstTaggedAddress() = tags.firstTaggedAddress()
|
||||
|
||||
+8
-4
@@ -29,14 +29,18 @@ fun <R> TagArray.mapTaggedAddress(map: (address: String) -> R) = this.mapValueTa
|
||||
|
||||
fun TagArray.firstIsTaggedAddressableNote(addressableNotes: Set<String>) = this.firstNotNullOfOrNull(ATag::parseIfIsIn, addressableNotes)
|
||||
|
||||
fun TagArray.isTaggedAddressableNote(idHex: String) = this.any(ATag::isTagged, idHex)
|
||||
fun TagArray.isTaggedAddressableNote(addressId: String) = this.any(ATag::isTagged, addressId)
|
||||
|
||||
fun TagArray.isTaggedAddressableNotes(idHexes: Set<String>) = this.any(ATag::isIn, idHexes)
|
||||
fun TagArray.isTaggedAddressableNotes(addressIds: Set<String>) = this.any(ATag::isIn, addressIds)
|
||||
|
||||
fun TagArray.isTaggedAddressableKind(kind: Int) = this.any(ATag::isTaggedWithKind, kind.toString())
|
||||
|
||||
fun TagArray.getTagOfAddressableKind(kind: Int) = this.firstNotNullOfOrNull(ATag::parseIfOfKind, kind.toString())
|
||||
|
||||
fun TagArray.taggedAddresses() = this.mapNotNull(ATag::parse)
|
||||
fun TagArray.taggedATags() = this.mapNotNull(ATag::parse)
|
||||
|
||||
fun TagArray.firstTaggedAddress() = this.firstNotNullOfOrNull(ATag::parse)
|
||||
fun TagArray.firstTaggedATag() = this.firstNotNullOfOrNull(ATag::parse)
|
||||
|
||||
fun TagArray.taggedAddresses() = this.mapNotNull(ATag::parseAddress)
|
||||
|
||||
fun TagArray.firstTaggedAddress() = this.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
|
||||
@@ -55,7 +55,7 @@ class DeletionEvent(
|
||||
|
||||
fun deleteAddresses() = taggedAddresses()
|
||||
|
||||
fun deleteAddressTags() = tags.mapNotNull(ATag::parseAddress)
|
||||
fun deleteAddressIds() = tags.mapNotNull(ATag::parseAddressId)
|
||||
|
||||
companion object {
|
||||
const val KIND = 5
|
||||
|
||||
@@ -23,7 +23,7 @@ package com.vitorpamplona.quartz.nip10Notes
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedAddresses
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedATags
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findIndexTagsWithEventsOrAddresses
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findIndexTagsWithPeople
|
||||
@@ -141,7 +141,7 @@ open class BaseThreadedEvent(
|
||||
val uncertainRepliesTo = unmarkedReplyTos()
|
||||
|
||||
val tagAddresses =
|
||||
taggedAddresses()
|
||||
taggedATags()
|
||||
.filter {
|
||||
it.kind != CommunityDefinitionEvent.KIND && (kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
|
||||
// removes forks from itself.
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -50,6 +51,8 @@ class ChatMessageRelayListEvent(
|
||||
companion object {
|
||||
const val KIND = 10050
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
@@ -75,12 +75,14 @@ data class NAddress(
|
||||
kind: Int,
|
||||
pubKeyHex: String,
|
||||
dTag: String,
|
||||
relay: String?,
|
||||
vararg relays: String?,
|
||||
): String =
|
||||
TlvBuilder()
|
||||
.apply {
|
||||
addString(TlvTypes.SPECIAL, dTag)
|
||||
addStringIfNotNull(TlvTypes.RELAY, relay)
|
||||
relays.forEach {
|
||||
addStringIfNotNull(TlvTypes.RELAY, it)
|
||||
}
|
||||
addHex(TlvTypes.AUTHOR, pubKeyHex)
|
||||
addInt(TlvTypes.KIND, kind)
|
||||
}.build()
|
||||
|
||||
@@ -59,12 +59,14 @@ data class NEvent(
|
||||
idHex: String,
|
||||
author: String?,
|
||||
kind: Int?,
|
||||
relay: String?,
|
||||
vararg relays: String?,
|
||||
): String =
|
||||
TlvBuilder()
|
||||
.apply {
|
||||
addHex(TlvTypes.SPECIAL, idHex)
|
||||
addStringIfNotNull(TlvTypes.RELAY, relay)
|
||||
relays.forEach {
|
||||
addStringIfNotNull(TlvTypes.RELAY, it)
|
||||
}
|
||||
addHexIfNotNull(TlvTypes.AUTHOR, author)
|
||||
addIntIfNotNull(TlvTypes.KIND, kind)
|
||||
}.build()
|
||||
|
||||
@@ -54,7 +54,7 @@ class LongTextNoteEvent(
|
||||
|
||||
override fun address() = Address(kind, pubKey, dTag())
|
||||
|
||||
override fun addressTag() = ATag.assembleATagId(kind, pubKey, dTag())
|
||||
override fun addressTag() = Address.assemble(kind, pubKey, dTag())
|
||||
|
||||
fun topics() = hashtags()
|
||||
|
||||
|
||||
+5
-3
@@ -28,7 +28,8 @@ import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventUpdate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedAddresses
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedATags
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.pack.EmojiPackEvent
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@@ -42,13 +43,14 @@ class EmojiPackSelectionEvent(
|
||||
content: String,
|
||||
sig: HexKey,
|
||||
) : BaseReplaceableEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
fun emojiPacks() = taggedAddresses()
|
||||
fun emojiPacks() = taggedATags()
|
||||
|
||||
companion object {
|
||||
const val KIND = 10030
|
||||
const val ALT_DESCRIPTION = "Emoji selection"
|
||||
const val FIXED_D_TAG = ""
|
||||
|
||||
fun createAddressATag(pubKey: HexKey) = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
fun createAddress(pubKey: HexKey) = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey) = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ class GitIssueEvent(
|
||||
content: String,
|
||||
sig: HexKey,
|
||||
) : BaseThreadedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
fun repositoryHex() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
fun repositoryHex() = tags.firstNotNullOfOrNull(ATag::parseAddressId)
|
||||
|
||||
fun repositoryAddress() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
|
||||
fun repository() = tags.firstNotNullOfOrNull(ATag::parse)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -43,6 +44,15 @@ class GitPatchEvent(
|
||||
|
||||
private fun repositoryHex() = innerRepository()?.getOrNull(1)
|
||||
|
||||
fun repositoryAddress() =
|
||||
innerRepository()?.let {
|
||||
if (it.size > 1) {
|
||||
Address.parse(it[1])
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun repository() =
|
||||
innerRepository()?.let {
|
||||
if (it.size > 1) {
|
||||
|
||||
@@ -44,7 +44,7 @@ class GitReplyEvent(
|
||||
content: String,
|
||||
sig: HexKey,
|
||||
) : BaseThreadedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
fun repositoryHex() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
fun repositoryHex() = tags.firstNotNullOfOrNull(ATag::parseAddressId)
|
||||
|
||||
fun repository() = tags.firstNotNullOfOrNull(ATag::parse)
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -50,6 +51,8 @@ class SearchRelayListEvent(
|
||||
companion object {
|
||||
const val KIND = 10007
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.isTagged
|
||||
import com.vitorpamplona.quartz.nip01Core.jackson.EventMapper
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.geohash.geohashes
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUserIds
|
||||
@@ -113,9 +114,14 @@ abstract class GeneralListEvent(
|
||||
onReady: (List<String>) -> Unit,
|
||||
) = privateTags(signer) { onReady(filterEvents(it)) }
|
||||
|
||||
fun privateTaggedAddresses(
|
||||
fun privateATags(
|
||||
signer: NostrSigner,
|
||||
onReady: (List<ATag>) -> Unit,
|
||||
) = privateTags(signer) { onReady(filterATags(it)) }
|
||||
|
||||
fun privateAddress(
|
||||
signer: NostrSigner,
|
||||
onReady: (List<Address>) -> Unit,
|
||||
) = privateTags(signer) { onReady(filterAddresses(it)) }
|
||||
|
||||
fun filterUsers(tags: Array<Array<String>>): List<String> = tags.filter { it.size > 1 && it[0] == "p" }.map { it[1] }
|
||||
@@ -126,15 +132,9 @@ abstract class GeneralListEvent(
|
||||
|
||||
fun filterEvents(tags: Array<Array<String>>): List<String> = tags.filter { it.size > 1 && it[0] == "e" }.map { it[1] }
|
||||
|
||||
fun filterAddresses(tags: Array<Array<String>>): List<ATag> =
|
||||
tags
|
||||
.filter { it.firstOrNull() == "a" }
|
||||
.mapNotNull {
|
||||
val aTagValue = it.getOrNull(1)
|
||||
val relay = it.getOrNull(2)
|
||||
fun filterATags(tags: Array<Array<String>>): List<ATag> = tags.mapNotNull(ATag::parse)
|
||||
|
||||
if (aTagValue != null) ATag.parse(aTagValue, relay) else null
|
||||
}
|
||||
fun filterAddresses(tags: Array<Array<String>>): List<Address> = tags.mapNotNull(ATag::parseAddress)
|
||||
|
||||
companion object {
|
||||
fun createPrivateTags(
|
||||
|
||||
@@ -22,8 +22,8 @@ package com.vitorpamplona.quartz.nip51Lists
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent.Companion.FIXED_D_TAG
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
@@ -77,8 +77,11 @@ class MuteListEvent(
|
||||
|
||||
companion object {
|
||||
const val KIND = 10000
|
||||
const val FIXED_D_TAG = ""
|
||||
const val ALT = "Mute List"
|
||||
|
||||
fun createAddress(pubKey: HexKey) = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun blockListFor(pubKeyHex: HexKey): String = "10000:$pubKeyHex:"
|
||||
|
||||
fun createListWithTag(
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip51Lists
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
import com.vitorpamplona.quartz.utils.bytesUsedInMemory
|
||||
@@ -127,6 +128,8 @@ class PeopleListEvent(
|
||||
const val BLOCK_LIST_D_TAG = "mute"
|
||||
const val ALT = "List of people"
|
||||
|
||||
fun createBlockAddress(pubKey: HexKey) = Address(KIND, pubKey, BLOCK_LIST_D_TAG)
|
||||
|
||||
fun blockListFor(pubKeyHex: HexKey): String = "30000:$pubKeyHex:$BLOCK_LIST_D_TAG"
|
||||
|
||||
fun createListWithTag(
|
||||
|
||||
+3
-1
@@ -39,10 +39,12 @@ class LiveActivitiesChatMessageEvent(
|
||||
content: String,
|
||||
sig: HexKey,
|
||||
) : BaseThreadedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||
private fun activityHex() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
private fun activityHex() = tags.firstNotNullOfOrNull(ATag::parseAddressId)
|
||||
|
||||
fun activity() = tags.firstNotNullOfOrNull(ATag::parse)
|
||||
|
||||
fun activityAddress() = tags.firstNotNullOfOrNull(ATag::parseAddress)
|
||||
|
||||
override fun markedReplyTos() = super.markedReplyTos().minus(activityHex() ?: "")
|
||||
|
||||
override fun unmarkedReplyTos() = super.markedReplyTos().minus(activityHex() ?: "")
|
||||
|
||||
@@ -48,7 +48,7 @@ class WikiNoteEvent(
|
||||
|
||||
override fun address() = Address(kind, pubKey, dTag())
|
||||
|
||||
override fun addressTag() = ATag.assembleATagId(kind, pubKey, dTag())
|
||||
override fun addressTag() = Address.assemble(kind, pubKey, dTag())
|
||||
|
||||
fun topics() = hashtags()
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedAddresses
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents
|
||||
|
||||
@@ -45,6 +46,8 @@ class BadgeProfilesEvent(
|
||||
private const val STANDARD_D_TAG = "profile_badges"
|
||||
private const val ALT = "List of accepted badges by the author"
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, STANDARD_D_TAG)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): ATag = ATag(KIND, pubKey, STANDARD_D_TAG, null)
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -85,6 +86,8 @@ class AdvertisedRelayListEvent(
|
||||
const val KIND = 10002
|
||||
const val ALT = "Relay list to discover the user's content"
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
+6
-1
@@ -27,6 +27,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedATags
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.taggedAddresses
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.kinds.kind
|
||||
@@ -54,10 +55,14 @@ class CommunityPostApprovalEvent(
|
||||
null
|
||||
}
|
||||
|
||||
fun communities() = taggedAddresses().filter { it.kind == CommunityDefinitionEvent.KIND }
|
||||
fun communities() = taggedATags().filter { it.kind == CommunityDefinitionEvent.KIND }
|
||||
|
||||
fun communityAddresses() = taggedAddresses().filter { it.kind == CommunityDefinitionEvent.KIND }
|
||||
|
||||
fun approvedEvents() = taggedEvents()
|
||||
|
||||
fun approvedATags() = taggedATags().filter { it.kind != CommunityDefinitionEvent.KIND }
|
||||
|
||||
fun approvedAddresses() = taggedAddresses().filter { it.kind != CommunityDefinitionEvent.KIND }
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.BaseAddressableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.AltTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
|
||||
@@ -39,6 +40,11 @@ class AppSpecificDataEvent(
|
||||
const val KIND = 30078
|
||||
const val ALT = "Arbitrary app data"
|
||||
|
||||
fun createAddress(
|
||||
pubKey: HexKey,
|
||||
dTag: String,
|
||||
) = Address(KIND, pubKey, dTag)
|
||||
|
||||
fun createTag(
|
||||
pubkey: HexKey,
|
||||
dTag: String,
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.nip84Highlights
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.nip01Core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.firstTaggedATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.firstTaggedAddress
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.firstTaggedEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.firstTaggedUser
|
||||
@@ -49,7 +50,9 @@ class HighlightEvent(
|
||||
|
||||
fun context() = tags.firstNotNullOfOrNull(ContextTag::parse)
|
||||
|
||||
fun inPost() = firstTaggedAddress()
|
||||
fun inPost() = firstTaggedATag()
|
||||
|
||||
fun inPostAddress() = firstTaggedAddress()
|
||||
|
||||
fun inPostVersion() = firstTaggedEvent()
|
||||
|
||||
|
||||
+3
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.core.BaseReplaceableEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArrayBuilder
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip96FileStorage.config.tags.ServerTag
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@@ -45,6 +46,8 @@ class FileServersEvent(
|
||||
const val KIND = 10096
|
||||
const val ALT_DESCRIPTOR = "File servers used by the author"
|
||||
|
||||
fun createAddress(pubKey: HexKey): Address = Address(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
fun createAddressATag(pubKey: HexKey): ATag = ATag(KIND, pubKey, FIXED_D_TAG, null)
|
||||
|
||||
fun createAddressTag(pubKey: HexKey): String = ATag.assembleATagId(KIND, pubKey, FIXED_D_TAG)
|
||||
|
||||
Reference in New Issue
Block a user