- Separates new Product Screen from the generic new Post screen.
- Adds New product button on the Marketplace tab - Adds imeta tags for images and urls inside the content of the Classifieds. - Shows multiple images on the post and thread view. - Removes the option for NIP-95 images on Classifieds. - Creates a new route for new products - Adjusts quarts to process images with iMeta tags
This commit is contained in:
@@ -25,7 +25,7 @@ import com.vitorpamplona.quartz.utils.ensure
|
||||
|
||||
class IMetaTag(
|
||||
val url: String,
|
||||
val properties: Map<String, List<String>>,
|
||||
val properties: Map<String, List<String>> = emptyMap(),
|
||||
) {
|
||||
fun toTagArray() =
|
||||
arrayOf(TAG_NAME, "$ANCHOR_PROPERTY $url") +
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.vitorpamplona.quartz.nip23LongContent.tags.PublishedAtTag
|
||||
import com.vitorpamplona.quartz.nip23LongContent.tags.SummaryTag
|
||||
import com.vitorpamplona.quartz.nip23LongContent.tags.TitleTag
|
||||
import com.vitorpamplona.quartz.nip31Alts.alt
|
||||
import com.vitorpamplona.quartz.nip92IMeta.imetas
|
||||
import com.vitorpamplona.quartz.nip99Classifieds.tags.ConditionTag
|
||||
import com.vitorpamplona.quartz.nip99Classifieds.tags.LocationTag
|
||||
import com.vitorpamplona.quartz.nip99Classifieds.tags.PriceTag
|
||||
@@ -55,6 +56,8 @@ class ClassifiedsEvent(
|
||||
|
||||
fun condition() = tags.firstNotNullOfOrNull(ConditionTag::parse)
|
||||
|
||||
fun conditionValid() = tags.firstNotNullOfOrNull(ConditionTag::parseCondition)
|
||||
|
||||
fun images() = tags.mapNotNull(ImageTag::parse)
|
||||
|
||||
fun status() = tags.firstNotNullOfOrNull(StatusTag::parse)
|
||||
@@ -71,6 +74,22 @@ class ClassifiedsEvent(
|
||||
|
||||
fun isWellFormed() = tags.containsAllTagNamesWithValues(REQUIRED_FIELDS)
|
||||
|
||||
fun imageMetas(): List<ProductImageMeta> {
|
||||
val images = images()
|
||||
val imetas = imetas()
|
||||
|
||||
val imetaSet = imetas.associate { it.url to it }
|
||||
|
||||
return images.map {
|
||||
val imeta = imetaSet.get(it)
|
||||
if (imeta != null) {
|
||||
ProductImageMeta.parse(imeta)
|
||||
} else {
|
||||
ProductImageMeta(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KIND = 30402
|
||||
const val ALT_DESCRIPTION = "Classifieds listing"
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.nip99Classifieds
|
||||
|
||||
import com.vitorpamplona.quartz.nip68Picture.alt
|
||||
import com.vitorpamplona.quartz.nip68Picture.blurhash
|
||||
import com.vitorpamplona.quartz.nip68Picture.dims
|
||||
import com.vitorpamplona.quartz.nip68Picture.hash
|
||||
import com.vitorpamplona.quartz.nip68Picture.mimeType
|
||||
import com.vitorpamplona.quartz.nip68Picture.size
|
||||
import com.vitorpamplona.quartz.nip92IMeta.IMetaTag
|
||||
import com.vitorpamplona.quartz.nip92IMeta.IMetaTagBuilder
|
||||
import com.vitorpamplona.quartz.nip94FileMetadata.tags.DimensionTag
|
||||
|
||||
data class ProductImageMeta(
|
||||
val url: String,
|
||||
val mimeType: String? = null,
|
||||
val blurhash: String? = null,
|
||||
val dimension: DimensionTag? = null,
|
||||
val alt: String? = null,
|
||||
val hash: String? = null,
|
||||
val size: Int? = null,
|
||||
) {
|
||||
fun toIMeta(): IMetaTag =
|
||||
IMetaTagBuilder(url)
|
||||
.apply {
|
||||
mimeType?.let { mimeType(it) }
|
||||
alt?.let { alt(it) }
|
||||
hash?.let { hash(it) }
|
||||
size?.let { size(it) }
|
||||
dimension?.let { dims(it) }
|
||||
blurhash?.let { blurhash(it) }
|
||||
}.build()
|
||||
|
||||
fun toIMetaArray(): Array<String> = toIMeta().toTagArray()
|
||||
|
||||
companion object {
|
||||
fun parse(iMeta: IMetaTag): ProductImageMeta =
|
||||
ProductImageMeta(
|
||||
iMeta.url,
|
||||
iMeta.mimeType()?.firstOrNull(),
|
||||
iMeta.blurhash()?.firstOrNull(),
|
||||
iMeta.dims()?.firstOrNull()?.let { DimensionTag.parse(it) },
|
||||
iMeta.alt()?.firstOrNull(),
|
||||
iMeta.hash()?.firstOrNull(),
|
||||
iMeta.size()?.firstOrNull()?.toIntOrNull(),
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -36,7 +36,7 @@ fun TagArrayBuilder<ClassifiedsEvent>.summary(summary: String) = addUnique(Summa
|
||||
|
||||
fun TagArrayBuilder<ClassifiedsEvent>.location(location: String) = addUnique(LocationTag.assemble(location))
|
||||
|
||||
fun TagArrayBuilder<ClassifiedsEvent>.image(imageUrl: String) = addUnique(ImageTag.assemble(imageUrl))
|
||||
fun TagArrayBuilder<ClassifiedsEvent>.image(imageUrl: String) = add(ImageTag.assemble(imageUrl))
|
||||
|
||||
fun TagArrayBuilder<ClassifiedsEvent>.images(imageUrls: List<String>) = addAll(imageUrls.map { ImageTag.assemble(it) })
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.vitorpamplona.quartz.utils.ensure
|
||||
|
||||
class ConditionTag {
|
||||
enum class CONDITION(
|
||||
val value: String,
|
||||
val code: String,
|
||||
) {
|
||||
NEW("new"),
|
||||
USED_LIKE_NEW("like new"),
|
||||
@@ -34,6 +34,10 @@ class ConditionTag {
|
||||
;
|
||||
|
||||
fun toTagArray() = assemble(this)
|
||||
|
||||
companion object {
|
||||
fun parse(cond: String) = entries.firstOrNull { it.code == cond }
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -48,6 +52,9 @@ class ConditionTag {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(condition: CONDITION) = arrayOf(TAG_NAME, condition.value)
|
||||
fun parseCondition(tag: Array<String>): CONDITION? = parse(tag)?.let { CONDITION.parse(it) }
|
||||
|
||||
@JvmStatic
|
||||
fun assemble(condition: CONDITION) = arrayOf(TAG_NAME, condition.code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user