feat: ブロック操作ユーザーとブロック対象ユーザーが両方リモートになっている異常なアクティビティを無視するように

This commit is contained in:
usbharu 2023-12-08 13:12:40 +09:00
parent 1a7cec5c7b
commit 03ae444d54
1 changed files with 16 additions and 9 deletions

View File

@ -30,21 +30,28 @@ class BlockServiceImpl(
BlockService { BlockService {
override suspend fun block(userId: Long, target: Long) { override suspend fun block(userId: Long, target: Long) {
logger.debug("Block userId: {} → target: {}", userId, target) 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)) blockRepository.save(Block(userId, target))
if (followerQueryService.alreadyFollow(userId, target)) { if (followerQueryService.alreadyFollow(userId, target)) {
logger.debug("Unfollow (Block) userId: {} → target: {}", userId, target) logger.debug("Unfollow (Block) userId: {} → target: {}", userId, target)
userService.unfollow(userId, target) userService.unfollow(userId, target)
} }
val user = userRepository.findById(userId) ?: throw IllegalStateException("Block user was not found.")
if (user.domain == applicationConfig.url.host) { if (user.domain == applicationConfig.url.host) {
return return
} }
val target = userRepository.findById(target) ?: throw IllegalStateException("Block use was not found.") if (targetEntity.domain == applicationConfig.url.host) {
if (target.domain == applicationConfig.url.host) {
return return
} }
@ -52,18 +59,18 @@ class BlockServiceImpl(
user.id, user.id,
dev.usbharu.hideout.activitypub.domain.model.Block( dev.usbharu.hideout.activitypub.domain.model.Block(
user.url, user.url,
"${applicationConfig.url}/block/${user.id}/${target.id}", "${applicationConfig.url}/block/${user.id}/${targetEntity.id}",
target.url targetEntity.url
), ),
Reject( Reject(
user.url, user.url,
"${applicationConfig.url}/reject/${user.id}/${target.id}", "${applicationConfig.url}/reject/${user.id}/${targetEntity.id}",
Follow( Follow(
apObject = user.url, apObject = user.url,
actor = target.url actor = targetEntity.url
) )
), ),
target.inbox targetEntity.inbox
) )
jobQueueParentService.scheduleTypeSafe(deliverBlockJob, blockJobParam) jobQueueParentService.scheduleTypeSafe(deliverBlockJob, blockJobParam)
} }