Merge branch 'main' into main
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? {
|
||||
try {
|
||||
val key = naddr.removePrefix("nostr:")
|
||||
|
||||
@@ -52,6 +52,26 @@ class ClassifiedsEvent(
|
||||
|
||||
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() =
|
||||
try {
|
||||
tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1)?.toLongOrNull()
|
||||
|
||||
@@ -58,6 +58,12 @@ class FileHeaderEvent(
|
||||
|
||||
fun hasUrl() = tags.any { it.size > 1 && it[0] == URL }
|
||||
|
||||
fun isImageOrVideo(): Boolean {
|
||||
val mimeType = mimeType() ?: return false
|
||||
|
||||
return mimeType.startsWith("image/") || mimeType.startsWith("video/")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 1063
|
||||
const val ALT_DESCRIPTION = "Verifiable file url"
|
||||
|
||||
@@ -54,6 +54,12 @@ class FileStorageHeaderEvent(
|
||||
|
||||
fun blurhash() = tags.firstOrNull { it.size > 1 && it[0] == BLUR_HASH }?.get(1)
|
||||
|
||||
fun isImageOrVideo(): Boolean {
|
||||
val mimeType = mimeType() ?: return false
|
||||
|
||||
return mimeType.startsWith("image/") || mimeType.startsWith("video/")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 1065
|
||||
const val ALT_DESCRIPTION = "Descriptors for a binary file"
|
||||
|
||||
Reference in New Issue
Block a user