Skip to content

Commit

Permalink
Fully Deprecates note1, removing the last usages of the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Nov 19, 2024
1 parent 72f3177 commit 2488487
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.vitorpamplona.ammolite.relays.BundledUpdate
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.Hex
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.toNote
import com.vitorpamplona.quartz.encoders.toNEvent
import com.vitorpamplona.quartz.events.ChannelCreateEvent
import com.vitorpamplona.quartz.events.LiveActivitiesEvent
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -107,7 +107,7 @@ abstract class Channel(

open fun id() = Hex.decode(idHex)

open fun idNote() = id().toNote()
open fun idNote() = id().toNEvent()

open fun idDisplayNote() = idNote().toShortenHex()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.vitorpamplona.quartz.encoders.Hex
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.LnInvoiceUtil
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.toNote
import com.vitorpamplona.quartz.events.AddressableEvent
import com.vitorpamplona.quartz.events.BaseTextNoteEvent
import com.vitorpamplona.quartz.events.ChannelCreateEvent
Expand Down Expand Up @@ -80,9 +79,9 @@ import kotlin.coroutines.resume
class AddressableNote(
val address: ATag,
) : Note(address.toTag()) {
override fun idNote() = address.toNAddr()
override fun idNote() = address.toNAddr(relayHintUrl())

override fun toNEvent() = address.toNAddr()
override fun toNEvent() = address.toNAddr(relayHintUrl())

override fun idDisplayNote() = idNote().toShortenHex()

Expand Down Expand Up @@ -146,7 +145,7 @@ open class Note(

fun id() = Hex.decode(idHex)

open fun idNote() = id().toNote()
open fun idNote() = toNEvent()

open fun toNEvent(): String {
val myEvent = event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ fun ClickableNoteTag(
accountViewModel: AccountViewModel,
nav: INav,
) {
val route = routeFor(baseNote, accountViewModel.userProfile())

ClickableText(
text = AnnotatedString("@${baseNote.idNote().toShortenHex()}"),
onClick = { nav.nav("Note/${baseNote.idHex}") },
onClick = { routeFor(baseNote, accountViewModel.userProfile())?.let { nav.nav(it) } },
style = LocalTextStyle.current.copy(color = MaterialTheme.colorScheme.primary),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ data class ATag(

fun toQTagArray() = removeTrailingNullsAndEmptyOthers("q", toTag(), relay)

fun toNAddr(): String =
fun toNAddr(overrideRelay: String? = relay): String =
TlvBuilder()
.apply {
addString(Nip19Bech32.TlvTypes.SPECIAL, dTag)
addStringIfNotNull(Nip19Bech32.TlvTypes.RELAY, relay)
addStringIfNotNull(Nip19Bech32.TlvTypes.RELAY, overrideRelay)
addHex(Nip19Bech32.TlvTypes.AUTHOR, pubKeyHex)
addInt(Nip19Bech32.TlvTypes.KIND, kind)
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ data class ETag(

fun toNEvent(): String = Nip19Bech32.createNEvent(eventId, authorPubKeyHex, null, relay)

fun toNote(): String = Nip19Bech32.createNote(eventId)

fun toETagArray() = removeTrailingNullsAndEmptyOthers("e", eventId, relay, authorPubKeyHex)

fun toQTagArray() = removeTrailingNullsAndEmptyOthers("q", eventId, relay, authorPubKeyHex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ object Nip19Bech32 {
}.build()
.toNEvent()

@Deprecated("Use nevent instead")
fun createNote(eventId: HexKey): String = eventId.hexToByteArray().toNote()

fun createNPub(authorPubKeyHex: HexKey): String = authorPubKeyHex.hexToByteArray().toNpub()
Expand Down Expand Up @@ -303,6 +304,7 @@ fun ByteArray.toNsec() = Bech32.encodeBytes(hrp = "nsec", this, Bech32.Encoding.

fun ByteArray.toNpub() = Bech32.encodeBytes(hrp = "npub", this, Bech32.Encoding.Bech32)

@Deprecated("Prefer nevent1 instead")
fun ByteArray.toNote() = Bech32.encodeBytes(hrp = "note", this, Bech32.Encoding.Bech32)

fun ByteArray.toNEvent() = Bech32.encodeBytes(hrp = "nevent", this, Bech32.Encoding.Bech32)
Expand Down

0 comments on commit 2488487

Please sign in to comment.