Adds two additional helper methods to ATags and Classifieds.
This commit is contained in:
@@ -69,6 +69,15 @@ data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val rela
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun parseAtagUnckecked(atag: String): ATag? {
|
||||||
|
return try {
|
||||||
|
val parts = atag.split(":")
|
||||||
|
ATag(parts[0].toInt(), parts[1], parts[2], null)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun parseNAddr(naddr: String): ATag? {
|
fun parseNAddr(naddr: String): ATag? {
|
||||||
try {
|
try {
|
||||||
val key = naddr.removePrefix("nostr:")
|
val key = naddr.removePrefix("nostr:")
|
||||||
|
|||||||
@@ -52,6 +52,26 @@ class ClassifiedsEvent(
|
|||||||
|
|
||||||
fun location() = tags.firstOrNull { it.size > 1 && it[0] == "location" }?.get(1)
|
fun location() = tags.firstOrNull { it.size > 1 && it[0] == "location" }?.get(1)
|
||||||
|
|
||||||
|
fun isWellFormed(): Boolean {
|
||||||
|
var hasImage = false
|
||||||
|
var hasTitle = false
|
||||||
|
var hasPrice = false
|
||||||
|
|
||||||
|
tags.forEach {
|
||||||
|
if (it.size > 1) {
|
||||||
|
if (it[0] == "image") {
|
||||||
|
hasImage = true
|
||||||
|
} else if (it[0] == "title") {
|
||||||
|
hasTitle = true
|
||||||
|
} else if (it[0] == "price") {
|
||||||
|
hasPrice = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasImage && hasPrice && hasTitle
|
||||||
|
}
|
||||||
|
|
||||||
fun publishedAt() =
|
fun publishedAt() =
|
||||||
try {
|
try {
|
||||||
tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1)?.toLongOrNull()
|
tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1)?.toLongOrNull()
|
||||||
|
|||||||
Reference in New Issue
Block a user