Fixes showing blog posts in the future

This commit is contained in:
Vitor Pamplona
2025-09-12 12:39:12 -04:00
parent bc10d7184f
commit ac48705980
5 changed files with 60 additions and 8 deletions

View File

@@ -132,7 +132,18 @@ class LongTextNoteEvent(
fun summary() = tags.firstNotNullOfOrNull(SummaryTag::parse)
override fun publishedAt() = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
override fun publishedAt(): Long? {
val publishedAt = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
if (publishedAt == null) return null
// removes posts in the future.
return if (publishedAt <= createdAt) {
publishedAt
} else {
null
}
}
companion object {
const val KIND = 30023

View File

@@ -46,6 +46,8 @@ import com.vitorpamplona.quartz.nip19Bech32.eventHints
import com.vitorpamplona.quartz.nip19Bech32.eventIds
import com.vitorpamplona.quartz.nip19Bech32.pubKeyHints
import com.vitorpamplona.quartz.nip19Bech32.pubKeys
import com.vitorpamplona.quartz.nip23LongContent.tags.PublishedAtTag
import com.vitorpamplona.quartz.nip23LongContent.tags.PublishedAtTag.Companion.parse
import com.vitorpamplona.quartz.nip31Alts.AltTag
import com.vitorpamplona.quartz.nip50Search.SearchableEvent
import com.vitorpamplona.quartz.utils.TimeUtils
@@ -129,12 +131,18 @@ class WikiNoteEvent(
fun image() = tags.firstOrNull { it.size > 1 && it[0] == "image" }?.get(1)
override fun publishedAt() =
try {
tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1)?.toLongOrNull()
} catch (_: Exception) {
override fun publishedAt(): Long? {
val publishedAt = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
if (publishedAt == null) return null
// removes posts in the future.
return if (publishedAt <= createdAt) {
publishedAt
} else {
null
}
}
companion object {
const val KIND = 30818

View File

@@ -53,7 +53,18 @@ abstract class ReplaceableVideoEvent(
override fun title() = tags.firstNotNullOfOrNull(TitleTag::parse)
override fun publishedAt() = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
override fun publishedAt(): Long? {
val publishedAt = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
if (publishedAt == null) return null
// removes posts in the future.
return if (publishedAt <= createdAt) {
publishedAt
} else {
null
}
}
override fun duration() = tags.firstNotNullOfOrNull(DurationTag::parse)

View File

@@ -79,7 +79,18 @@ class AppDefinitionEvent(
fun includeKind(kind: Int) = tags.isTaggedKind(kind)
override fun publishedAt() = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
override fun publishedAt(): Long? {
val publishedAt = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
if (publishedAt == null) return null
// removes posts in the future.
return if (publishedAt <= createdAt) {
publishedAt
} else {
null
}
}
companion object {
const val KIND = 31990

View File

@@ -70,7 +70,18 @@ class ClassifiedsEvent(
fun location() = tags.firstNotNullOfOrNull(LocationTag::parse)
override fun publishedAt() = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
override fun publishedAt(): Long? {
val publishedAt = tags.firstNotNullOfOrNull(PublishedAtTag::parse)
if (publishedAt == null) return null
// removes posts in the future.
return if (publishedAt <= createdAt) {
publishedAt
} else {
null
}
}
fun categories() = tags.hashtags()