Skip to content

Commit

Permalink
Temporarily disable facets
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpgrailsdev committed Dec 11, 2024
1 parent d9b91b1 commit 48fa796
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ data class BlueSkyRecordCommit(

@SuppressFBWarnings(value = ["EI_EXPOSE_REP", "EI_EXPOSE_REP2"])
data class BlueSkyGetFeedsResponse(
val cursor: String,
val cursor: String?,
val feeds: List<BlueSkyFeed>,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.jdpgrailsdev.oasis.timeline.client.BlueSkyReply
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyReplyPost
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyTagFacetFeature
import com.jdpgrailsdev.oasis.timeline.data.Post
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand All @@ -48,14 +49,15 @@ object BlueSkyUtils {
text = text,
createdAt = TIMESTAMP_FORMAT.format(Instant.now()),
reply = reply,
facets = createFacets(text = text, resolvers = resolvers),
facets = emptyList(), // createFacets(text = text, resolvers = resolvers),
)

fun createReply(
rootMessage: BlueSkyReplyPost? = null,
parentMessage: BlueSkyReplyPost? = null,
): BlueSkyReply = BlueSkyReply(root = rootMessage ?: parentMessage, parent = parentMessage ?: rootMessage)

@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD")
private fun createFacets(
text: String,
resolvers: Map<BlueSkyFacetType, (mention: String) -> String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

package com.jdpgrailsdev.oasis.timeline.util

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyFacet
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyFacetType
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyMentionFacetFeature
import com.jdpgrailsdev.oasis.timeline.client.BlueSkyReply
Expand All @@ -33,6 +29,7 @@ import com.jdpgrailsdev.oasis.timeline.data.Post
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -98,6 +95,7 @@ internal class BlueSkyUtilsTest {
}

@Test
@Disabled
fun testCreateRecordWithFacets() {
val did = "did:plc:2kfn5kwq4dqzncgv2g2tqmii"
val mention = "test.bsky.social"
Expand All @@ -108,50 +106,35 @@ internal class BlueSkyUtilsTest {

val record = BlueSkyUtils.createRecord(text = text, resolvers = blueSkyResolverMap)

val mapper =
JsonMapper
.builder()
.addModule(JavaTimeModule())
.addModule(KotlinModule.Builder().build())
.serializationInclusion(JsonInclude.Include.NON_NULL)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.build()
println(mapper.writeValueAsString(record))
assertEquals(text, record.text)
assertNotNull(record.createdAt)
assertEquals(3, record.facets.size)
assertEquals(
2,
record.facets
.filter { f ->
f.features.find { feature -> feature.getType() == BlueSkyFacetType.TAG.type } != null
}.size,
)
assertEquals(
1,
record.facets
.filter { f ->
f.features.find { feature -> feature.getType() == BlueSkyFacetType.MENTION.type } != null
}.size,
)
assertEquals(
did,
(
record.facets
.first { f ->
f.features.find { feature -> feature.getType() == BlueSkyFacetType.MENTION.type } !=
null
}.features
.first() as BlueSkyMentionFacetFeature
).did,
)
val tagFacets =
record.facets.filter { f ->
f.features.find { feature -> feature.getType() == BlueSkyFacetType.TAG.type } != null
}
val tags =
(tagFacets.flatMap { t -> t.features.map { f -> (f as BlueSkyTagFacetFeature).tag } })
assertEquals(2, getTagFacetFeatures(facets = record.facets).size)
assertEquals(1, getMentionFacetFeatures(facets = record.facets).size)
assertEquals(did, getMentionFacetFeatures(facets = record.facets).first().did)
val tags = getTagFacetFeatures(facets = record.facets).map { f -> f.tag }
assertTrue(tags.contains("tag1"))
assertTrue(tags.contains("tag2"))

record.facets.forEach { facet ->
val byteStart = facet.index.byteStart
val byteEnd = facet.index.byteEnd

println("Index for facet $facet")

println(text.substring(byteStart, byteEnd))
}
}

private fun getMentionFacetFeatures(facets: List<BlueSkyFacet>): List<BlueSkyMentionFacetFeature> =
facets
.flatMap { f -> f.features }
.filter { f -> f.getType() == BlueSkyFacetType.MENTION.type }
.map { f -> f as BlueSkyMentionFacetFeature }

private fun getTagFacetFeatures(facets: List<BlueSkyFacet>): List<BlueSkyTagFacetFeature> =
facets
.flatMap { f -> f.features }
.filter { f -> f.getType() == BlueSkyFacetType.TAG.type }
.map { f -> f as BlueSkyTagFacetFeature }
}

0 comments on commit 48fa796

Please sign in to comment.