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 {
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)
}