1. Adds Classified creation from Amethyst.
2. Adds relay information for Replaceable events.
This commit is contained in:
@@ -19,6 +19,7 @@ class ClassifiedsEvent(
|
||||
) : BaseAddressableEvent(id, pubKey, createdAt, kind, tags, content, sig) {
|
||||
fun title() = tags.firstOrNull { it.size > 1 && it[0] == "title" }?.get(1)
|
||||
fun image() = tags.firstOrNull { it.size > 1 && it[0] == "image" }?.get(1)
|
||||
fun condition() = tags.firstOrNull { it.size > 1 && it[0] == "condition" }?.get(1)
|
||||
fun images() = tags.filter { it.size > 1 && it[0] == "image" }.map { it[1] }
|
||||
fun summary() = tags.firstOrNull { it.size > 1 && it[0] == "summary" }?.get(1)
|
||||
fun price() = tags.firstOrNull { it.size > 1 && it[0] == "price" }?.let {
|
||||
@@ -32,23 +33,65 @@ class ClassifiedsEvent(
|
||||
null
|
||||
}
|
||||
|
||||
enum class CONDITION(val value: String){
|
||||
NEW("new"),
|
||||
USED_LIKE_NEW("like new"),
|
||||
USED_GOOD("good"),
|
||||
USED_FAIR("fair"),
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val kind = 30402
|
||||
private val imageExtensions = listOf("png", "jpg", "gif", "bmp", "jpeg", "webp", "svg")
|
||||
|
||||
fun create(
|
||||
dTag: String,
|
||||
title: String?,
|
||||
image: String?,
|
||||
summary: String?,
|
||||
message: String,
|
||||
price: Price?,
|
||||
location: String?,
|
||||
publishedAt: Long?,
|
||||
category: String?,
|
||||
condition: ClassifiedsEvent.CONDITION?,
|
||||
publishedAt: Long? = TimeUtils.now(),
|
||||
replyTos: List<String>?,
|
||||
addresses: List<ATag>?,
|
||||
mentions: List<String>?,
|
||||
directMentions: Set<HexKey>,
|
||||
zapReceiver: List<ZapSplitSetup>? = null,
|
||||
markAsSensitive: Boolean,
|
||||
zapRaiserAmount: Long?,
|
||||
geohash: String? = null,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
onReady: (ClassifiedsEvent) -> Unit
|
||||
) {
|
||||
val tags = mutableListOf<Array<String>>()
|
||||
|
||||
replyTos?.forEach {
|
||||
if (it in directMentions) {
|
||||
tags.add(arrayOf("e", it, "", "mention"))
|
||||
} else {
|
||||
tags.add(arrayOf("e", it))
|
||||
}
|
||||
}
|
||||
mentions?.forEach {
|
||||
if (it in directMentions) {
|
||||
tags.add(arrayOf("p", it, "", "mention"))
|
||||
} else {
|
||||
tags.add(arrayOf("p", it))
|
||||
}
|
||||
}
|
||||
addresses?.forEach {
|
||||
val aTag = it.toTag()
|
||||
if (aTag in directMentions) {
|
||||
tags.add(arrayOf("a", aTag, "", "mention"))
|
||||
} else {
|
||||
tags.add(arrayOf("a", aTag))
|
||||
}
|
||||
}
|
||||
|
||||
tags.add(arrayOf("d", dTag))
|
||||
title?.let { tags.add(arrayOf("title", it)) }
|
||||
image?.let { tags.add(arrayOf("image", it)) }
|
||||
@@ -62,11 +105,36 @@ class ClassifiedsEvent(
|
||||
tags.add(arrayOf("price", it.amount))
|
||||
}
|
||||
}
|
||||
category?.let { tags.add(arrayOf("t", it)) }
|
||||
location?.let { tags.add(arrayOf("location", it)) }
|
||||
publishedAt?.let { tags.add(arrayOf("publishedAt", it.toString())) }
|
||||
title?.let { tags.add(arrayOf("title", it)) }
|
||||
condition?.let { tags.add(arrayOf("condition", it.value)) }
|
||||
|
||||
signer.sign(createdAt, kind, tags.toTypedArray(), "", onReady)
|
||||
findHashtags(message).forEach {
|
||||
tags.add(arrayOf("t", it))
|
||||
tags.add(arrayOf("t", it.lowercase()))
|
||||
}
|
||||
zapReceiver?.forEach {
|
||||
tags.add(arrayOf("zap", it.lnAddressOrPubKeyHex, it.relay ?: "", it.weight.toString()))
|
||||
}
|
||||
findURLs(message).forEach {
|
||||
val removedParamsFromUrl = it.split("?")[0].lowercase()
|
||||
if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||
tags.add(arrayOf("image", it))
|
||||
}
|
||||
tags.add(arrayOf("r", it))
|
||||
}
|
||||
if (markAsSensitive) {
|
||||
tags.add(arrayOf("content-warning", ""))
|
||||
}
|
||||
zapRaiserAmount?.let {
|
||||
tags.add(arrayOf("zapraiser", "$it"))
|
||||
}
|
||||
geohash?.let {
|
||||
tags.addAll(geohashMipMap(it))
|
||||
}
|
||||
|
||||
signer.sign(createdAt, kind, tags.toTypedArray(), message, onReady)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user