Removes the need for an extra object for the tag array in the custom emoji nip

This commit is contained in:
Vitor Pamplona
2026-01-13 17:32:38 -05:00
parent 288fccd414
commit 6097a0b5b7
4 changed files with 10 additions and 12 deletions
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.nip30CustomEmoji
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.nip01Core.core.ImmutableListOfLists
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
@@ -32,10 +31,10 @@ class CustomEmoji {
fun fastMightContainEmoji(
input: String,
allTags: ImmutableListOfLists<String>?,
allTags: Array<Array<String>>?,
): Boolean {
if (allTags == null) return false
if (allTags.lists.any { it.size > 2 && it[0] == EmojiUrlTag.TAG_NAME }) return true
if (allTags.any { it.size > 2 && it[0] == EmojiUrlTag.TAG_NAME }) return true
return input.contains(":")
}
@@ -47,7 +46,7 @@ class CustomEmoji {
return input.contains(":")
}
fun createEmojiMap(tags: ImmutableListOfLists<String>): Map<String, String> = tags.lists.filter { it.size > 2 && it[0] == EmojiUrlTag.TAG_NAME }.associate { ":${it[1]}:" to it[2] }
fun createEmojiMap(tags: Array<Array<String>>): Map<String, String> = tags.filter { it.size > 2 && it[0] == EmojiUrlTag.TAG_NAME }.associate { ":${it[1]}:" to it[2] }
fun findAllEmojis(input: String): List<String> {
val matcher = customEmojiPattern.findAll(input)
@@ -67,11 +66,11 @@ class CustomEmoji {
fun assembleAnnotatedList(
input: String,
allTags: ImmutableListOfLists<String>?,
tags: Array<Array<String>>?,
): ImmutableList<Renderable>? {
if (allTags == null || allTags.lists.isEmpty()) return null
if (tags == null || tags.isEmpty()) return null
val emojiPairs = createEmojiMap(allTags)
val emojiPairs = createEmojiMap(tags)
return assembleAnnotatedList(input, emojiPairs)
}
@@ -20,7 +20,6 @@
*/
package com.vitorpamplona.quartz.nip30CustomEmoji
import com.vitorpamplona.quartz.nip01Core.core.ImmutableListOfLists
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
@@ -150,7 +149,7 @@ class Nip30Test {
"#ioメシヨソイゲーム\n" +
"https://misskey.io/play/9g3qza4jow"
val result = CustomEmoji.assembleAnnotatedList(input, ImmutableListOfLists(tags))
val result = CustomEmoji.assembleAnnotatedList(input, tags)
assertEquals(9, result!!.size)