From 55783fefa2cea6ef16017a2df25985cc55689cae Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 11 Dec 2023 01:22:17 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E6=89=BF=E8=AA=8D=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accept/APDeliverAcceptJobProcessor.kt | 6 ++- .../activity/accept/ApSendAcceptService.kt | 4 +- .../reject/APDeliverRejectJobProcessor.kt | 6 ++- .../undo/APDeliverUndoJobProcessor.kt | 6 ++- .../service/activity/undo/APUndoProcessor.kt | 11 +++++ .../core/external/job/DeliverAcceptJob.kt | 3 +- .../core/external/job/DeliverRejectJob.kt | 2 +- .../core/external/job/DeliverUndoJob.kt | 2 +- .../hideout/core/external/job/HideoutJob.kt | 2 +- .../kjobexposed/KJobJobQueueWorkerService.kt | 3 ++ .../relationship/RelationshipService.kt | 9 ++++ .../relationship/RelationshipServiceImpl.kt | 18 ++++++-- src/main/resources/logback.xml | 4 +- .../RelationshipServiceImplTest.kt | 42 +++++++++---------- 14 files changed, 80 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APDeliverAcceptJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APDeliverAcceptJobProcessor.kt index e9d240a9..343dcb50 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APDeliverAcceptJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APDeliverAcceptJobProcessor.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.activitypub.service.activity.accept import dev.usbharu.hideout.activitypub.service.common.APRequestService +import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.external.job.DeliverAcceptJob import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam import dev.usbharu.hideout.core.query.UserQueryService @@ -11,10 +12,11 @@ import org.springframework.stereotype.Service class APDeliverAcceptJobProcessor( private val apRequestService: APRequestService, private val userQueryService: UserQueryService, - private val deliverAcceptJob: DeliverAcceptJob + private val deliverAcceptJob: DeliverAcceptJob, + private val transaction: Transaction ) : JobProcessor { - override suspend fun process(param: DeliverAcceptJobParam) { + override suspend fun process(param: DeliverAcceptJobParam): Unit = transaction.transaction { apRequestService.apPost(param.inbox, param.accept, userQueryService.findById(param.signer)) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApSendAcceptService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApSendAcceptService.kt index 573e7104..ab364c06 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApSendAcceptService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/ApSendAcceptService.kt @@ -21,8 +21,8 @@ class ApSendAcceptServiceImpl( val deliverAcceptJobParam = DeliverAcceptJobParam( Accept( apObject = Follow( - apObject = target.url, - actor = user.url + apObject = user.url, + actor = target.url ), actor = user.url ), diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/reject/APDeliverRejectJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/reject/APDeliverRejectJobProcessor.kt index 8e271288..575a34de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/reject/APDeliverRejectJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/reject/APDeliverRejectJobProcessor.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.activitypub.service.activity.reject import dev.usbharu.hideout.activitypub.service.common.APRequestService +import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.external.job.DeliverRejectJob import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam import dev.usbharu.hideout.core.query.UserQueryService @@ -11,10 +12,11 @@ import org.springframework.stereotype.Component class APDeliverRejectJobProcessor( private val apRequestService: APRequestService, private val userQueryService: UserQueryService, - private val deliverRejectJob: DeliverRejectJob + private val deliverRejectJob: DeliverRejectJob, + private val transaction: Transaction ) : JobProcessor { - override suspend fun process(param: DeliverRejectJobParam) { + override suspend fun process(param: DeliverRejectJobParam): Unit = transaction.transaction { apRequestService.apPost(param.inbox, param.reject, userQueryService.findById(param.signer)) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APDeliverUndoJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APDeliverUndoJobProcessor.kt index 800f6ca5..d5f1fec2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APDeliverUndoJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APDeliverUndoJobProcessor.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.activitypub.service.activity.undo import dev.usbharu.hideout.activitypub.service.common.APRequestService +import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.external.job.DeliverUndoJob import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam import dev.usbharu.hideout.core.query.UserQueryService @@ -11,9 +12,10 @@ import org.springframework.stereotype.Service class APDeliverUndoJobProcessor( private val deliverUndoJob: DeliverUndoJob, private val apRequestService: APRequestService, - private val userQueryService: UserQueryService + private val userQueryService: UserQueryService, + private val transaction: Transaction ) : JobProcessor { - override suspend fun process(param: DeliverUndoJobParam) { + override suspend fun process(param: DeliverUndoJobParam): Unit = transaction.transaction { apRequestService.apPost(param.inbox, param.undo, userQueryService.findById(param.signer)) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index f6a3ff0e..7e5b8583 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.undo +import dev.usbharu.hideout.activitypub.domain.model.Block import dev.usbharu.hideout.activitypub.domain.model.Follow import dev.usbharu.hideout.activitypub.domain.model.Undo import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor @@ -44,6 +45,16 @@ class APUndoProcessor( return } + "Block" -> { + val block = undo.apObject as Block + + val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second + val target = userQueryService.findByUrl(block.apObject) + + relationshipService.unblock(blocker.id, target.id) + return + } + else -> {} } TODO() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptJob.kt index ad002175..0de9fafb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverAcceptJob.kt @@ -14,7 +14,8 @@ data class DeliverAcceptJobParam( ) @Component -class DeliverAcceptJob(private val objectMapper: ObjectMapper) : HideoutJob() { +class DeliverAcceptJob(private val objectMapper: ObjectMapper) : + HideoutJob("DeliverAcceptJob") { val accept = string("accept") val inbox = string("inbox") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt index 9f923534..c52dc5ab 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverRejectJob.kt @@ -16,7 +16,7 @@ data class DeliverRejectJobParam( @Component class DeliverRejectJob(@Qualifier("activitypub") private val objectMapper: ObjectMapper) : - HideoutJob() { + HideoutJob("DeliverRejectJob") { val reject = string("reject") val inbox = string("inbox") val signer = long("signer") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoJob.kt index b8ad9088..50efd716 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/DeliverUndoJob.kt @@ -16,7 +16,7 @@ data class DeliverUndoJobParam( @Component class DeliverUndoJob(@Qualifier("activitypub") private val objectMapper: ObjectMapper) : - HideoutJob() { + HideoutJob("DeliverUndoJob") { val undo = string("undo") val inbox = string("inbox") diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt index d201fc9a..3efdf09d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt @@ -7,7 +7,7 @@ import kjob.core.dsl.ScheduleContext import kjob.core.job.JobProps import org.springframework.stereotype.Component -abstract class HideoutJob>(name: String = "") : Job(name) { +abstract class HideoutJob>(name: String) : Job(name) { abstract fun convert(value: @UnsafeVariance T): ScheduleContext<@UnsafeVariance R>.(@UnsafeVariance R) -> Unit fun convertUnsafe(props: JobProps<*>): T = convert(props as JobProps) abstract fun convert(props: JobProps<@UnsafeVariance R>): T diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueWorkerService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueWorkerService.kt index ff8e07e8..9bd19351 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueWorkerService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobexposed/KJobJobQueueWorkerService.kt @@ -40,6 +40,9 @@ class KJobJobQueueWorkerService(private val jobQueueProcessorList: List - %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{x-request-id}] %logger{36} - %msg%n + %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{x-request-id}] [%X{x-job-id}] %logger{36} - + %msg%n + diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt index cda067c5..0389b895 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt @@ -140,10 +140,10 @@ class RelationshipServiceImplTest { @Test fun `followRequest 既にフォローしている場合は念の為フォロー承認を自動で行う`() = runTest { - val localUser = UserBuilder.localUserOf(domain = "example.com") - whenever(userQueryService.findById(eq(1234))).doReturn(localUser) val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com") - whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser) + whenever(userQueryService.findById(eq(1234))).doReturn(remoteUser) + val localUser = UserBuilder.localUserOf(domain = "example.com") + whenever(userQueryService.findById(eq(5678))).doReturn(localUser) whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( Relationship( userId = 1234, @@ -258,10 +258,10 @@ class RelationshipServiceImplTest { fun `acceptFollowRequest ローカルユーザーの場合永続化される`() = runTest { whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com")) - whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( + whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn( Relationship( - userId = 1234, - targetUserId = 5678, + userId = 5678, + targetUserId = 1234, following = false, blocking = false, muting = false, @@ -274,8 +274,8 @@ class RelationshipServiceImplTest { verify(relationshipRepository, times(1)).save( Relationship( - userId = 1234, - targetUserId = 5678, + userId = 5678, + targetUserId = 1234, following = true, blocking = false, muting = false, @@ -294,10 +294,10 @@ class RelationshipServiceImplTest { val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com") whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser) - whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( + whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn( Relationship( - userId = 1234, - targetUserId = 5678, + userId = 5678, + targetUserId = 1234, following = false, blocking = false, muting = false, @@ -311,8 +311,8 @@ class RelationshipServiceImplTest { verify(relationshipRepository, times(1)).save( eq( Relationship( - userId = 1234, - targetUserId = 5678, + userId = 5678, + targetUserId = 1234, following = true, blocking = false, muting = false, @@ -334,9 +334,9 @@ class RelationshipServiceImplTest { @Test fun `acceptFollowRequest フォローリクエストが存在せずforceがfalseのとき何もしない`() = runTest { - whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( + whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn( Relationship( - 1234, 5678, false, false, false, false, false + 5678, 1234, false, false, false, false, false ) ) @@ -349,9 +349,9 @@ class RelationshipServiceImplTest { fun `acceptFollowRequest フォローリクエストが存在せずforceがtrueのときフォローを承認する`() = runTest { whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com")) - whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( + whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn( Relationship( - 1234, 5678, false, false, false, false, false + 5678, 1234, false, false, false, false, false ) ) @@ -360,8 +360,8 @@ class RelationshipServiceImplTest { verify(relationshipRepository, times(1)).save( eq( Relationship( - userId = 1234, - targetUserId = 5678, + userId = 5678, + targetUserId = 1234, following = true, blocking = false, muting = false, @@ -374,9 +374,9 @@ class RelationshipServiceImplTest { @Test fun `acceptFollowRequest ブロックしている場合は何もしない`() = runTest { - whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( + whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn( Relationship( - 1234, 5678, false, true, false, true, false + 5678, 1234, false, true, false, true, false ) )