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) + } +}