From 1b721c5a0c660227425a7028b0956fcd3d1069a0 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:09:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=81=9D=E3=81=AE=E4=BB=96=E3=81=AEJob?= =?UTF-8?q?Processor=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/like/ApReactionJobProcessor.kt | 35 +++++++++++++++ .../like/ApRemoveReactionJobProcessor.kt | 43 +++++++++++++++++++ .../objects/note/ApNoteJobProcessor.kt | 40 +++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt new file mode 100644 index 00000000..af3f2f09 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApReactionJobProcessor.kt @@ -0,0 +1,35 @@ +package dev.usbharu.hideout.activitypub.service.activity.like + +import dev.usbharu.hideout.activitypub.domain.model.Like +import dev.usbharu.hideout.activitypub.service.common.APRequestService +import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.application.external.Transaction +import dev.usbharu.hideout.core.external.job.DeliverReactionJob +import dev.usbharu.hideout.core.external.job.DeliverReactionJobParam +import dev.usbharu.hideout.core.query.UserQueryService +import dev.usbharu.hideout.core.service.job.JobProcessor + +class ApReactionJobProcessor( + private val userQueryService: UserQueryService, + private val apRequestService: APRequestService, + private val applicationConfig: ApplicationConfig, + private val transaction: Transaction +) : JobProcessor { + override suspend fun process(param: DeliverReactionJobParam): Unit = transaction.transaction { + val signer = userQueryService.findByUrl(param.actor) + + apRequestService.apPost( + param.inbox, + Like( + name = "Like", + actor = param.actor, + `object` = param.postUrl, + id = "${applicationConfig.url}/liek/note/${param.id}", + content = param.reaction + ), + signer + ) + } + + override fun job(): DeliverReactionJob = DeliverReactionJob +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt new file mode 100644 index 00000000..dadbe66e --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/ApRemoveReactionJobProcessor.kt @@ -0,0 +1,43 @@ +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.application.external.Transaction +import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob +import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJobParam +import dev.usbharu.hideout.core.query.UserQueryService +import dev.usbharu.hideout.core.service.job.JobProcessor +import java.time.Instant + +class ApRemoveReactionJobProcessor( + private val userQueryService: UserQueryService, + private val transaction: Transaction, + private val objectMapper: ObjectMapper, + private val apRequestService: APRequestService, + private val applicationConfig: ApplicationConfig +) : JobProcessor { + override suspend fun process(param: DeliverRemoveReactionJobParam): Unit = transaction.transaction { + + val like = objectMapper.readValue(param.like) + + val signer = userQueryService.findByUrl(param.actor) + + apRequestService.apPost( + param.inbox, + Undo( + name = "Undo Reaction", + actor = param.actor, + `object` = like, + id = "${applicationConfig.url}/undo/like/${param.id}", + published = Instant.now() + ), + signer + ) + } + + override fun job(): DeliverRemoveReactionJob = DeliverRemoveReactionJob +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt new file mode 100644 index 00000000..df54350d --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/ApNoteJobProcessor.kt @@ -0,0 +1,40 @@ +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.external.job.DeliverPostJobParam +import dev.usbharu.hideout.core.query.UserQueryService +import dev.usbharu.hideout.core.service.job.JobProcessor +import org.slf4j.LoggerFactory + +class ApNoteJobProcessor( + private val transaction: Transaction, + private val objectMapper: ObjectMapper, + private val userQueryService: UserQueryService, + private val apRequestService: APRequestService +) : JobProcessor { + override suspend fun process(param: DeliverPostJobParam) { + val create = objectMapper.readValue(param.create) + transaction.transaction { + val signer = userQueryService.findByUrl(param.actor) + + logger.debug("CreateNoteJob: actor: {} create: {} inbox: {}", param.actor, create, param.inbox) + + apRequestService.apPost( + param.inbox, + create, + signer + ) + } + } + + override fun job(): DeliverPostJob = DeliverPostJob + + companion object { + private val logger = LoggerFactory.getLogger(ApNoteJobProcessor::class.java) + } +}