mirror of https://github.com/usbharu/Hideout.git
feat: inboxをジョブキューに載せた
This commit is contained in:
parent
f4d4380c7f
commit
e4eaef7277
|
@ -2,16 +2,17 @@ package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.exception.JsonParseException
|
import dev.usbharu.hideout.activitypub.domain.exception.JsonParseException
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
|
||||||
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
||||||
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubStringResponse
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.accept.APAcceptService
|
import dev.usbharu.hideout.activitypub.service.activity.accept.APAcceptService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.create.APCreateService
|
import dev.usbharu.hideout.activitypub.service.activity.create.APCreateService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.delete.APReceiveDeleteService
|
import dev.usbharu.hideout.activitypub.service.activity.delete.APReceiveDeleteService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowService
|
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.like.APLikeService
|
import dev.usbharu.hideout.activitypub.service.activity.like.APLikeService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.undo.APUndoService
|
import dev.usbharu.hideout.activitypub.service.activity.undo.APUndoService
|
||||||
|
import dev.usbharu.hideout.core.external.job.InboxJob
|
||||||
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.beans.factory.annotation.Qualifier
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
@ -182,7 +183,8 @@ class APServiceImpl(
|
||||||
private val apCreateService: APCreateService,
|
private val apCreateService: APCreateService,
|
||||||
private val apLikeService: APLikeService,
|
private val apLikeService: APLikeService,
|
||||||
private val apReceiveDeleteService: APReceiveDeleteService,
|
private val apReceiveDeleteService: APReceiveDeleteService,
|
||||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
||||||
|
private val jobQueueParentService: JobQueueParentService
|
||||||
) : APService {
|
) : APService {
|
||||||
|
|
||||||
val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java)
|
val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java)
|
||||||
|
@ -227,20 +229,10 @@ class APServiceImpl(
|
||||||
@Suppress("CyclomaticComplexMethod", "NotImplementedDeclaration")
|
@Suppress("CyclomaticComplexMethod", "NotImplementedDeclaration")
|
||||||
override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse {
|
override suspend fun processActivity(json: String, type: ActivityType): ActivityPubResponse {
|
||||||
logger.debug("process activity: {}", type)
|
logger.debug("process activity: {}", type)
|
||||||
return when (type) {
|
jobQueueParentService.schedule(InboxJob) {
|
||||||
ActivityType.Accept -> apAcceptService.receiveAccept(objectMapper.readValue(json))
|
props[it.json] = json
|
||||||
ActivityType.Follow ->
|
props[it.type] = type.name
|
||||||
apReceiveFollowService
|
|
||||||
.receiveFollow(objectMapper.readValue(json, Follow::class.java))
|
|
||||||
|
|
||||||
ActivityType.Create -> apCreateService.receiveCreate(objectMapper.readValue(json))
|
|
||||||
ActivityType.Like -> apLikeService.receiveLike(objectMapper.readValue(json))
|
|
||||||
ActivityType.Undo -> apUndoService.receiveUndo(objectMapper.readValue(json))
|
|
||||||
ActivityType.Delete -> apReceiveDeleteService.receiveDelete(objectMapper.readValue(json))
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
throw IllegalArgumentException("$type is not supported.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return ActivityPubStringResponse(message = "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,37 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.accept.APAcceptServiceImpl
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.create.APCreateServiceImpl
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.delete.APReceiveDeleteServiceImpl
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowJobService
|
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowJobService
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowServiceImpl
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.like.APLikeServiceImpl
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.like.ApReactionJobService
|
import dev.usbharu.hideout.activitypub.service.activity.like.ApReactionJobService
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.undo.APUndoServiceImpl
|
||||||
import dev.usbharu.hideout.activitypub.service.objects.note.ApNoteJobService
|
import dev.usbharu.hideout.activitypub.service.objects.note.ApNoteJobService
|
||||||
import dev.usbharu.hideout.core.external.job.*
|
import dev.usbharu.hideout.core.external.job.*
|
||||||
|
|
||||||
import kjob.core.dsl.JobContextWithProps
|
import kjob.core.dsl.JobContextWithProps
|
||||||
import kjob.core.job.JobProps
|
import kjob.core.job.JobProps
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApJobServiceImpl(
|
class ApJobServiceImpl(
|
||||||
private val apReceiveFollowJobService: APReceiveFollowJobService,
|
private val apReceiveFollowJobService: APReceiveFollowJobService,
|
||||||
private val apNoteJobService: ApNoteJobService,
|
private val apNoteJobService: ApNoteJobService,
|
||||||
private val apReactionJobService: ApReactionJobService
|
private val apReactionJobService: ApReactionJobService,
|
||||||
|
private val APAcceptServiceImpl: APAcceptServiceImpl,
|
||||||
|
private val APReceiveFollowServiceImpl: APReceiveFollowServiceImpl,
|
||||||
|
private val APCreateServiceImpl: APCreateServiceImpl,
|
||||||
|
private val APLikeServiceImpl: APLikeServiceImpl,
|
||||||
|
private val APUndoServiceImpl: APUndoServiceImpl,
|
||||||
|
private val APReceiveDeleteServiceImpl: APReceiveDeleteServiceImpl,
|
||||||
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
||||||
) : ApJobService {
|
) : ApJobService {
|
||||||
@Suppress("REDUNDANT_ELSE_IN_WHEN")
|
@Suppress("REDUNDANT_ELSE_IN_WHEN")
|
||||||
override suspend fun <T : HideoutJob> processActivity(job: JobContextWithProps<T>, hideoutJob: HideoutJob) {
|
override suspend fun <T : HideoutJob> processActivity(job: JobContextWithProps<T>, hideoutJob: HideoutJob) {
|
||||||
|
@ -22,6 +40,26 @@ class ApJobServiceImpl(
|
||||||
@Suppress("ElseCaseInsteadOfExhaustiveWhen")
|
@Suppress("ElseCaseInsteadOfExhaustiveWhen")
|
||||||
// Springで作成されるプロキシの都合上パターンマッチングが壊れるので必須
|
// Springで作成されるプロキシの都合上パターンマッチングが壊れるので必須
|
||||||
when (hideoutJob) {
|
when (hideoutJob) {
|
||||||
|
is InboxJob -> {
|
||||||
|
val typeString = (job.props as JobProps<InboxJob>)[InboxJob.type]
|
||||||
|
val json = (job.props as JobProps<InboxJob>)[InboxJob.json]
|
||||||
|
val type = ActivityType.valueOf(typeString)
|
||||||
|
when (type) {
|
||||||
|
ActivityType.Accept -> APAcceptServiceImpl.receiveAccept(objectMapper.readValue(json))
|
||||||
|
ActivityType.Follow ->
|
||||||
|
APReceiveFollowServiceImpl
|
||||||
|
.receiveFollow(objectMapper.readValue(json, Follow::class.java))
|
||||||
|
|
||||||
|
ActivityType.Create -> APCreateServiceImpl.receiveCreate(objectMapper.readValue(json))
|
||||||
|
ActivityType.Like -> APLikeServiceImpl.receiveLike(objectMapper.readValue(json))
|
||||||
|
ActivityType.Undo -> APUndoServiceImpl.receiveUndo(objectMapper.readValue(json))
|
||||||
|
ActivityType.Delete -> APReceiveDeleteServiceImpl.receiveDelete(objectMapper.readValue(json))
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
throw IllegalArgumentException("$type is not supported.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
is ReceiveFollowJob -> {
|
is ReceiveFollowJob -> {
|
||||||
apReceiveFollowJobService.receiveFollowJob(
|
apReceiveFollowJobService.receiveFollowJob(
|
||||||
job.props as JobProps<ReceiveFollowJob>
|
job.props as JobProps<ReceiveFollowJob>
|
||||||
|
|
|
@ -36,3 +36,9 @@ object DeliverRemoveReactionJob : HideoutJob("DeliverRemoveReactionJob") {
|
||||||
val actor: Prop<DeliverRemoveReactionJob, String> = string("actor")
|
val actor: Prop<DeliverRemoveReactionJob, String> = string("actor")
|
||||||
val like: Prop<DeliverRemoveReactionJob, String> = string("like")
|
val like: Prop<DeliverRemoveReactionJob, String> = string("like")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
object InboxJob : HideoutJob("InboxJob") {
|
||||||
|
val json = string("json")
|
||||||
|
val type = string("type")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue