From 03ae444d54f13507948c704eef7b80f6653c2b99 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:12:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=A8?= =?UTF-8?q?=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E5=AF=BE=E8=B1=A1=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=8C=E4=B8=A1=E6=96=B9=E3=83=AA?= =?UTF-8?q?=E3=83=A2=E3=83=BC=E3=83=88=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E7=95=B0=E5=B8=B8=E3=81=AA=E3=82=A2=E3=82=AF?= =?UTF-8?q?=E3=83=86=E3=82=A3=E3=83=93=E3=83=86=E3=82=A3=E3=82=92=E7=84=A1?= =?UTF-8?q?=E8=A6=96=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/service/block/BlockServiceImpl.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/block/BlockServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/block/BlockServiceImpl.kt index 77209855..761308e4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/block/BlockServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/block/BlockServiceImpl.kt @@ -30,21 +30,28 @@ class BlockServiceImpl( BlockService { override suspend fun block(userId: Long, target: Long) { logger.debug("Block userId: {} → target: {}", userId, target) + + val user = userRepository.findById(userId) ?: throw IllegalStateException("Block user was not found.") + + val targetEntity = userRepository.findById(target) ?: throw IllegalStateException("Block use was not found.") + + if (user.domain != applicationConfig.url.host && targetEntity.domain != applicationConfig.url.host) { + logger.warn("Invalid Block activity. Both user and target are remote users.") + return + } + blockRepository.save(Block(userId, target)) if (followerQueryService.alreadyFollow(userId, target)) { logger.debug("Unfollow (Block) userId: {} → target: {}", userId, target) userService.unfollow(userId, target) } - val user = userRepository.findById(userId) ?: throw IllegalStateException("Block user was not found.") if (user.domain == applicationConfig.url.host) { return } - val target = userRepository.findById(target) ?: throw IllegalStateException("Block use was not found.") - - if (target.domain == applicationConfig.url.host) { + if (targetEntity.domain == applicationConfig.url.host) { return } @@ -52,18 +59,18 @@ class BlockServiceImpl( user.id, dev.usbharu.hideout.activitypub.domain.model.Block( user.url, - "${applicationConfig.url}/block/${user.id}/${target.id}", - target.url + "${applicationConfig.url}/block/${user.id}/${targetEntity.id}", + targetEntity.url ), Reject( user.url, - "${applicationConfig.url}/reject/${user.id}/${target.id}", + "${applicationConfig.url}/reject/${user.id}/${targetEntity.id}", Follow( apObject = user.url, - actor = target.url + actor = targetEntity.url ) ), - target.inbox + targetEntity.inbox ) jobQueueParentService.scheduleTypeSafe(deliverBlockJob, blockJobParam) }