mirror of https://github.com/usbharu/Hideout.git
refactor: jobを別のクラスに切り出し
This commit is contained in:
parent
1118ca30fb
commit
ab25e136dd
|
@ -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<DeliverPostJob>)
|
||||
|
||||
|
||||
@Cacheable("fetchNote")
|
||||
fun fetchNoteAsync(url: String, targetActor: String? = null): Deferred<Note> {
|
||||
|
@ -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<DeliverPostJob>) {
|
||||
val actor = props[DeliverPostJob.actor]
|
||||
val postEntity = objectMapper.readValue<Post>(props[DeliverPostJob.post])
|
||||
val mediaList =
|
||||
objectMapper.readValue<List<dev.usbharu.hideout.domain.model.hideout.entity.Media>>(
|
||||
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)
|
||||
|
|
|
@ -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<DeliverReactionJob>)
|
||||
suspend fun removeReactionJob(props: JobProps<DeliverRemoveReactionJob>)
|
||||
}
|
||||
|
||||
@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<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 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ReceiveFollowJob>)
|
||||
}
|
||||
|
||||
@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<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(APReceiveFollowServiceImpl::class.java)
|
||||
}
|
||||
|
|
|
@ -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<ReceiveFollowJob>
|
||||
)
|
||||
}
|
||||
|
||||
is DeliverPostJob -> apNoteService.createNoteJob(job.props as JobProps<DeliverPostJob>)
|
||||
is DeliverReactionJob -> apReactionService.reactionJob(job.props as JobProps<DeliverReactionJob>)
|
||||
is DeliverRemoveReactionJob -> apReactionService.removeReactionJob(
|
||||
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>
|
||||
)
|
||||
|
||||
|
|
|
@ -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<ReceiveFollowJob>)
|
||||
}
|
|
@ -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<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)
|
||||
}
|
||||
}
|
|
@ -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<DeliverPostJob>)
|
||||
}
|
|
@ -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<DeliverPostJob>) {
|
||||
val actor = props[DeliverPostJob.actor]
|
||||
val postEntity = objectMapper.readValue<Post>(props[DeliverPostJob.post])
|
||||
val mediaList =
|
||||
objectMapper.readValue<List<dev.usbharu.hideout.domain.model.hideout.entity.Media>>(
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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<DeliverReactionJob>)
|
||||
suspend fun removeReactionJob(props: JobProps<DeliverRemoveReactionJob>)
|
||||
}
|
|
@ -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<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 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
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue