diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobService.kt deleted file mode 100644 index d3c106b9..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobService.kt +++ /dev/null @@ -1,9 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.follow - -import dev.usbharu.hideout.core.external.job.ReceiveFollowJob -import kjob.core.job.JobProps - -@Deprecated("use activitypub processor") -interface APReceiveFollowJobService { - suspend fun receiveFollowJob(props: JobProps) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobServiceImpl.kt deleted file mode 100644 index 86056b69..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/follow/APReceiveFollowJobServiceImpl.kt +++ /dev/null @@ -1,62 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.follow - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.activitypub.domain.model.Accept -import dev.usbharu.hideout.activitypub.domain.model.Follow -import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.external.job.ReceiveFollowJob -import dev.usbharu.hideout.core.query.UserQueryService -import dev.usbharu.hideout.core.service.user.UserService -import kjob.core.job.JobProps -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Component - -@Component -@Deprecated("use activitypub processor") -class APReceiveFollowJobServiceImpl( - private val apUserService: APUserService, - private val userQueryService: UserQueryService, - private val apRequestService: APRequestService, - private val userService: UserService, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val transaction: Transaction -) : APReceiveFollowJobService { - override suspend fun receiveFollowJob(props: JobProps) { - transaction.transaction { - val actor = props[ReceiveFollowJob.actor] - val targetActor = props[ReceiveFollowJob.targetActor] - val person = apUserService.fetchPerson(actor, targetActor) - val follow = objectMapper.readValue(props[ReceiveFollowJob.follow]) - logger.info("START Follow from: {} to: {}", targetActor, actor) - - val signer = userQueryService.findByUrl(targetActor) - - val urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found") - - apRequestService.apPost( - url = urlString, - body = Accept( - name = "Follow", - `object` = follow, - actor = targetActor - ), - signer = signer - ) - - val targetEntity = userQueryService.findByUrl(targetActor) - val followActorEntity = - userQueryService.findByUrl(follow.actor ?: throw java.lang.IllegalArgumentException("Actor is null")) - - userService.followRequest(targetEntity.id, followActorEntity.id) - logger.info("SUCCESS Follow from: {} to: {}", targetActor, actor) - } - } - - companion object { - private val logger = LoggerFactory.getLogger(APReceiveFollowJobServiceImpl::class.java) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobService.kt deleted file mode 100644 index ca43443f..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobService.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.like - -import dev.usbharu.hideout.core.external.job.DeliverReactionJob -import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob -import kjob.core.job.JobProps - -interface ApReactionJobService { - suspend fun reactionJob(props: JobProps) - suspend fun removeReactionJob(props: JobProps) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobServiceImpl.kt deleted file mode 100644 index 5a8e088c..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobServiceImpl.kt +++ /dev/null @@ -1,66 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.like - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.activitypub.domain.model.Like -import dev.usbharu.hideout.activitypub.domain.model.Undo -import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.core.external.job.DeliverReactionJob -import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob -import dev.usbharu.hideout.core.query.UserQueryService -import kjob.core.job.JobProps -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service -import java.time.Instant - -@Service -class ApReactionJobServiceImpl( - private val userQueryService: UserQueryService, - private val apRequestService: APRequestService, - private val applicationConfig: ApplicationConfig, - @Qualifier("activitypub") private val objectMapper: ObjectMapper -) : ApReactionJobService { - override suspend fun reactionJob(props: JobProps) { - val inbox = props[DeliverReactionJob.inbox] - val actor = props[DeliverReactionJob.actor] - val postUrl = props[DeliverReactionJob.postUrl] - val id = props[DeliverReactionJob.id] - val content = props[DeliverReactionJob.reaction] - - val signer = userQueryService.findByUrl(actor) - - apRequestService.apPost( - inbox, - Like( - name = "Like", - actor = actor, - `object` = postUrl, - id = "${applicationConfig.url}/like/note/$id", - content = content - ), - signer - ) - } - - override suspend fun removeReactionJob(props: JobProps) { - val inbox = props[DeliverRemoveReactionJob.inbox] - val actor = props[DeliverRemoveReactionJob.actor] - val like = objectMapper.readValue(props[DeliverRemoveReactionJob.like]) - val id = props[DeliverRemoveReactionJob.id] - - val signer = userQueryService.findByUrl(actor) - - apRequestService.apPost( - inbox, - Undo( - name = "Undo Reaction", - actor = actor, - `object` = like, - id = "${applicationConfig.url}/undo/note/$id", - published = Instant.now() - ), - signer - ) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/ApJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/ApJobServiceImpl.kt deleted file mode 100644 index 64505017..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/ApJobServiceImpl.kt +++ /dev/null @@ -1,58 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.common - -import com.fasterxml.jackson.databind.ObjectMapper -import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowJobService -import dev.usbharu.hideout.activitypub.service.activity.like.ApReactionJobService -import dev.usbharu.hideout.activitypub.service.inbox.InboxJobProcessor -import dev.usbharu.hideout.activitypub.service.objects.note.ApNoteJobService -import dev.usbharu.hideout.core.external.job.* -import kjob.core.dsl.JobContextWithProps -import kjob.core.job.JobProps -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Service - -@Service -class ApJobServiceImpl( - private val apReceiveFollowJobService: APReceiveFollowJobService, - private val apNoteJobService: ApNoteJobService, - private val apReactionJobService: ApReactionJobService, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val inboxJobProcessor: InboxJobProcessor -) : ApJobService { - @Suppress("REDUNDANT_ELSE_IN_WHEN") - override suspend fun > processActivity( - job: JobContextWithProps, - hideoutJob: HideoutJob - ) { - logger.debug("processActivity: ${hideoutJob.name}") - - @Suppress("ElseCaseInsteadOfExhaustiveWhen") - // Springで作成されるプロキシの都合上パターンマッチングが壊れるので必須 - when (hideoutJob) { - is InboxJob -> { - inboxJobProcessor.process(job.props as JobProps) - } - - is ReceiveFollowJob -> { - apReceiveFollowJobService.receiveFollowJob( - job.props as JobProps - ) - } - - is DeliverPostJob -> apNoteJobService.createNoteJob(job.props as JobProps) - is DeliverReactionJob -> apReactionJobService.reactionJob(job.props as JobProps) - is DeliverRemoveReactionJob -> apReactionJobService.removeReactionJob( - job.props as JobProps - ) - - else -> { - throw IllegalStateException("WTF") - } - } - } - - companion object { - private val logger = LoggerFactory.getLogger(ApJobServiceImpl::class.java) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobService.kt deleted file mode 100644 index ad7ea01e..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.objects.note - -import dev.usbharu.hideout.core.external.job.DeliverPostJob -import kjob.core.job.JobProps - -interface ApNoteJobService { - suspend fun createNoteJob(props: JobProps) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobServiceImpl.kt deleted file mode 100644 index 1e3dc801..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobServiceImpl.kt +++ /dev/null @@ -1,41 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.objects.note - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.activitypub.domain.model.Create -import dev.usbharu.hideout.activitypub.service.common.APRequestService -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.external.job.DeliverPostJob -import dev.usbharu.hideout.core.query.UserQueryService -import kjob.core.job.JobProps -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Qualifier -import org.springframework.stereotype.Component - -@Component -class ApNoteJobServiceImpl( - private val userQueryService: UserQueryService, - private val apRequestService: APRequestService, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val transaction: Transaction -) : ApNoteJobService { - override suspend fun createNoteJob(props: JobProps) { - val actor = props[DeliverPostJob.actor] - val create = objectMapper.readValue(props[DeliverPostJob.create]) - transaction.transaction { - val signer = userQueryService.findByUrl(actor) - - val inbox = props[DeliverPostJob.inbox] - logger.debug("createNoteJob: actor={}, create={}, inbox={}", actor, create, inbox) - apRequestService.apPost( - inbox, - create, - signer - ) - } - } - - companion object { - private val logger = LoggerFactory.getLogger(ApNoteJobServiceImpl::class.java) - } -}