mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-04 05:29:31 +02:00
Fixes missing reply order when the direct reply is also included as a quote.
This commit is contained in:
parent
d0b0f441b1
commit
cb538bc6a3
@ -73,7 +73,7 @@ dependencies {
|
|||||||
// Parses URLs from Text:
|
// Parses URLs from Text:
|
||||||
api libs.url.detector
|
api libs.url.detector
|
||||||
|
|
||||||
// Parses URLs from Text:
|
// Normalizes URLs
|
||||||
api libs.rfc3986.normalizer
|
api libs.rfc3986.normalizer
|
||||||
|
|
||||||
testImplementation libs.junit
|
testImplementation libs.junit
|
||||||
|
@ -57,20 +57,14 @@ open class BaseTextNoteEvent(
|
|||||||
|
|
||||||
fun isForkFromAddressWithPubkey(authorHex: HexKey) = tags.any { it.size > 3 && it[0] == "a" && it[3] == "fork" && it[1].contains(authorHex) }
|
fun isForkFromAddressWithPubkey(authorHex: HexKey) = tags.any { it.size > 3 && it[0] == "a" && it[3] == "fork" && it[1].contains(authorHex) }
|
||||||
|
|
||||||
open fun replyTos(): List<HexKey> {
|
open fun markedReplyTos(): List<HexKey> {
|
||||||
val oldStylePositional = tags.filter { it.size > 1 && it.size <= 3 && it[0] == "e" }.map { it[1] }
|
|
||||||
val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "reply" }?.get(1)
|
val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "reply" }?.get(1)
|
||||||
val newStyleRoot = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "root" }?.get(1)
|
val newStyleRoot = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "root" }?.get(1)
|
||||||
|
return listOfNotNull(newStyleReply, newStyleRoot)
|
||||||
val newStyleReplyTos = listOfNotNull(newStyleReply, newStyleRoot)
|
|
||||||
|
|
||||||
return if (newStyleReplyTos.isNotEmpty()) {
|
|
||||||
newStyleReplyTos
|
|
||||||
} else {
|
|
||||||
oldStylePositional
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun unMarkedReplyTos(): List<HexKey> = tags.filter { it.size > 1 && it.size <= 3 && it[0] == "e" }.map { it[1] }
|
||||||
|
|
||||||
open fun replyingTo(): HexKey? {
|
open fun replyingTo(): HexKey? {
|
||||||
val oldStylePositional = tags.lastOrNull { it.size > 1 && it.size <= 3 && it[0] == "e" }?.get(1)
|
val oldStylePositional = tags.lastOrNull { it.size > 1 && it.size <= 3 && it[0] == "e" }?.get(1)
|
||||||
val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "reply" }?.get(1)
|
val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "e" && it[3] == "reply" }?.get(1)
|
||||||
@ -190,21 +184,51 @@ open class BaseTextNoteEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tagsWithoutCitations(): List<String> {
|
fun tagsWithoutCitations(): List<String> {
|
||||||
val repliesTo = replyTos()
|
val certainRepliesTo = markedReplyTos()
|
||||||
|
val uncertainRepliesTo = unMarkedReplyTos()
|
||||||
|
|
||||||
val tagAddresses =
|
val tagAddresses =
|
||||||
taggedAddresses()
|
taggedAddresses()
|
||||||
.filter {
|
.filter {
|
||||||
it.kind != CommunityDefinitionEvent.KIND && (kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
|
it.kind != CommunityDefinitionEvent.KIND && (kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
|
||||||
// removes forks from itself.
|
// removes forks from itself.
|
||||||
}.map { it.toTag() }
|
}.map { it.toTag() }
|
||||||
if (repliesTo.isEmpty() && tagAddresses.isEmpty()) return emptyList()
|
|
||||||
|
if (certainRepliesTo.isEmpty() && uncertainRepliesTo.isEmpty() && tagAddresses.isEmpty()) return emptyList()
|
||||||
|
|
||||||
val citations = findCitations()
|
val citations = findCitations()
|
||||||
|
|
||||||
|
if (id == "d349431390b141e7ea010ebabc288abbfdf8a479cf248f7e1cb2cfa4497ad278") {
|
||||||
|
certainRepliesTo.forEach {
|
||||||
|
println("AABBCC Replies $it")
|
||||||
|
}
|
||||||
|
|
||||||
|
uncertainRepliesTo.forEach {
|
||||||
|
println("AABBCC Replies $it")
|
||||||
|
}
|
||||||
|
|
||||||
|
tagAddresses.forEach {
|
||||||
|
println("AABBCC Addresses $it")
|
||||||
|
}
|
||||||
|
|
||||||
|
citations.forEach {
|
||||||
|
println("AABBCC Citations $it")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return if (citations.isEmpty()) {
|
return if (citations.isEmpty()) {
|
||||||
repliesTo + tagAddresses
|
if (certainRepliesTo.isNotEmpty()) {
|
||||||
|
certainRepliesTo + tagAddresses
|
||||||
|
} else {
|
||||||
|
uncertainRepliesTo + tagAddresses
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
repliesTo.filter { it !in citations }
|
if (certainRepliesTo.isNotEmpty()) {
|
||||||
|
certainRepliesTo + tagAddresses
|
||||||
|
} else {
|
||||||
|
// mix bag between `e` for replies and `e` for citations
|
||||||
|
uncertainRepliesTo.filter { it !in citations }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,13 @@ class ChannelMessageEvent(
|
|||||||
tags.firstOrNull { it.size > 3 && it[0] == "e" && it[3] == "root" }?.get(1)
|
tags.firstOrNull { it.size > 3 && it[0] == "e" && it[3] == "root" }?.get(1)
|
||||||
?: tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
|
?: tags.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)
|
||||||
|
|
||||||
override fun replyTos() =
|
override fun markedReplyTos() =
|
||||||
tags
|
tags
|
||||||
.filter { it.firstOrNull() == "e" && it.getOrNull(1) != channel() }
|
.filter { it.firstOrNull() == "e" && it.getOrNull(1) != channel() }
|
||||||
.mapNotNull { it.getOrNull(1) }
|
.mapNotNull { it.getOrNull(1) }
|
||||||
|
|
||||||
|
override fun unMarkedReplyTos() = emptyList<String>()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KIND = 42
|
const val KIND = 42
|
||||||
const val ALT = "Public chat message"
|
const val ALT = "Public chat message"
|
||||||
|
@ -65,7 +65,9 @@ class CommentEvent(
|
|||||||
|
|
||||||
override fun isTaggedGeoHashes(hashtags: Set<String>) = geohashes().any { it in hashtags }
|
override fun isTaggedGeoHashes(hashtags: Set<String>) = geohashes().any { it in hashtags }
|
||||||
|
|
||||||
override fun replyTos(): List<HexKey> = tags.filter { it.size > 1 && it[0] == "e" }.map { it[1] } + tags.filter { it.size > 1 && it[0] == "E" }.map { it[1] }
|
override fun markedReplyTos(): List<HexKey> = tags.filter { it.size > 1 && it[0] == "e" }.map { it[1] } + tags.filter { it.size > 1 && it[0] == "E" }.map { it[1] }
|
||||||
|
|
||||||
|
override fun unMarkedReplyTos() = emptyList<String>()
|
||||||
|
|
||||||
override fun replyingTo(): HexKey? =
|
override fun replyingTo(): HexKey? =
|
||||||
tags.lastOrNull { it.size > 1 && it[0] == "e" }?.get(1)
|
tags.lastOrNull { it.size > 1 && it[0] == "e" }?.get(1)
|
||||||
|
@ -54,7 +54,9 @@ class LiveActivitiesChatMessageEvent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replyTos() = taggedEvents().minus(activityHex() ?: "")
|
override fun markedReplyTos() = super.markedReplyTos().minus(activityHex() ?: "")
|
||||||
|
|
||||||
|
override fun unMarkedReplyTos() = super.markedReplyTos().minus(activityHex() ?: "")
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KIND = 1311
|
const val KIND = 1311
|
||||||
|
Loading…
x
Reference in New Issue
Block a user