mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:57:29 +01:00
Visual support for Kind1 forks.
This commit is contained in:
@@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.events
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.vitorpamplona.quartz.encoders.ATag
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.encoders.Nip19Bech32
|
||||
import com.vitorpamplona.quartz.encoders.Nip19Bech32.nip19regex
|
||||
@@ -42,6 +43,18 @@ open class BaseTextNoteEvent(
|
||||
) : Event(id, pubKey, createdAt, kind, tags, content, sig) {
|
||||
fun mentions() = taggedUsers()
|
||||
|
||||
fun isAFork() = tags.any { it.size > 3 && (it[0] == "a" || it[0] == "e") && it[3] == "fork" }
|
||||
|
||||
fun 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)
|
||||
}
|
||||
|
||||
fun forkFromVersion() = tags.firstOrNull { it.size > 3 && it[0] == "e" && it[3] == "fork" }?.get(1)
|
||||
|
||||
open fun replyTos(): List<HexKey> {
|
||||
val oldStylePositional = tags.filter { it.size > 1 && it.size <= 3 && it[0] == "e" }.map { it[1] }
|
||||
val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "reply" }?.get(1)
|
||||
|
||||
@@ -57,6 +57,7 @@ class TextNoteEvent(
|
||||
directMentions: Set<HexKey> = emptySet(),
|
||||
geohash: String? = null,
|
||||
nip94attachments: List<FileHeaderEvent>? = null,
|
||||
forkedFrom: Event? = null,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
onReady: (TextNoteEvent) -> Unit,
|
||||
@@ -69,6 +70,7 @@ class TextNoteEvent(
|
||||
root = root,
|
||||
replyingTo = replyingTo,
|
||||
directMentions = directMentions,
|
||||
forkedFrom = forkedFrom?.id,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -93,6 +95,7 @@ class TextNoteEvent(
|
||||
root = root,
|
||||
replyingTo = replyingTo,
|
||||
directMentions = directMentions,
|
||||
forkedFrom = (forkedFrom as? AddressableEvent)?.address()?.toTag(),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -136,6 +139,7 @@ class TextNoteEvent(
|
||||
root: String?,
|
||||
replyingTo: String?,
|
||||
directMentions: Set<HexKey>,
|
||||
forkedFrom: String?,
|
||||
) = sortedWith { o1, o2 ->
|
||||
when {
|
||||
o1 == o2 -> 0
|
||||
@@ -150,6 +154,7 @@ class TextNoteEvent(
|
||||
when (it) {
|
||||
root -> arrayOf(tagName, it, "", "root")
|
||||
replyingTo -> arrayOf(tagName, it, "", "reply")
|
||||
forkedFrom -> arrayOf(tagName, it, "", "fork")
|
||||
in directMentions -> arrayOf(tagName, it, "", "mention")
|
||||
else -> arrayOf(tagName, it)
|
||||
}
|
||||
|
||||
@@ -41,16 +41,6 @@ class WikiNoteEvent(
|
||||
|
||||
fun topics() = hashtags()
|
||||
|
||||
fun 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)
|
||||
}
|
||||
|
||||
fun forkFromVersion() = tags.firstOrNull { it.size > 3 && it[0] == "e" && it[3] == "fork" }?.get(1)
|
||||
|
||||
fun title() = tags.firstOrNull { it.size > 1 && it[0] == "title" }?.get(1)
|
||||
|
||||
fun summary() = tags.firstOrNull { it.size > 1 && it[0] == "summary" }?.get(1)
|
||||
|
||||
Reference in New Issue
Block a user