mirror of https://github.com/usbharu/Hideout.git
refactor: 不要になったAPServiceを削除
This commit is contained in:
parent
1b721c5a0c
commit
640dff53cf
|
@ -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<ReceiveFollowJob>)
|
||||
}
|
|
@ -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<ReceiveFollowJob>) {
|
||||
transaction.transaction {
|
||||
val actor = props[ReceiveFollowJob.actor]
|
||||
val targetActor = props[ReceiveFollowJob.targetActor]
|
||||
val person = apUserService.fetchPerson(actor, targetActor)
|
||||
val follow = objectMapper.readValue<Follow>(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)
|
||||
}
|
||||
}
|
|
@ -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<DeliverReactionJob>)
|
||||
suspend fun removeReactionJob(props: JobProps<DeliverRemoveReactionJob>)
|
||||
}
|
|
@ -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<DeliverReactionJob>) {
|
||||
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<DeliverRemoveReactionJob>) {
|
||||
val inbox = props[DeliverRemoveReactionJob.inbox]
|
||||
val actor = props[DeliverRemoveReactionJob.actor]
|
||||
val like = objectMapper.readValue<Like>(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
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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 <T, R : HideoutJob<T, R>> processActivity(
|
||||
job: JobContextWithProps<R>,
|
||||
hideoutJob: HideoutJob<T, R>
|
||||
) {
|
||||
logger.debug("processActivity: ${hideoutJob.name}")
|
||||
|
||||
@Suppress("ElseCaseInsteadOfExhaustiveWhen")
|
||||
// Springで作成されるプロキシの都合上パターンマッチングが壊れるので必須
|
||||
when (hideoutJob) {
|
||||
is InboxJob -> {
|
||||
inboxJobProcessor.process(job.props as JobProps<InboxJob>)
|
||||
}
|
||||
|
||||
is ReceiveFollowJob -> {
|
||||
apReceiveFollowJobService.receiveFollowJob(
|
||||
job.props as JobProps<ReceiveFollowJob>
|
||||
)
|
||||
}
|
||||
|
||||
is DeliverPostJob -> apNoteJobService.createNoteJob(job.props as JobProps<DeliverPostJob>)
|
||||
is DeliverReactionJob -> apReactionJobService.reactionJob(job.props as JobProps<DeliverReactionJob>)
|
||||
is DeliverRemoveReactionJob -> apReactionJobService.removeReactionJob(
|
||||
job.props as JobProps<DeliverRemoveReactionJob>
|
||||
)
|
||||
|
||||
else -> {
|
||||
throw IllegalStateException("WTF")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = LoggerFactory.getLogger(ApJobServiceImpl::class.java)
|
||||
}
|
||||
}
|
|
@ -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<DeliverPostJob>)
|
||||
}
|
|
@ -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<DeliverPostJob>) {
|
||||
val actor = props[DeliverPostJob.actor]
|
||||
val create = objectMapper.readValue<Create>(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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue