diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index b8544aae3..32f57fac8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -751,11 +751,13 @@ private fun ReplyRow( val replyingDirectlyTo = remember(note) { if (noteEvent is BaseTextNoteEvent) { - val replyingTo = noteEvent.replyingTo() + val replyingTo = noteEvent.replyingToAddressOrEvent() if (replyingTo != null) { - note.replyTo?.firstOrNull { - // important to test both ids in case it's a replaceable event. - it.idHex == replyingTo || it.event?.id() == replyingTo + val newNote = accountViewModel.getNoteIfExists(replyingTo) + if (newNote != null && newNote.channelHex() == null && newNote.event?.kind() != CommunityDefinitionEvent.KIND) { + newNote + } else { + note.replyTo?.lastOrNull { it.event?.kind() != CommunityDefinitionEvent.KIND } } } else { note.replyTo?.lastOrNull { it.event?.kind() != CommunityDefinitionEvent.KIND } 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 aa65eb642..503944e38 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/BaseTextNoteEvent.kt @@ -79,6 +79,22 @@ open class BaseTextNoteEvent( return newStyleReply ?: newStyleRoot ?: oldStylePositional } + fun replyingToAddress(): ATag? { + val oldStylePositional = tags.lastOrNull { it.size > 1 && it[0] == "a" }?.let { ATag.parseAtag(it[1], it[2]) } + val newStyleReply = tags.lastOrNull { it.size > 3 && it[0] == "a" && it[3] == "reply" }?.let { ATag.parseAtag(it[1], it[2]) } + val newStyleRoot = tags.lastOrNull { it.size > 3 && it[0] == "a" && it[3] == "root" }?.let { ATag.parseAtag(it[1], it[2]) } + + return newStyleReply ?: newStyleRoot ?: oldStylePositional + } + + fun replyingToAddressOrEvent(): String? { + val oldStylePositional = tags.lastOrNull { it.size > 1 && (it[0] == "e" || it[0] == "a") }?.get(1) + val newStyleReply = tags.lastOrNull { it.size > 3 && (it[0] == "e" || it[0] == "a") && it[3] == "reply" }?.get(1) + val newStyleRoot = tags.lastOrNull { it.size > 3 && (it[0] == "e" || it[0] == "a") && it[3] == "root" }?.get(1) + + return newStyleReply ?: newStyleRoot ?: oldStylePositional + } + @Transient private var citedUsersCache: Set? = null @Transient private var citedNotesCache: Set? = null