From bbc4ec26257213cd1624a3958928416aa301a597 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 12 Feb 2024 15:10:48 -0500 Subject: [PATCH] Fixes thread rendering when "mention" events are added with mentioning the event. --- .../quartz/events/BaseTextNoteEvent.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt index 5afa7657d..1317d6ae9 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt @@ -42,13 +42,26 @@ open class BaseTextNoteEvent( ) : Event(id, pubKey, createdAt, kind, tags, content, sig) { fun mentions() = taggedUsers() - open fun replyTos() = taggedEvents() + open fun replyTos(): List { + val oldStylePositional = tags.filter { it.size > 1 && it[0] == "e" }.map { it[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 newStyleReplyTos = listOfNotNull(newStyleReply, newStyleRoot) + + return if (newStyleReplyTos.isNotEmpty()) { + newStyleReplyTos + } else { + oldStylePositional + } + } fun replyingTo(): HexKey? { val oldStylePositional = tags.lastOrNull { it.size > 1 && it[0] == "e" }?.get(1) - val newStyle = 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) - return newStyle ?: oldStylePositional + return newStyleReply ?: newStyleRoot ?: oldStylePositional } @Transient private var citedUsersCache: Set? = null