mirror of https://github.com/usbharu/Hideout.git
wip
This commit is contained in:
parent
334462d402
commit
f036febf5c
|
@ -33,6 +33,7 @@ dependencies {
|
|||
implementation(libs.owl.producer.embedded)
|
||||
implementation(libs.owl.common.serialize.jackson)
|
||||
implementation(libs.activity.streams.serialization)
|
||||
implementation(libs.coroutines.core)
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
|
|
|
@ -1,19 +1,49 @@
|
|||
package dev.usbharu.hideout.activitypub.external.activitystreams
|
||||
|
||||
import dev.usbharu.activitystreamsserialization.activity.pub.ActivityPubActor
|
||||
import dev.usbharu.activitystreamsserialization.dsl.JsonLdBuilder
|
||||
|
||||
import dev.usbharu.activitystreamsserialization.dsl.ActivityBuilder
|
||||
import dev.usbharu.activitystreamsserialization.other.JsonLd
|
||||
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||
import dev.usbharu.hideout.core.domain.model.media.Media
|
||||
|
||||
class ActorTranslator {
|
||||
fun translate(actor: Actor): JsonLd {
|
||||
fun translate(actor: Actor, iconMedia: Media?, bannerMedia: Media?): JsonLd {
|
||||
//todo actorにbot等の属性が生えてきたら対応する
|
||||
val person = JsonLdBuilder().Person {
|
||||
val person = ActivityBuilder().Person {
|
||||
name(actor.name.name)
|
||||
id(actor.url)
|
||||
preferredUsername(actor.name.name)
|
||||
inbox(actor.inbox)
|
||||
outbox(actor.outbox)
|
||||
followers(actor.followersEndpoint)
|
||||
following(actor.followingEndpoint)
|
||||
publicKey {
|
||||
listOf(
|
||||
Key {
|
||||
owner(actor.url)
|
||||
publicKeyPem(actor.publicKey.publicKey)
|
||||
id(actor.keyId.keyId)
|
||||
})
|
||||
|
||||
}
|
||||
iconMedia?.let {
|
||||
icon {
|
||||
listOf(
|
||||
Image {
|
||||
url(iconMedia.url)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
bannerMedia?.let {
|
||||
image {
|
||||
listOf(
|
||||
Image {
|
||||
url(bannerMedia.url)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
person as ActivityPubActor
|
||||
|
||||
return person
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package dev.usbharu.hideout.activitypub.external.activitystreams
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ActorTranslatorTest {
|
||||
@Test
|
||||
fun translate() {
|
||||
val translate = ActorTranslator().translate(TestActorFactory.create(), null, null)
|
||||
println(translate)
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package dev.usbharu.hideout.activitypub.external.activitystreams
|
||||
|
||||
import dev.usbharu.hideout.core.domain.model.actor.*
|
||||
import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiId
|
||||
import dev.usbharu.hideout.core.domain.model.instance.InstanceId
|
||||
import dev.usbharu.hideout.core.domain.model.media.MediaId
|
||||
import dev.usbharu.hideout.core.domain.model.support.domain.Domain
|
||||
import dev.usbharu.hideout.core.infrastructure.other.TwitterSnowflakeIdGenerateService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.net.URI
|
||||
import java.time.Instant
|
||||
|
||||
object TestActorFactory {
|
||||
private val idGenerateService = TwitterSnowflakeIdGenerateService
|
||||
|
||||
fun create(
|
||||
id: Long = generateId(),
|
||||
actorName: String = "test-$id",
|
||||
domain: String = "example.com",
|
||||
actorScreenName: String = actorName,
|
||||
description: String = "test description",
|
||||
inbox: URI = URI.create("https://example.com/$id/inbox"),
|
||||
outbox: URI = URI.create("https://example.com/$id/outbox"),
|
||||
uri: URI = URI.create("https://example.com/$id"),
|
||||
publicKey: ActorPublicKey = ActorPublicKey(""),
|
||||
privateKey: ActorPrivateKey? = null,
|
||||
createdAt: Instant = Instant.now(),
|
||||
keyId: String = "https://example.com/$id#key-id",
|
||||
followersEndpoint: URI = URI.create("https://example.com/$id/followers"),
|
||||
followingEndpoint: URI = URI.create("https://example.com/$id/following"),
|
||||
instanceId: Long = 1L,
|
||||
locked: Boolean = false,
|
||||
followersCount: Int = 0,
|
||||
followingCount: Int = 0,
|
||||
postCount: Int = 0,
|
||||
lastPostDate: Instant? = null,
|
||||
lastUpdateAt: Instant = createdAt,
|
||||
suspend: Boolean = false,
|
||||
alsoKnownAs: Set<ActorId> = emptySet(),
|
||||
moveTo: Long? = null,
|
||||
emojiIds: Set<CustomEmojiId> = emptySet(),
|
||||
deleted: Boolean = false,
|
||||
icon: Long? = null,
|
||||
banner: Long? = null,
|
||||
): Actor {
|
||||
return runBlocking {
|
||||
Actor(
|
||||
id = ActorId(id),
|
||||
name = ActorName(actorName),
|
||||
domain = Domain(domain),
|
||||
screenName = ActorScreenName(actorScreenName),
|
||||
description = ActorDescription(description),
|
||||
inbox = inbox,
|
||||
outbox = outbox,
|
||||
url = uri,
|
||||
publicKey = publicKey,
|
||||
privateKey = privateKey,
|
||||
createdAt = createdAt,
|
||||
keyId = ActorKeyId(keyId),
|
||||
followersEndpoint = followersEndpoint,
|
||||
followingEndpoint = followingEndpoint,
|
||||
instance = InstanceId(instanceId),
|
||||
locked = locked,
|
||||
followersCount = ActorRelationshipCount(followersCount),
|
||||
followingCount = ActorRelationshipCount(followingCount),
|
||||
postsCount = ActorPostsCount(postCount),
|
||||
lastPostAt = lastPostDate,
|
||||
lastUpdateAt = lastUpdateAt,
|
||||
suspend = suspend,
|
||||
alsoKnownAs = alsoKnownAs,
|
||||
moveTo = moveTo?.let { ActorId(it) },
|
||||
emojiIds = emojiIds,
|
||||
deleted = deleted,
|
||||
icon = icon?.let { MediaId(it) },
|
||||
banner = banner?.let { MediaId(it) },
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateId(): Long = runBlocking {
|
||||
idGenerateService.generateId()
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version = "5.4.
|
|||
|
||||
http-signature = { module = "dev.usbharu:http-signature", version = "1.0.0" }
|
||||
emoji-kt = { module = "dev.usbharu:emoji-kt", version = "2.0.1" }
|
||||
activity-streams-serialization = { module = "dev.usbharu:activity-streams-serialization", version = "0.2.0" }
|
||||
activity-streams-serialization = { module = "dev.usbharu:activity-streams-serialization", version = "0.4.1" }
|
||||
|
||||
logback-ecs-encoder = { module = "co.elastic.logging:logback-ecs-encoder", version = "1.6.0" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue