feat: とりあえずacceptを返すように

This commit is contained in:
usbharu 2023-03-30 18:23:38 +09:00
parent 61ddbb5743
commit 9dcaddc108
4 changed files with 56 additions and 34 deletions

View File

@ -1,13 +1,13 @@
package dev.usbharu.hideout.ap package dev.usbharu.hideout.ap
open class Follow : Object{ open class Follow : Object{
public var `object`:Object? = null public var `object`:String? = null
public var actor:String? = null public var actor:String? = null
protected constructor() : super() protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, name: String,
`object`: Object?, `object`: String?,
actor: String? actor: String?
) : super(add(type,"Follow"), name) { ) : super(add(type,"Follow"), name) {
this.`object` = `object` this.`object` = `object`

View File

@ -4,7 +4,7 @@ open class Person : Object {
private var id:String? = null private var id:String? = null
var preferredUsername:String? = null var preferredUsername:String? = null
var summary:String? = null var summary:String? = null
private var inbox:String? = null var inbox:String? = null
private var outbox:String? = null private var outbox:String? = null
private var url:String? = null private var url:String? = null
private var icon:Image? = null private var icon:Image? = null

View File

@ -1,6 +1,10 @@
package dev.usbharu.hideout.routing package dev.usbharu.hideout.routing
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.ap.Follow
import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.service.ActivityPubService import dev.usbharu.hideout.service.ActivityPubService
import dev.usbharu.hideout.service.ActivityPubUserService
import dev.usbharu.hideout.util.HttpUtil import dev.usbharu.hideout.util.HttpUtil
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.* import io.ktor.server.application.*
@ -8,7 +12,7 @@ import io.ktor.server.request.*
import io.ktor.server.response.* import io.ktor.server.response.*
import io.ktor.server.routing.* import io.ktor.server.routing.*
fun Application.userActivityPubRouting(activityPubService: ActivityPubService) { fun Application.userActivityPubRouting(activityPubService: ActivityPubService, activityPubUserService: ActivityPubUserService) {
routing { routing {
route("/users/{name}") { route("/users/{name}") {
route("/inbox") { route("/inbox") {
@ -21,7 +25,17 @@ fun Application.userActivityPubRouting(activityPubService: ActivityPubService) {
} }
val bodyText = call.receiveText() val bodyText = call.receiveText()
println(bodyText) println(bodyText)
activityPubService.switchApType(bodyText) when (activityPubService.switchApType(bodyText)) {
ActivityPubService.ActivityType.Follow -> {
val readValue = Config.configData.objectMapper.readValue<Follow>(bodyText)
activityPubUserService.receiveFollow(readValue)
}
ActivityPubService.ActivityType.Undo -> {
TODO()
}
}
} }
} }

View File

@ -1,8 +1,6 @@
package dev.usbharu.hideout.service package dev.usbharu.hideout.service
import dev.usbharu.hideout.ap.Image import dev.usbharu.hideout.ap.*
import dev.usbharu.hideout.ap.Key
import dev.usbharu.hideout.ap.Person
import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.Config
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.call.* import io.ktor.client.call.*
@ -13,7 +11,8 @@ import io.ktor.http.*
class ActivityPubUserService( class ActivityPubUserService(
private val httpClient: HttpClient, private val httpClient: HttpClient,
private val userService: UserService, private val userService: UserService,
private val userAuthService: IUserAuthService private val userAuthService: IUserAuthService,
private val webFingerService: WebFingerService
) { ) {
suspend fun generateUserModel(name: String): Person { suspend fun generateUserModel(name: String): Person {
val userEntity = userService.findByName(name) val userEntity = userService.findByName(name)
@ -55,7 +54,16 @@ class ActivityPubUserService(
} }
} }
suspend fun receiveFollow(){ suspend fun receiveFollow(follow: Follow) {
val actor = follow.actor ?: throw IllegalArgumentException("actor is null")
val person = fetchUserModel(actor) ?: throw IllegalArgumentException("actor is not found")
val inboxUrl = person.inbox ?: throw IllegalArgumentException("inbox is not found")
httpClient.post(inboxUrl) {
setBody(Accept(
name = "Follow",
`object` = follow,
actor = follow.`object`.orEmpty()
))
}
} }
} }