mirror of https://github.com/usbharu/Hideout.git
feat: Followを受け取ったときの処理を追加
This commit is contained in:
parent
7eed0e270d
commit
4b0484df64
|
@ -12,12 +12,11 @@ import dev.usbharu.hideout.repository.UserAuthRepository
|
|||
import dev.usbharu.hideout.repository.UserRepository
|
||||
import dev.usbharu.hideout.routing.register
|
||||
import dev.usbharu.hideout.service.IUserAuthService
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubServiceImpl
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubUserServiceImpl
|
||||
import dev.usbharu.hideout.service.activitypub.*
|
||||
import dev.usbharu.hideout.service.impl.UserAuthService
|
||||
import dev.usbharu.hideout.service.impl.UserService
|
||||
import dev.usbharu.hideout.service.job.JobQueueService
|
||||
import dev.usbharu.hideout.service.job.KJobJobQueueService
|
||||
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
|
||||
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyServiceImpl
|
||||
import io.ktor.server.application.*
|
||||
|
@ -55,7 +54,12 @@ fun Application.module() {
|
|||
single<IUserAuthRepository> { UserAuthRepository(get()) }
|
||||
single<IUserAuthService> { UserAuthService(get(), get()) }
|
||||
single<HttpSignatureVerifyService> { HttpSignatureVerifyServiceImpl(get()) }
|
||||
single<ActivityPubService> { ActivityPubServiceImpl() }
|
||||
single<JobQueueService> { val kJobJobQueueService = KJobJobQueueService(get())
|
||||
kJobJobQueueService.init(listOf())
|
||||
kJobJobQueueService
|
||||
}
|
||||
single<ActivityPubFollowService>{ ActivityPubFollowServiceImpl(get()) }
|
||||
single<ActivityPubService> { ActivityPubServiceImpl(get()) }
|
||||
single<UserService> { UserService(get()) }
|
||||
single<ActivityPubUserService> { ActivityPubUserServiceImpl(get(), get()) }
|
||||
}
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
package dev.usbharu.hideout.domain.model
|
||||
|
||||
import dev.usbharu.hideout.ap.JsonLd
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import io.ktor.http.*
|
||||
|
||||
sealed class ActivityPubResponse(val httpStatusCode: HttpStatusCode)
|
||||
class ActivityPubStringResponse(httpStatusCode: HttpStatusCode, val message: String) :
|
||||
ActivityPubResponse(httpStatusCode)
|
||||
sealed class ActivityPubResponse(
|
||||
val httpStatusCode: HttpStatusCode,
|
||||
val contentType: ContentType = ContentType.Application.Activity
|
||||
)
|
||||
|
||||
class ActivityPubObjectResponse(httpStatusCode: HttpStatusCode, val message: JsonLd) :
|
||||
ActivityPubResponse(httpStatusCode)
|
||||
class ActivityPubStringResponse(
|
||||
httpStatusCode: HttpStatusCode,
|
||||
val message: String,
|
||||
contentType: ContentType = ContentType.Application.Activity
|
||||
) :
|
||||
ActivityPubResponse(httpStatusCode, contentType)
|
||||
|
||||
class ActivityPubObjectResponse(
|
||||
httpStatusCode: HttpStatusCode,
|
||||
val message: JsonLd,
|
||||
contentType: ContentType = ContentType.Application.Activity
|
||||
) :
|
||||
ActivityPubResponse(httpStatusCode, contentType)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package dev.usbharu.hideout.domain.model.job
|
||||
|
||||
import kjob.core.Job
|
||||
|
||||
object AcceptFollowJob : Job("AcceptFollowJob")
|
|
@ -0,0 +1,8 @@
|
|||
package dev.usbharu.hideout.service.activitypub
|
||||
|
||||
import dev.usbharu.hideout.ap.Follow
|
||||
import dev.usbharu.hideout.domain.model.ActivityPubResponse
|
||||
|
||||
interface ActivityPubFollowService {
|
||||
suspend fun receiveFollow(follow:Follow):ActivityPubResponse
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package dev.usbharu.hideout.service.activitypub
|
||||
|
||||
import dev.usbharu.hideout.ap.Follow
|
||||
import dev.usbharu.hideout.domain.model.ActivityPubResponse
|
||||
import dev.usbharu.hideout.domain.model.ActivityPubStringResponse
|
||||
import dev.usbharu.hideout.domain.model.job.AcceptFollowJob
|
||||
import dev.usbharu.hideout.service.job.JobQueueService
|
||||
import io.ktor.http.*
|
||||
|
||||
class ActivityPubFollowServiceImpl(private val jobQueueService: JobQueueService) : ActivityPubFollowService {
|
||||
override suspend fun receiveFollow(follow: Follow): ActivityPubResponse {
|
||||
// TODO: Verify HTTP Signature
|
||||
jobQueueService.schedule(AcceptFollowJob)
|
||||
return ActivityPubStringResponse(HttpStatusCode.OK,"{}",ContentType.Application.Json)
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ import dev.usbharu.hideout.domain.model.ActivityPubResponse
|
|||
interface ActivityPubService {
|
||||
fun parseActivity(json:String): ActivityType
|
||||
|
||||
fun processActivity(json:String, type: ActivityType): ActivityPubResponse?
|
||||
suspend fun processActivity(json:String, type: ActivityType): ActivityPubResponse?
|
||||
}
|
||||
|
||||
enum class ActivityType {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package dev.usbharu.hideout.service.activitypub
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import dev.usbharu.hideout.ap.Follow
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import dev.usbharu.hideout.domain.model.ActivityPubResponse
|
||||
import dev.usbharu.hideout.exception.JsonParseException
|
||||
|
||||
class ActivityPubServiceImpl : ActivityPubService {
|
||||
class ActivityPubServiceImpl(private val activityPubFollowService: ActivityPubFollowService) : ActivityPubService {
|
||||
override fun parseActivity(json: String): ActivityType {
|
||||
val readTree = Config.configData.objectMapper.readTree(json)
|
||||
if (readTree.isObject.not()) {
|
||||
|
@ -20,8 +21,8 @@ class ActivityPubServiceImpl : ActivityPubService {
|
|||
return ActivityType.values().first { it.name.equals(type.asText(), true) }
|
||||
}
|
||||
|
||||
override fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
|
||||
when (type) {
|
||||
override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
|
||||
return when (type) {
|
||||
ActivityType.Accept -> TODO()
|
||||
ActivityType.Add -> TODO()
|
||||
ActivityType.Announce -> TODO()
|
||||
|
@ -31,7 +32,13 @@ class ActivityPubServiceImpl : ActivityPubService {
|
|||
ActivityType.Delete -> TODO()
|
||||
ActivityType.Dislike -> TODO()
|
||||
ActivityType.Flag -> TODO()
|
||||
ActivityType.Follow -> TODO()
|
||||
ActivityType.Follow -> activityPubFollowService.receiveFollow(
|
||||
Config.configData.objectMapper.readValue(
|
||||
json,
|
||||
Follow::class.java
|
||||
)
|
||||
)
|
||||
|
||||
ActivityType.Ignore -> TODO()
|
||||
ActivityType.Invite -> TODO()
|
||||
ActivityType.Join -> TODO()
|
||||
|
|
|
@ -6,5 +6,5 @@ import kjob.core.dsl.ScheduleContext
|
|||
interface JobQueueService {
|
||||
|
||||
fun init(jobDefines:List<Job>)
|
||||
suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit)
|
||||
suspend fun <J : Job> schedule(job: J, block: ScheduleContext<J>.(J) -> Unit = {})
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ class UsersAPTest {
|
|||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
|
||||
override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}, UserService(object : IUserRepository {
|
||||
|
|
Loading…
Reference in New Issue