mirror of https://github.com/usbharu/Hideout.git
feat: ブロックのMastodon APIを追加
This commit is contained in:
parent
7e93db6c7e
commit
2c1da54a77
|
@ -197,6 +197,7 @@ class SecurityConfig {
|
||||||
authorize(GET, "/api/v1/accounts/*", permitAll)
|
authorize(GET, "/api/v1/accounts/*", permitAll)
|
||||||
authorize(GET, "/api/v1/accounts/*/statuses", permitAll)
|
authorize(GET, "/api/v1/accounts/*/statuses", permitAll)
|
||||||
authorize(POST, "/api/v1/accounts/*/follow", hasAnyScope("write", "write:follows"))
|
authorize(POST, "/api/v1/accounts/*/follow", hasAnyScope("write", "write:follows"))
|
||||||
|
authorize(POST, "/api/v1/accounts/*/block", hasAnyScope("write", "write:blocks"))
|
||||||
|
|
||||||
authorize(POST, "/api/v1/media", hasAnyScope("write", "write:media"))
|
authorize(POST, "/api/v1/media", hasAnyScope("write", "write:media"))
|
||||||
authorize(POST, "/api/v1/statuses", hasAnyScope("write", "write:statuses"))
|
authorize(POST, "/api/v1/statuses", hasAnyScope("write", "write:statuses"))
|
||||||
|
|
|
@ -28,7 +28,7 @@ class BlockServiceImpl(
|
||||||
private val applicationConfig: ApplicationConfig
|
private val applicationConfig: ApplicationConfig
|
||||||
) :
|
) :
|
||||||
BlockService {
|
BlockService {
|
||||||
override suspend fun block(userId: Long, target: Long): Unit = transaction.transaction {
|
override suspend fun block(userId: Long, target: Long) {
|
||||||
logger.debug("Block userId: {} → target: {}", userId, target)
|
logger.debug("Block userId: {} → target: {}", userId, target)
|
||||||
blockRepository.save(Block(userId, target))
|
blockRepository.save(Block(userId, target))
|
||||||
if (followerQueryService.alreadyFollow(userId, target)) {
|
if (followerQueryService.alreadyFollow(userId, target)) {
|
||||||
|
@ -39,13 +39,13 @@ class BlockServiceImpl(
|
||||||
val user = userRepository.findById(userId) ?: throw IllegalStateException("Block user was not found.")
|
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@transaction
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val target = userRepository.findById(target) ?: throw IllegalStateException("Block use was not found.")
|
val target = userRepository.findById(target) ?: throw IllegalStateException("Block use was not found.")
|
||||||
|
|
||||||
if (target.domain == applicationConfig.url.host) {
|
if (target.domain == applicationConfig.url.host) {
|
||||||
return@transaction
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val blockJobParam = DeliverBlockJobParam(
|
val blockJobParam = DeliverBlockJobParam(
|
||||||
|
|
|
@ -103,4 +103,14 @@ class MastodonAccountApiController(
|
||||||
.asFlow()
|
.asFlow()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun apiV1AccountsIdBlockPost(id: String): ResponseEntity<Relationship> {
|
||||||
|
val principal = SecurityContextHolder.getContext().getAuthentication().principal as Jwt
|
||||||
|
|
||||||
|
val userid = principal.getClaim<String>("uid").toLong()
|
||||||
|
|
||||||
|
val block = accountApiService.block(userid, id.toLong())
|
||||||
|
|
||||||
|
return ResponseEntity.ok(block)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package dev.usbharu.hideout.mastodon.service.account
|
package dev.usbharu.hideout.mastodon.service.account
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.domain.model.block.BlockRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
|
import dev.usbharu.hideout.core.service.block.BlockService
|
||||||
import dev.usbharu.hideout.core.service.user.UserCreateDto
|
import dev.usbharu.hideout.core.service.user.UserCreateDto
|
||||||
import dev.usbharu.hideout.core.service.user.UserService
|
import dev.usbharu.hideout.core.service.user.UserService
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
||||||
|
@ -32,6 +35,7 @@ interface AccountApiService {
|
||||||
suspend fun follow(userid: Long, followeeId: Long): Relationship
|
suspend fun follow(userid: Long, followeeId: Long): Relationship
|
||||||
suspend fun account(id: Long): Account
|
suspend fun account(id: Long): Account
|
||||||
suspend fun relationships(userid: Long, id: List<Long>, withSuspended: Boolean): List<Relationship>
|
suspend fun relationships(userid: Long, id: List<Long>, withSuspended: Boolean): List<Relationship>
|
||||||
|
suspend fun block(userid: Long, target: Long): Relationship
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -41,7 +45,9 @@ class AccountApiServiceImpl(
|
||||||
private val userService: UserService,
|
private val userService: UserService,
|
||||||
private val followerQueryService: FollowerQueryService,
|
private val followerQueryService: FollowerQueryService,
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
private val statusQueryService: StatusQueryService
|
private val statusQueryService: StatusQueryService,
|
||||||
|
private val blockService: BlockService,
|
||||||
|
private val blockRepository: BlockRepository
|
||||||
) :
|
) :
|
||||||
AccountApiService {
|
AccountApiService {
|
||||||
override suspend fun accountsStatuses(
|
override suspend fun accountsStatuses(
|
||||||
|
@ -160,6 +166,35 @@ class AccountApiServiceImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun block(userid: Long, target: Long): Relationship = transaction.transaction {
|
||||||
|
blockService.block(userid, target)
|
||||||
|
|
||||||
|
val blocked = try {
|
||||||
|
blockRepository.findByUserIdAndTarget(target, userid)
|
||||||
|
true
|
||||||
|
} catch (e: FailedToGetResourcesException) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
val requested = userRepository.findFollowRequestsById(target, userid)
|
||||||
|
|
||||||
|
Relationship(
|
||||||
|
target.toString(),
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
blocked,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
requested,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun from(account: Account): CredentialAccount {
|
private fun from(account: Account): CredentialAccount {
|
||||||
return CredentialAccount(
|
return CredentialAccount(
|
||||||
id = account.id,
|
id = account.id,
|
||||||
|
|
|
@ -287,6 +287,27 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Relationship"
|
$ref: "#/components/schemas/Relationship"
|
||||||
|
|
||||||
|
/api/v1/accounts/{id}/block:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- account
|
||||||
|
security:
|
||||||
|
- OAuth2:
|
||||||
|
- "write:blocks"
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: 成功
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Relationship"
|
||||||
|
|
||||||
/api/v1/accounts/{id}/statuses:
|
/api/v1/accounts/{id}/statuses:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
|
Loading…
Reference in New Issue