From ab25e136dd90268340f11e1f4d6eef202b1f6844 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:22:18 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20job=E3=82=92=E5=88=A5=E3=81=AE?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AB=E5=88=87=E3=82=8A=E5=87=BA?= =?UTF-8?q?=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/service/ap/APNoteService.kt | 46 +------------ .../hideout/service/ap/APReactionService.kt | 54 +-------------- .../service/ap/APReceiveFollowService.kt | 45 +------------ .../usbharu/hideout/service/ap/APService.kt | 18 +++-- .../ap/job/APReceiveFollowJobService.kt | 8 +++ .../ap/job/APReceiveFollowJobServiceImpl.kt | 61 +++++++++++++++++ .../service/ap/job/ApNoteJobService.kt | 8 +++ .../service/ap/job/ApNoteJobServiceImpl.kt | 67 +++++++++++++++++++ .../service/ap/job/ApReactionJobService.kt | 10 +++ .../ap/job/ApReactionJobServiceImpl.kt | 65 ++++++++++++++++++ .../service/ap/APNoteServiceImplTest.kt | 7 -- .../ap/APReceiveFollowServiceImplTest.kt | 15 +---- 12 files changed, 236 insertions(+), 168 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobServiceImpl.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobServiceImpl.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobServiceImpl.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 9f4f87e2..6ff134d1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -1,10 +1,6 @@ package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.config.ApplicationConfig -import dev.usbharu.hideout.domain.model.ap.Create -import dev.usbharu.hideout.domain.model.ap.Document import dev.usbharu.hideout.domain.model.ap.Note import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.Visibility @@ -19,12 +15,10 @@ import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.repository.PostRepository import dev.usbharu.hideout.service.ap.resource.APResourceResolveService import dev.usbharu.hideout.service.ap.resource.resolve -import dev.usbharu.hideout.service.core.Transaction import dev.usbharu.hideout.service.job.JobQueueParentService import dev.usbharu.hideout.service.post.PostCreateInterceptor import dev.usbharu.hideout.service.post.PostService import io.ktor.client.plugins.* -import kjob.core.job.JobProps import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers @@ -40,7 +34,7 @@ import java.time.Instant interface APNoteService { suspend fun createNote(post: Post) - suspend fun createNoteJob(props: JobProps) + @Cacheable("fetchNote") fun fetchNoteAsync(url: String, targetActor: String? = null): Deferred { @@ -66,12 +60,9 @@ class APNoteServiceImpl( private val postQueryService: PostQueryService, private val mediaQueryService: MediaQueryService, @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val applicationConfig: ApplicationConfig, private val postService: PostService, private val apResourceResolveService: APResourceResolveService, - private val apRequestService: APRequestService, - private val postBuilder: Post.PostBuilder, - private val transaction: Transaction + private val postBuilder: Post.PostBuilder ) : APNoteService, PostCreateInterceptor { @@ -104,40 +95,7 @@ class APNoteServiceImpl( logger.debug("SUCCESS Create Local Note ${post.url}") } - override suspend fun createNoteJob(props: JobProps) { - val actor = props[DeliverPostJob.actor] - val postEntity = objectMapper.readValue(props[DeliverPostJob.post]) - val mediaList = - objectMapper.readValue>( - props[DeliverPostJob.media] - ) - val note = Note( - name = "Note", - id = postEntity.url, - attributedTo = actor, - content = postEntity.text, - published = Instant.ofEpochMilli(postEntity.createdAt).toString(), - to = listOf(public, "$actor/follower"), - attachment = mediaList.map { Document(mediaType = "image/jpeg", url = it.url) } - ) - val inbox = props[DeliverPostJob.inbox] - logger.debug("createNoteJob: actor={}, note={}, inbox={}", actor, postEntity, inbox) - - transaction.transaction { - val signer = userQueryService.findByUrl(actor) - apRequestService.apPost( - inbox, - Create( - name = "Create Note", - `object` = note, - actor = note.attributedTo, - id = "${applicationConfig.url}/create/note/${postEntity.id}" - ), - signer - ) - } - } override suspend fun fetchNote(url: String, targetActor: String?): Note { logger.debug("START Fetch Note url: {}", url) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt index 5a8cb788..c097d3fb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReactionService.kt @@ -1,10 +1,6 @@ package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.config.ApplicationConfig -import dev.usbharu.hideout.domain.model.ap.Like -import dev.usbharu.hideout.domain.model.ap.Undo 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 @@ -12,16 +8,12 @@ import dev.usbharu.hideout.query.FollowerQueryService import dev.usbharu.hideout.query.PostQueryService import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.service.job.JobQueueParentService -import kjob.core.job.JobProps import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service -import java.time.Instant interface APReactionService { suspend fun reaction(like: Reaction) suspend fun removeReaction(like: Reaction) - suspend fun reactionJob(props: JobProps) - suspend fun removeReactionJob(props: JobProps) } @Service @@ -30,9 +22,7 @@ class APReactionServiceImpl( private val userQueryService: UserQueryService, private val followerQueryService: FollowerQueryService, private val postQueryService: PostQueryService, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val applicationConfig: ApplicationConfig, - private val apRequestService: APRequestService + @Qualifier("activitypub") private val objectMapper: ObjectMapper ) : APReactionService { override suspend fun reaction(like: Reaction) { val followers = followerQueryService.findFollowersById(like.userId) @@ -64,46 +54,4 @@ class APReactionServiceImpl( } } } - - 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 signer = userQueryService.findByUrl(actor) - - apRequestService.apPost( - inbox, - Undo( - name = "Undo Reaction", - actor = actor, - `object` = like, - id = "${applicationConfig.url}/undo/note/${like.id}", - published = Instant.now() - ), - signer - ) - } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt index d6d237e8..e53c5130 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowService.kt @@ -1,36 +1,24 @@ package dev.usbharu.hideout.service.ap import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ActivityPubStringResponse -import dev.usbharu.hideout.domain.model.ap.Accept import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob -import dev.usbharu.hideout.query.UserQueryService -import dev.usbharu.hideout.service.core.Transaction import dev.usbharu.hideout.service.job.JobQueueParentService -import dev.usbharu.hideout.service.user.UserService import io.ktor.http.* -import kjob.core.job.JobProps import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Qualifier import org.springframework.stereotype.Service interface APReceiveFollowService { suspend fun receiveFollow(follow: Follow): ActivityPubResponse - suspend fun receiveFollowJob(props: JobProps) } @Service class APReceiveFollowServiceImpl( private val jobQueueParentService: JobQueueParentService, - private val apUserService: APUserService, - private val userService: UserService, - private val userQueryService: UserQueryService, - private val transaction: Transaction, - @Qualifier("activitypub") private val objectMapper: ObjectMapper, - private val apRequestService: APRequestService + @Qualifier("activitypub") private val objectMapper: ObjectMapper ) : APReceiveFollowService { override suspend fun receiveFollow(follow: Follow): ActivityPubResponse { logger.info("FOLLOW from: {} to: {}", follow.actor, follow.`object`) @@ -42,37 +30,6 @@ class APReceiveFollowServiceImpl( return ActivityPubStringResponse(HttpStatusCode.OK, "{}", ContentType.Application.Json) } - 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(APReceiveFollowServiceImpl::class.java) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt index 9ea98a66..73fcd83b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APService.kt @@ -7,6 +7,9 @@ import dev.usbharu.hideout.domain.model.ActivityPubResponse import dev.usbharu.hideout.domain.model.ap.Follow import dev.usbharu.hideout.domain.model.job.* import dev.usbharu.hideout.exception.JsonParseException +import dev.usbharu.hideout.service.ap.job.APReceiveFollowJobService +import dev.usbharu.hideout.service.ap.job.ApNoteJobService +import dev.usbharu.hideout.service.ap.job.ApReactionJobService import kjob.core.dsl.JobContextWithProps import kjob.core.job.JobProps import org.slf4j.Logger @@ -176,13 +179,14 @@ enum class ExtendedVocabulary { @Service 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, - @Qualifier("activitypub") private val objectMapper: ObjectMapper + @Qualifier("activitypub") private val objectMapper: ObjectMapper, + private val apReceiveFollowJobService: APReceiveFollowJobService, + private val apNoteJobService: ApNoteJobService, + private val apReactionJobService: ApReactionJobService ) : APService { val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java) @@ -237,14 +241,14 @@ class APServiceImpl( // Springで作成されるプロキシの都合上パターンマッチングが壊れるので必須 when (hideoutJob) { is ReceiveFollowJob -> { - apReceiveFollowService.receiveFollowJob( + apReceiveFollowJobService.receiveFollowJob( job.props as JobProps ) } - is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps) - is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps) - is DeliverRemoveReactionJob -> apReactionService.removeReactionJob( + is DeliverPostJob -> apNoteJobService.createNoteJob(job.props as JobProps) + is DeliverReactionJob -> apReactionJobService.reactionJob(job.props as JobProps) + is DeliverRemoveReactionJob -> apReactionJobService.removeReactionJob( job.props as JobProps ) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobService.kt new file mode 100644 index 00000000..0aa35a9c --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobService.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.service.ap.job + +import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob +import kjob.core.job.JobProps + +interface APReceiveFollowJobService { + suspend fun receiveFollowJob(props: JobProps) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobServiceImpl.kt new file mode 100644 index 00000000..cc12b0b1 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/APReceiveFollowJobServiceImpl.kt @@ -0,0 +1,61 @@ +package dev.usbharu.hideout.service.ap.job + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import dev.usbharu.hideout.domain.model.ap.Accept +import dev.usbharu.hideout.domain.model.ap.Follow +import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob +import dev.usbharu.hideout.query.UserQueryService +import dev.usbharu.hideout.service.ap.APRequestService +import dev.usbharu.hideout.service.ap.APUserService +import dev.usbharu.hideout.service.core.Transaction +import dev.usbharu.hideout.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 +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/service/ap/job/ApNoteJobService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobService.kt new file mode 100644 index 00000000..35d7e3cb --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobService.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.service.ap.job + +import dev.usbharu.hideout.domain.model.job.DeliverPostJob +import kjob.core.job.JobProps + +interface ApNoteJobService { + suspend fun createNoteJob(props: JobProps) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobServiceImpl.kt new file mode 100644 index 00000000..8146a597 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApNoteJobServiceImpl.kt @@ -0,0 +1,67 @@ +package dev.usbharu.hideout.service.ap.job + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.domain.model.ap.Create +import dev.usbharu.hideout.domain.model.ap.Document +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 dev.usbharu.hideout.query.UserQueryService +import dev.usbharu.hideout.service.ap.APNoteServiceImpl +import dev.usbharu.hideout.service.ap.APRequestService +import dev.usbharu.hideout.service.core.Transaction +import kjob.core.job.JobProps +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.stereotype.Component +import java.time.Instant + +@Component +class ApNoteJobServiceImpl( + private val userQueryService: UserQueryService, + private val apRequestService: APRequestService, + @Qualifier("activitypub") private val objectMapper: ObjectMapper, + private val transaction: Transaction, + private val applicationConfig: ApplicationConfig +) : ApNoteJobService { + override suspend fun createNoteJob(props: JobProps) { + val actor = props[DeliverPostJob.actor] + val postEntity = objectMapper.readValue(props[DeliverPostJob.post]) + val mediaList = + objectMapper.readValue>( + props[DeliverPostJob.media] + ) + val note = Note( + name = "Note", + id = postEntity.url, + attributedTo = actor, + content = postEntity.text, + published = Instant.ofEpochMilli(postEntity.createdAt).toString(), + to = listOf(APNoteServiceImpl.public, "$actor/follower"), + attachment = mediaList.map { Document(mediaType = "image/jpeg", url = it.url) } + + ) + val inbox = props[DeliverPostJob.inbox] + logger.debug("createNoteJob: actor={}, note={}, inbox={}", actor, postEntity, inbox) + + transaction.transaction { + val signer = userQueryService.findByUrl(actor) + apRequestService.apPost( + inbox, + Create( + name = "Create Note", + `object` = note, + actor = note.attributedTo, + id = "${applicationConfig.url}/create/note/${postEntity.id}" + ), + signer + ) + } + } + + companion object { + private val logger = LoggerFactory.getLogger(ApNoteJobServiceImpl::class.java) + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobService.kt new file mode 100644 index 00000000..90a029ae --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobService.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.service.ap.job + +import dev.usbharu.hideout.domain.model.job.DeliverReactionJob +import dev.usbharu.hideout.domain.model.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/service/ap/job/ApReactionJobServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobServiceImpl.kt new file mode 100644 index 00000000..45736662 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/job/ApReactionJobServiceImpl.kt @@ -0,0 +1,65 @@ +package dev.usbharu.hideout.service.ap.job + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import dev.usbharu.hideout.config.ApplicationConfig +import dev.usbharu.hideout.domain.model.ap.Like +import dev.usbharu.hideout.domain.model.ap.Undo +import dev.usbharu.hideout.domain.model.job.DeliverReactionJob +import dev.usbharu.hideout.domain.model.job.DeliverRemoveReactionJob +import dev.usbharu.hideout.query.UserQueryService +import dev.usbharu.hideout.service.ap.APRequestService +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 signer = userQueryService.findByUrl(actor) + + apRequestService.apPost( + inbox, + Undo( + name = "Undo Reaction", + actor = actor, + `object` = like, + id = "${applicationConfig.url}/undo/note/${like.id}", + published = Instant.now() + ), + signer + ) + } +} diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index 628a8eff..089acdca 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -24,7 +24,6 @@ import org.mockito.Mockito.anyLong import org.mockito.Mockito.eq import org.mockito.kotlin.* import utils.JsonObjectMapper.objectMapper -import utils.TestApplicationConfig.testApplicationConfig import java.net.URL import java.time.Instant import kotlin.test.assertEquals @@ -104,11 +103,8 @@ class APNoteServiceImplTest { postQueryService = mock(), mediaQueryService = mediaQueryService, objectMapper = objectMapper, - applicationConfig = testApplicationConfig, postService = mock(), apResourceResolveService = mock(), - apRequestService = mock(), - transaction = mock(), postBuilder = postBuilder ) val postEntity = postBuilder.of( @@ -147,11 +143,8 @@ class APNoteServiceImplTest { postQueryService = mock(), mediaQueryService = mediaQueryService, objectMapper = objectMapper, - applicationConfig = testApplicationConfig, postService = mock(), apResourceResolveService = mock(), - apRequestService = mock(), - transaction = mock(), postBuilder = postBuilder ) activityPubNoteService.createNoteJob( diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt index 38c266e1..d91761a2 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* import utils.JsonObjectMapper.objectMapper -import utils.TestTransaction import java.net.URL import java.time.Instant @@ -42,12 +41,7 @@ class APReceiveFollowServiceImplTest { val activityPubFollowService = APReceiveFollowServiceImpl( jobQueueParentService, - mock(), - mock(), - mock(), - TestTransaction, - objectMapper, - mock() + objectMapper ) activityPubFollowService.receiveFollow( Follow( @@ -153,12 +147,7 @@ class APReceiveFollowServiceImplTest { val activityPubFollowService = APReceiveFollowServiceImpl( mock(), - apUserService, - userService, - userQueryService, - TestTransaction, - objectMapper, - mock() + objectMapper ) activityPubFollowService.receiveFollowJob( JobProps(