From 5f85a25daf6d9b57ba4c40c28c0c157aa8ba263b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 11 Aug 2023 16:29:52 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ActivityPub=E3=82=92AP=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/dev/usbharu/hideout/Application.kt | 18 ++++----- .../domain/model/ap/ObjectDeserializer.kt | 2 +- .../dev/usbharu/hideout/plugins/Routing.kt | 12 +++--- .../routing/activitypub/InboxRouting.kt | 10 ++--- .../routing/activitypub/UserRouting.kt | 6 +-- .../APAcceptService.kt} | 4 +- .../APAcceptServiceImpl.kt} | 6 +-- .../APCreateService.kt} | 4 +- .../APCreateServiceImpl.kt} | 10 ++--- .../APLikeService.kt} | 4 +- .../APLikeServiceImpl.kt} | 14 +++---- .../APNoteService.kt} | 4 +- .../APNoteServiceImpl.kt} | 15 +++++--- .../APReactionService.kt} | 4 +- .../APReactionServiceImpl.kt} | 6 +-- .../APReceiveFollowService.kt} | 4 +- .../APReceiveFollowServiceImpl.kt} | 10 ++--- .../APSendFollowService.kt} | 4 +- .../APSendFollowServiceImpl.kt} | 4 +- .../ActivityPubService.kt => ap/APService.kt} | 4 +- .../APServiceImpl.kt} | 38 +++++++++---------- .../APUndoService.kt} | 4 +- .../APUndoServiceImpl.kt} | 10 ++--- .../APUserService.kt} | 4 +- .../APUserServiceImpl.kt} | 6 +-- .../hideout/service/post/PostServiceImpl.kt | 6 +-- .../service/reaction/ReactionServiceImpl.kt | 6 +-- .../hideout/service/user/UserService.kt | 6 +-- .../routing/activitypub/InboxRoutingKtTest.kt | 16 ++++---- .../routing/activitypub/UsersAPTest.kt | 10 ++--- .../APNoteServiceImplTest.kt} | 8 ++-- .../APReceiveFollowServiceImplTest.kt} | 12 +++--- 32 files changed, 137 insertions(+), 134 deletions(-) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubAcceptService.kt => ap/APAcceptService.kt} (68%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubAcceptServiceImpl.kt => ap/APAcceptServiceImpl.kt} (92%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubCreateService.kt => ap/APCreateService.kt} (68%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubCreateServiceImpl.kt => ap/APCreateServiceImpl.kt} (80%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubLikeService.kt => ap/APLikeService.kt} (67%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubLikeServiceImpl.kt => ap/APLikeServiceImpl.kt} (80%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubNoteService.kt => ap/APNoteService.kt} (84%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubNoteServiceImpl.kt => ap/APNoteServiceImpl.kt} (95%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubReactionService.kt => ap/APReactionService.kt} (84%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubReactionServiceImpl.kt => ap/APReactionServiceImpl.kt} (96%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubReceiveFollowService.kt => ap/APReceiveFollowService.kt} (78%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubReceiveFollowServiceImpl.kt => ap/APReceiveFollowServiceImpl.kt} (90%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubSendFollowService.kt => ap/APSendFollowService.kt} (58%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubSendFollowServiceImpl.kt => ap/APSendFollowServiceImpl.kt} (80%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubService.kt => ap/APService.kt} (96%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubServiceImpl.kt => ap/APServiceImpl.kt} (58%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubUndoService.kt => ap/APUndoService.kt} (67%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubUndoServiceImpl.kt => ap/APUndoServiceImpl.kt} (87%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubUserService.kt => ap/APUserService.kt} (79%) rename src/main/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubUserServiceImpl.kt => ap/APUserServiceImpl.kt} (97%) rename src/test/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubNoteServiceImplTest.kt => ap/APNoteServiceImplTest.kt} (95%) rename src/test/kotlin/dev/usbharu/hideout/service/{activitypub/ActivityPubReceiveFollowServiceImplTest.kt => ap/APReceiveFollowServiceImplTest.kt} (95%) diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index dc4d2788..2af9ef54 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -15,8 +15,8 @@ import dev.usbharu.hideout.plugins.* import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.routing.register -import dev.usbharu.hideout.service.activitypub.ActivityPubService -import dev.usbharu.hideout.service.activitypub.ActivityPubUserService +import dev.usbharu.hideout.service.ap.APService +import dev.usbharu.hideout.service.ap.APUserService import dev.usbharu.hideout.service.api.IPostApiService import dev.usbharu.hideout.service.api.IUserApiService import dev.usbharu.hideout.service.api.UserAuthApiService @@ -109,9 +109,9 @@ fun Application.parent() { ) configureRouting( httpSignatureVerifyService = inject().value, - activityPubService = inject().value, + apService = inject().value, userService = inject().value, - activityPubUserService = inject().value, + apUserService = inject().value, postService = inject().value, userApiService = inject().value, userQueryService = inject().value, @@ -128,28 +128,28 @@ fun Application.worker() { connectionDatabase = inject().value }.start() - val activityPubService = inject().value + val apService = inject().value kJob.register(ReceiveFollowJob) { execute { - activityPubService.processActivity(this, it) + apService.processActivity(this, it) } } kJob.register(DeliverPostJob) { execute { - activityPubService.processActivity(this, it) + apService.processActivity(this, it) } } kJob.register(DeliverReactionJob) { execute { - activityPubService.processActivity(this, it) + apService.processActivity(this, it) } } kJob.register(DeliverRemoveReactionJob) { execute { - activityPubService.processActivity(this, it) + apService.processActivity(this, it) } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt index d3b47879..66af888a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonDeserializer import com.fasterxml.jackson.databind.JsonNode -import dev.usbharu.hideout.service.activitypub.ExtendedActivityVocabulary +import dev.usbharu.hideout.service.ap.ExtendedActivityVocabulary class ObjectDeserializer : JsonDeserializer() { @Suppress("LongMethod", "CyclomaticComplexMethod") diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt index 5fcd18de..0567db26 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt @@ -9,8 +9,8 @@ import dev.usbharu.hideout.routing.api.internal.v1.auth import dev.usbharu.hideout.routing.api.internal.v1.posts import dev.usbharu.hideout.routing.api.internal.v1.users import dev.usbharu.hideout.routing.wellknown.webfinger -import dev.usbharu.hideout.service.activitypub.ActivityPubService -import dev.usbharu.hideout.service.activitypub.ActivityPubUserService +import dev.usbharu.hideout.service.ap.APService +import dev.usbharu.hideout.service.ap.APUserService import dev.usbharu.hideout.service.api.IPostApiService import dev.usbharu.hideout.service.api.IUserApiService import dev.usbharu.hideout.service.api.UserAuthApiService @@ -25,9 +25,9 @@ import io.ktor.server.routing.* @Suppress("LongParameterList") fun Application.configureRouting( httpSignatureVerifyService: HttpSignatureVerifyService, - activityPubService: ActivityPubService, + apService: APService, userService: IUserService, - activityPubUserService: ActivityPubUserService, + apUserService: APUserService, postService: IPostApiService, userApiService: IUserApiService, userQueryService: UserQueryService, @@ -38,9 +38,9 @@ fun Application.configureRouting( ) { install(AutoHeadResponse) routing { - inbox(httpSignatureVerifyService, activityPubService) + inbox(httpSignatureVerifyService, apService) outbox() - usersAP(activityPubUserService, userQueryService, followerQueryService, transaction) + usersAP(apUserService, userQueryService, followerQueryService, transaction) webfinger(webFingerApiService) route("/api/internal/v1") { posts(postService) diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt index 92a216bb..dbdcd666 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt @@ -13,7 +13,7 @@ import io.ktor.server.routing.* fun Routing.inbox( httpSignatureVerifyService: HttpSignatureVerifyService, - activityPubService: dev.usbharu.hideout.service.activitypub.ActivityPubService + apService: dev.usbharu.hideout.service.ap.APService ) { route("/inbox") { get { @@ -25,9 +25,9 @@ fun Routing.inbox( } val json = call.receiveText() call.application.log.trace("Received: $json") - val activityTypes = activityPubService.parseActivity(json) + val activityTypes = apService.parseActivity(json) call.application.log.debug("ActivityTypes: ${activityTypes.name}") - val response = activityPubService.processActivity(json, activityTypes) + val response = apService.processActivity(json, activityTypes) when (response) { is ActivityPubObjectResponse -> call.respond( response.httpStatusCode, @@ -54,9 +54,9 @@ fun Routing.inbox( } val json = call.receiveText() call.application.log.trace("Received: $json") - val activityTypes = activityPubService.parseActivity(json) + val activityTypes = apService.parseActivity(json) call.application.log.debug("ActivityTypes: ${activityTypes.name}") - val response = activityPubService.processActivity(json, activityTypes) + val response = apService.processActivity(json, activityTypes) when (response) { is ActivityPubObjectResponse -> call.respond( response.httpStatusCode, diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt index 734c45c8..c4b03cba 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt @@ -5,7 +5,7 @@ import dev.usbharu.hideout.exception.ParameterNotExistException import dev.usbharu.hideout.plugins.respondAp import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.UserQueryService -import dev.usbharu.hideout.service.activitypub.ActivityPubUserService +import dev.usbharu.hideout.service.ap.APUserService import dev.usbharu.hideout.service.core.Transaction import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.JsonLd @@ -16,7 +16,7 @@ import io.ktor.server.response.* import io.ktor.server.routing.* fun Routing.usersAP( - activityPubUserService: ActivityPubUserService, + apUserService: APUserService, userQueryService: UserQueryService, followerQueryService: FollowerQueryService, transaction: Transaction @@ -27,7 +27,7 @@ fun Routing.usersAP( call.application.log.debug("Authorization: ${call.request.header("Authorization")}") val name = call.parameters["name"] ?: throw ParameterNotExistException("Parameter(name='name') does not exist.") - val person = activityPubUserService.getPersonByName(name) + val person = apUserService.getPersonByName(name) return@handle call.respondAp( person, HttpStatusCode.OK diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt similarity index 68% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt index d0746c44..fdcbbf61 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptService.kt @@ -1,8 +1,8 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Accept -interface ActivityPubAcceptService { +interface APAcceptService { suspend fun receiveAccept(accept: Accept): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptServiceImpl.kt similarity index 92% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptServiceImpl.kt index 19df2c97..b8fd337f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubAcceptServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APAcceptServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ActivityPubStringResponse @@ -11,10 +11,10 @@ import io.ktor.http.* import org.koin.core.annotation.Single @Single -class ActivityPubAcceptServiceImpl( +class APAcceptServiceImpl( private val userService: IUserService, private val userQueryService: UserQueryService -) : ActivityPubAcceptService { +) : APAcceptService { override suspend fun receiveAccept(accept: Accept): ActivityPubResponse { val value = accept.`object` ?: throw IllegalActivityPubObjectException("object is null") if (value.type.contains("Follow").not()) { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt similarity index 68% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt index 632c801e..29fa38de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateService.kt @@ -1,8 +1,8 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Create -interface ActivityPubCreateService { +interface APCreateService { suspend fun receiveCreate(create: Create): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImpl.kt similarity index 80% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImpl.kt index 85e88b57..2f1e4bd0 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubCreateServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APCreateServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ActivityPubStringResponse @@ -10,10 +10,10 @@ import io.ktor.http.* import org.koin.core.annotation.Single @Single -class ActivityPubCreateServiceImpl( - private val activityPubNoteService: ActivityPubNoteService, +class APCreateServiceImpl( + private val apNoteService: APNoteService, private val transaction: Transaction -) : ActivityPubCreateService { +) : APCreateService { override suspend fun receiveCreate(create: Create): ActivityPubResponse { val value = create.`object` ?: throw IllegalActivityPubObjectException("object is null") if (value.type.contains("Note").not()) { @@ -22,7 +22,7 @@ class ActivityPubCreateServiceImpl( return transaction.transaction { val note = value as Note - activityPubNoteService.fetchNote(note) + apNoteService.fetchNote(note) ActivityPubStringResponse(HttpStatusCode.OK, "Created") } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt similarity index 67% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt index 19d3f341..0ecb30a6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeService.kt @@ -1,8 +1,8 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Like -interface ActivityPubLikeService { +interface APLikeService { suspend fun receiveLike(like: Like): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeServiceImpl.kt similarity index 80% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeServiceImpl.kt index a9f12cfa..929f79c5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubLikeServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APLikeServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ActivityPubStringResponse @@ -12,21 +12,21 @@ import io.ktor.http.* import org.koin.core.annotation.Single @Single -class ActivityPubLikeServiceImpl( +class APLikeServiceImpl( private val reactionService: IReactionService, - private val activityPubUserService: ActivityPubUserService, - private val activityPubNoteService: ActivityPubNoteService, + private val apUserService: APUserService, + private val apNoteService: APNoteService, private val userQueryService: UserQueryService, private val postQueryService: PostQueryService, private val transaction: Transaction -) : ActivityPubLikeService { +) : APLikeService { override suspend fun receiveLike(like: Like): ActivityPubResponse { val actor = like.actor ?: throw IllegalActivityPubObjectException("actor is null") val content = like.content ?: throw IllegalActivityPubObjectException("content is null") like.`object` ?: throw IllegalActivityPubObjectException("object is null") transaction.transaction { - val person = activityPubUserService.fetchPerson(actor) - activityPubNoteService.fetchNote(like.`object`!!) + val person = apUserService.fetchPerson(actor) + apNoteService.fetchNote(like.`object`!!) val user = userQueryService.findByUrl( person.url diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt similarity index 84% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 2c289415..33b9d457 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -1,11 +1,11 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ap.Note import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.job.DeliverPostJob import kjob.core.job.JobProps -interface ActivityPubNoteService { +interface APNoteService { suspend fun createNote(post: Post) suspend fun createNoteJob(props: JobProps) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImpl.kt similarity index 95% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImpl.kt index a6cdce08..d46d02a7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config @@ -23,15 +23,15 @@ import org.slf4j.LoggerFactory import java.time.Instant @Single -class ActivityPubNoteServiceImpl( +class APNoteServiceImpl( private val httpClient: HttpClient, private val jobQueueParentService: JobQueueParentService, private val postRepository: IPostRepository, - private val activityPubUserService: ActivityPubUserService, + private val apUserService: APUserService, private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService, private val postQueryService: PostQueryService -) : ActivityPubNoteService { +) : APNoteService { private val logger = LoggerFactory.getLogger(this::class.java) @@ -75,9 +75,12 @@ class ActivityPubNoteServiceImpl( override suspend fun fetchNote(url: String, targetActor: String?): Note { val post = postQueryService.findByUrl(url) - if (post != null) { + try { return postToNote(post) + } catch (_: NoSuchElementException) { + } catch (_: IllegalArgumentException) { } + val response = httpClient.getAp( url, targetActor?.let { "$targetActor#pubkey" } @@ -118,7 +121,7 @@ class ActivityPubNoteServiceImpl( } private suspend fun internalNote(note: Note, targetActor: String?, url: String): Note { - val person = activityPubUserService.fetchPerson( + val person = apUserService.fetchPerson( note.attributedTo ?: throw IllegalActivityPubObjectException("note.attributedTo is null"), targetActor ) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt similarity index 84% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt index f3ac458c..aa12198c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt @@ -1,11 +1,11 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.hideout.entity.Reaction import dev.usbharu.hideout.domain.model.job.DeliverReactionJob import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob import kjob.core.job.JobProps -interface ActivityPubReactionService { +interface APReactionService { suspend fun reaction(like: Reaction) suspend fun removeReaction(like: Reaction) suspend fun reactionJob(props: JobProps) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionServiceImpl.kt similarity index 96% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionServiceImpl.kt index 3a6f1771..3635836b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config @@ -19,14 +19,14 @@ import org.koin.core.annotation.Single import java.time.Instant @Single -class ActivityPubReactionServiceImpl( +class APReactionServiceImpl( private val jobQueueParentService: JobQueueParentService, private val iPostRepository: IPostRepository, private val httpClient: HttpClient, private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService, private val postQueryService: PostQueryService -) : ActivityPubReactionService { +) : APReactionService { override suspend fun reaction(like: Reaction) { val followers = followerQueryService.findFollowersById(like.userId) val user = userQueryService.findById(like.userId) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt similarity index 78% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt index 378b0db6..7aaf21e5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt @@ -1,11 +1,11 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob import kjob.core.job.JobProps -interface ActivityPubReceiveFollowService { +interface APReceiveFollowService { suspend fun receiveFollow(follow: Follow): ActivityPubResponse suspend fun receiveFollowJob(props: JobProps) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImpl.kt similarity index 90% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImpl.kt index 94392412..3e8500df 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config @@ -18,14 +18,14 @@ import kjob.core.job.JobProps import org.koin.core.annotation.Single @Single -class ActivityPubReceiveFollowServiceImpl( +class APReceiveFollowServiceImpl( private val jobQueueParentService: JobQueueParentService, - private val activityPubUserService: ActivityPubUserService, + private val apUserService: APUserService, private val userService: IUserService, private val httpClient: HttpClient, private val userQueryService: UserQueryService, private val transaction: Transaction -) : ActivityPubReceiveFollowService { +) : APReceiveFollowService { override suspend fun receiveFollow(follow: Follow): ActivityPubResponse { // TODO: Verify HTTP Signature jobQueueParentService.schedule(ReceiveFollowJob) { @@ -40,7 +40,7 @@ class ActivityPubReceiveFollowServiceImpl( transaction.transaction { val actor = props[ReceiveFollowJob.actor] val targetActor = props[ReceiveFollowJob.targetActor] - val person = activityPubUserService.fetchPerson(actor, targetActor) + val person = apUserService.fetchPerson(actor, targetActor) val follow = Config.configData.objectMapper.readValue(props[ReceiveFollowJob.follow]) httpClient.postAp( urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found"), diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt similarity index 58% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt index 8d0dd1f2..d4058113 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowService.kt @@ -1,7 +1,7 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.hideout.dto.SendFollowDto -interface ActivityPubSendFollowService { +interface APSendFollowService { suspend fun sendFollow(sendFollowDto: SendFollowDto) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowServiceImpl.kt similarity index 80% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowServiceImpl.kt index e73e9266..a2ccb74f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubSendFollowServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APSendFollowServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.hideout.dto.SendFollowDto @@ -7,7 +7,7 @@ import io.ktor.client.* import org.koin.core.annotation.Single @Single -class ActivityPubSendFollowServiceImpl(private val httpClient: HttpClient) : ActivityPubSendFollowService { +class APSendFollowServiceImpl(private val httpClient: HttpClient) : APSendFollowService { override suspend fun sendFollow(sendFollowDto: SendFollowDto) { val follow = Follow( name = "Follow", diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt similarity index 96% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt index bec7f2fb..719149c1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt @@ -1,10 +1,10 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.job.HideoutJob import kjob.core.dsl.JobContextWithProps -interface ActivityPubService { +interface APService { fun parseActivity(json: String): ActivityType suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse? diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APServiceImpl.kt similarity index 58% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APServiceImpl.kt index 95355d2a..f2cd4000 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.module.kotlin.readValue @@ -14,15 +14,15 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory @Single -class ActivityPubServiceImpl( - private val activityPubReceiveFollowService: ActivityPubReceiveFollowService, - private val activityPubNoteService: ActivityPubNoteService, - private val activityPubUndoService: ActivityPubUndoService, - private val activityPubAcceptService: ActivityPubAcceptService, - private val activityPubCreateService: ActivityPubCreateService, - private val activityPubLikeService: ActivityPubLikeService, - private val activityPubReactionService: ActivityPubReactionService -) : ActivityPubService { +class APServiceImpl( + private val apReceiveFollowService: APReceiveFollowService, + private val apNoteService: APNoteService, + private val apUndoService: APUndoService, + private val apAcceptService: APAcceptService, + private val apCreateService: APCreateService, + private val apLikeService: APLikeService, + private val apReactionService: APReactionService +) : APService { val logger: Logger = LoggerFactory.getLogger(this::class.java) override fun parseActivity(json: String): ActivityType { @@ -44,17 +44,17 @@ class ActivityPubServiceImpl( override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse { logger.debug("proccess activity: {}", type) return when (type) { - ActivityType.Accept -> activityPubAcceptService.receiveAccept(configData.objectMapper.readValue(json)) - ActivityType.Follow -> activityPubReceiveFollowService.receiveFollow( + ActivityType.Accept -> apAcceptService.receiveAccept(configData.objectMapper.readValue(json)) + ActivityType.Follow -> apReceiveFollowService.receiveFollow( configData.objectMapper.readValue( json, Follow::class.java ) ) - ActivityType.Create -> activityPubCreateService.receiveCreate(configData.objectMapper.readValue(json)) - ActivityType.Like -> activityPubLikeService.receiveLike(configData.objectMapper.readValue(json)) - ActivityType.Undo -> activityPubUndoService.receiveUndo(configData.objectMapper.readValue(json)) + ActivityType.Create -> apCreateService.receiveCreate(configData.objectMapper.readValue(json)) + ActivityType.Like -> apLikeService.receiveLike(configData.objectMapper.readValue(json)) + ActivityType.Undo -> apUndoService.receiveUndo(configData.objectMapper.readValue(json)) else -> { throw IllegalArgumentException("$type is not supported.") @@ -65,13 +65,13 @@ class ActivityPubServiceImpl( override suspend fun processActivity(job: JobContextWithProps, hideoutJob: HideoutJob) { logger.debug("processActivity: ${hideoutJob.name}") when (hideoutJob) { - ReceiveFollowJob -> activityPubReceiveFollowService.receiveFollowJob( + ReceiveFollowJob -> apReceiveFollowService.receiveFollowJob( job.props as JobProps ) - DeliverPostJob -> activityPubNoteService.createNoteJob(job.props as JobProps) - DeliverReactionJob -> activityPubReactionService.reactionJob(job.props as JobProps) - DeliverRemoveReactionJob -> activityPubReactionService.removeReactionJob( + DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps) + DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps) + DeliverRemoveReactionJob -> apReactionService.removeReactionJob( job.props as JobProps ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt similarity index 67% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt index d0972608..f3b0c587 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoService.kt @@ -1,8 +1,8 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Undo -interface ActivityPubUndoService { +interface APUndoService { suspend fun receiveUndo(undo: Undo): ActivityPubResponse } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoServiceImpl.kt similarity index 87% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoServiceImpl.kt index 612146a6..381e4160 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUndoServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUndoServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ActivityPubStringResponse @@ -12,12 +12,12 @@ import org.koin.core.annotation.Single @Single @Suppress("UnsafeCallOnNullableType") -class ActivityPubUndoServiceImpl( +class APUndoServiceImpl( private val userService: IUserService, - private val activityPubUserService: ActivityPubUserService, + private val apUserService: APUserService, private val userQueryService: UserQueryService, private val transaction: Transaction -) : ActivityPubUndoService { +) : APUndoService { override suspend fun receiveUndo(undo: Undo): ActivityPubResponse { if (undo.actor == null) { return ActivityPubStringResponse(HttpStatusCode.BadRequest, "actor is null") @@ -36,7 +36,7 @@ class ActivityPubUndoServiceImpl( return ActivityPubStringResponse(HttpStatusCode.BadRequest, "object.object is null") } transaction.transaction { - activityPubUserService.fetchPerson(undo.actor!!, follow.`object`) + apUserService.fetchPerson(undo.actor!!, follow.`object`) val follower = userQueryService.findByUrl(undo.actor!!) val target = userQueryService.findByUrl(follow.`object`!!) userService.unfollow(target.id, follower.id) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt similarity index 79% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserService.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt index 3ee34667..d0c71b66 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserService.kt @@ -1,8 +1,8 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.domain.model.ap.Person -interface ActivityPubUserService { +interface APUserService { suspend fun getPersonByName(name: String): Person /** diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserServiceImpl.kt similarity index 97% rename from src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt rename to src/main/kotlin/dev/usbharu/hideout/service/ap/APUserServiceImpl.kt index 504bbdba..ec846191 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APUserServiceImpl.kt @@ -1,4 +1,4 @@ -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config @@ -19,13 +19,13 @@ import io.ktor.http.* import org.koin.core.annotation.Single @Single -class ActivityPubUserServiceImpl( +class APUserServiceImpl( private val userService: IUserService, private val httpClient: HttpClient, private val userQueryService: UserQueryService, private val transaction: Transaction ) : - ActivityPubUserService { + APUserService { override suspend fun getPersonByName(name: String): Person { val userEntity = transaction.transaction { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt index fbd204e8..0ca22f77 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt @@ -5,7 +5,7 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.repository.IPostRepository import dev.usbharu.hideout.repository.IUserRepository -import dev.usbharu.hideout.service.activitypub.ActivityPubNoteService +import dev.usbharu.hideout.service.ap.APNoteService import org.koin.core.annotation.Single import java.time.Instant @@ -13,7 +13,7 @@ import java.time.Instant class PostServiceImpl( private val postRepository: IPostRepository, private val userRepository: IUserRepository, - private val activityPubNoteService: ActivityPubNoteService + private val apNoteService: APNoteService ) : IPostService { override suspend fun createLocal(post: PostCreateDto): Post { val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found") @@ -29,7 +29,7 @@ class PostServiceImpl( repostId = null, replyId = null ) - activityPubNoteService.createNote(createPost) + apNoteService.createNote(createPost) return internalCreate(createPost) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt index b9166326..4eb42ea3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt @@ -3,13 +3,13 @@ package dev.usbharu.hideout.service.reaction import dev.usbharu.hideout.domain.model.hideout.entity.Reaction import dev.usbharu.hideout.query.ReactionQueryService import dev.usbharu.hideout.repository.ReactionRepository -import dev.usbharu.hideout.service.activitypub.ActivityPubReactionService +import dev.usbharu.hideout.service.ap.APReactionService import org.koin.core.annotation.Single @Single class ReactionServiceImpl( private val reactionRepository: ReactionRepository, - private val activityPubReactionService: ActivityPubReactionService, + private val apReactionService: APReactionService, private val reactionQueryService: ReactionQueryService ) : IReactionService { override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) { @@ -27,7 +27,7 @@ class ReactionServiceImpl( } else { val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId) reactionRepository.save(reaction) - activityPubReactionService.reaction(reaction) + apReactionService.reaction(reaction) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt index 89876aaf..febc8ac6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt @@ -9,7 +9,7 @@ import dev.usbharu.hideout.exception.UserNotFoundException import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.repository.IUserRepository -import dev.usbharu.hideout.service.activitypub.ActivityPubSendFollowService +import dev.usbharu.hideout.service.ap.APSendFollowService import org.koin.core.annotation.Single import java.time.Instant @@ -17,7 +17,7 @@ import java.time.Instant class UserService( private val userRepository: IUserRepository, private val userAuthService: IUserAuthService, - private val activityPubSendFollowService: ActivityPubSendFollowService, + private val apSendFollowService: APSendFollowService, private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService ) : @@ -77,7 +77,7 @@ class UserService( if (userRepository.findFollowRequestsById(id, followerId)) { // do-nothing } else { - activityPubSendFollowService.sendFollow(SendFollowDto(follower, user)) + apSendFollowService.sendFollow(SendFollowDto(follower, user)) } false } diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRoutingKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRoutingKtTest.kt index 9260848c..29f220bf 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRoutingKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRoutingKtTest.kt @@ -3,8 +3,8 @@ package dev.usbharu.hideout.routing.activitypub import dev.usbharu.hideout.exception.JsonParseException import dev.usbharu.hideout.plugins.configureSerialization import dev.usbharu.hideout.plugins.configureStatusPages -import dev.usbharu.hideout.service.activitypub.ActivityPubService -import dev.usbharu.hideout.service.activitypub.ActivityPubUserService +import dev.usbharu.hideout.service.ap.APService +import dev.usbharu.hideout.service.ap.APUserService import dev.usbharu.hideout.service.auth.HttpSignatureVerifyService import dev.usbharu.hideout.service.user.IUserService import io.ktor.client.request.* @@ -44,16 +44,16 @@ class InboxRoutingKtTest { val httpSignatureVerifyService = mock { on { verify(any()) } doReturn true } - val activityPubService = mock { + val apService = mock { on { parseActivity(any()) } doThrow JsonParseException() } mock() - mock() + mock() application { configureStatusPages() configureSerialization() routing { - inbox(httpSignatureVerifyService, activityPubService) + inbox(httpSignatureVerifyService, apService) } } client.post("/inbox").let { @@ -85,16 +85,16 @@ class InboxRoutingKtTest { val httpSignatureVerifyService = mock { on { verify(any()) } doReturn true } - val activityPubService = mock { + val apService = mock { on { parseActivity(any()) } doThrow JsonParseException() } mock() - mock() + mock() application { configureStatusPages() configureSerialization() routing { - inbox(httpSignatureVerifyService, activityPubService) + inbox(httpSignatureVerifyService, apService) } } client.post("/users/test/inbox").let { diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt index 3aaa4168..8fbb324f 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt @@ -12,7 +12,7 @@ import dev.usbharu.hideout.domain.model.ap.Person import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.plugins.configureSerialization import dev.usbharu.hideout.query.UserQueryService -import dev.usbharu.hideout.service.activitypub.ActivityPubUserService +import dev.usbharu.hideout.service.ap.APUserService import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.JsonLd import io.ktor.client.request.* @@ -63,14 +63,14 @@ class UsersAPTest { ) person.context = listOf("https://www.w3.org/ns/activitystreams") - val activityPubUserService = mock { + val apUserService = mock { onBlocking { getPersonByName(anyString()) } doReturn person } application { configureSerialization() routing { - usersAP(activityPubUserService, mock(), mock(), TestTransaction) + usersAP(apUserService, mock(), mock(), TestTransaction) } } client.get("/users/test") { @@ -121,14 +121,14 @@ class UsersAPTest { ) person.context = listOf("https://www.w3.org/ns/activitystreams") - val activityPubUserService = mock { + val apUserService = mock { onBlocking { getPersonByName(anyString()) } doReturn person } application { configureSerialization() routing { - usersAP(activityPubUserService, mock(), mock(), TestTransaction) + usersAP(apUserService, mock(), mock(), TestTransaction) } } client.get("/users/test") { diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt similarity index 95% rename from src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt rename to src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index c02f65ae..df22d1e1 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -1,7 +1,7 @@ @file:OptIn(ExperimentalCoroutinesApi::class) @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import dev.usbharu.hideout.config.Config import dev.usbharu.hideout.config.ConfigData @@ -25,7 +25,7 @@ import utils.JsonObjectMapper import java.time.Instant import kotlin.test.assertEquals -class ActivityPubNoteServiceImplTest { +class APNoteServiceImplTest { @Test fun `createPost 新しい投稿`() = runTest { val followers = listOf( @@ -76,7 +76,7 @@ class ActivityPubNoteServiceImplTest { } val jobQueueParentService = mock() val activityPubNoteService = - ActivityPubNoteServiceImpl( + APNoteServiceImpl( mock(), jobQueueParentService, mock(), @@ -107,7 +107,7 @@ class ActivityPubNoteServiceImplTest { respondOk() } ) - val activityPubNoteService = ActivityPubNoteServiceImpl( + val activityPubNoteService = APNoteServiceImpl( httpClient, mock(), mock(), diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt similarity index 95% rename from src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt rename to src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt index 66f7b338..6e5fbe30 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt @@ -1,7 +1,7 @@ @file:OptIn(ExperimentalCoroutinesApi::class) @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -package dev.usbharu.hideout.service.activitypub +package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config @@ -27,14 +27,14 @@ import utils.JsonObjectMapper import utils.TestTransaction import java.time.Instant -class ActivityPubReceiveFollowServiceImplTest { +class APReceiveFollowServiceImplTest { @Test fun `receiveFollow フォロー受付処理`() = runTest { val jobQueueParentService = mock { onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit } val activityPubFollowService = - ActivityPubReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction) + APReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction) activityPubFollowService.receiveFollow( Follow( emptyList(), @@ -96,7 +96,7 @@ class ActivityPubReceiveFollowServiceImplTest { ) ) - val activityPubUserService = mock { + val apUserService = mock { onBlocking { fetchPerson(anyString(), any()) } doReturn person } val userQueryService = mock { @@ -132,9 +132,9 @@ class ActivityPubReceiveFollowServiceImplTest { onBlocking { followRequest(any(), any()) } doReturn false } val activityPubFollowService = - ActivityPubReceiveFollowServiceImpl( + APReceiveFollowServiceImpl( mock(), - activityPubUserService, + apUserService, userService, HttpClient( MockEngine { httpRequestData ->