mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-01 01:39:26 +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:
|
||||
api libs.url.detector
|
||||
|
||||
// Parses URLs from Text:
|
||||
// Normalizes URLs
|
||||
api libs.rfc3986.normalizer
|
||||
|
||||
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) }
|
||||
|
||||
open fun replyTos(): List<HexKey> {
|
||||
val oldStylePositional = tags.filter { it.size > 1 && it.size <= 3 && it[0] == "e" }.map { it[1] }
|
||||
open fun markedReplyTos(): List<HexKey> {
|
||||
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 newStyleReplyTos = listOfNotNull(newStyleReply, newStyleRoot)
|
||||
|
||||
return if (newStyleReplyTos.isNotEmpty()) {
|
||||
newStyleReplyTos
|
||||
} else {
|
||||
oldStylePositional
|
||||
}
|
||||
return listOfNotNull(newStyleReply, newStyleRoot)
|
||||
}
|
||||
|
||||
open fun unMarkedReplyTos(): List<HexKey> = tags.filter { it.size > 1 && it.size <= 3 && it[0] == "e" }.map { it[1] }
|
||||
|
||||
open fun replyingTo(): HexKey? {
|
||||
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)
|
||||
@ -190,21 +184,51 @@ open class BaseTextNoteEvent(
|
||||
}
|
||||
|
||||
fun tagsWithoutCitations(): List<String> {
|
||||
val repliesTo = replyTos()
|
||||
val certainRepliesTo = markedReplyTos()
|
||||
val uncertainRepliesTo = unMarkedReplyTos()
|
||||
|
||||
val tagAddresses =
|
||||
taggedAddresses()
|
||||
.filter {
|
||||
it.kind != CommunityDefinitionEvent.KIND && (kind != WikiNoteEvent.KIND || it.kind != WikiNoteEvent.KIND)
|
||||
// removes forks from itself.
|
||||
}.map { it.toTag() }
|
||||
if (repliesTo.isEmpty() && tagAddresses.isEmpty()) return emptyList()
|
||||
|
||||
if (certainRepliesTo.isEmpty() && uncertainRepliesTo.isEmpty() && tagAddresses.isEmpty()) return emptyList()
|
||||
|
||||
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()) {
|
||||
repliesTo + tagAddresses
|
||||
if (certainRepliesTo.isNotEmpty()) {
|
||||
certainRepliesTo + tagAddresses
|
||||
} else {
|
||||
uncertainRepliesTo + tagAddresses
|
||||
}
|
||||
} 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 > 1 && it[0] == "e" }?.get(1)
|
||||
|
||||
override fun replyTos() =
|
||||
override fun markedReplyTos() =
|
||||
tags
|
||||
.filter { it.firstOrNull() == "e" && it.getOrNull(1) != channel() }
|
||||
.mapNotNull { it.getOrNull(1) }
|
||||
|
||||
override fun unMarkedReplyTos() = emptyList<String>()
|
||||
|
||||
companion object {
|
||||
const val KIND = 42
|
||||
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 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? =
|
||||
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 {
|
||||
const val KIND = 1311
|
||||
|
Loading…
x
Reference in New Issue
Block a user