mirror of https://github.com/usbharu/Hideout.git
refactor: 命名をプログラムにも適用
This commit is contained in:
parent
b74e359123
commit
9c2107eac1
|
@ -1,4 +1,4 @@
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Users
|
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors
|
||||||
import org.jetbrains.exposed.sql.and
|
import org.jetbrains.exposed.sql.and
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
|
@ -16,13 +16,13 @@ object AssertionUtil {
|
||||||
domain
|
domain
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectAll = Users.selectAll()
|
val selectAll = Actors.selectAll()
|
||||||
println(selectAll.fetchSize)
|
println(selectAll.fetchSize)
|
||||||
|
|
||||||
println(selectAll.toList().size)
|
println(selectAll.toList().size)
|
||||||
|
|
||||||
selectAll.map { "@${it[Users.name]}@${it[Users.domain]}" }.forEach { println(it) }
|
selectAll.map { "@${it[Actors.name]}@${it[Actors.domain]}" }.forEach { println(it) }
|
||||||
|
|
||||||
return Users.select { Users.name eq username and (Users.domain eq s) }.empty().not()
|
return Actors.select { Actors.name eq username and (Actors.domain eq s) }.empty().not()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package mastodon.account
|
package mastodon.account
|
||||||
|
|
||||||
import dev.usbharu.hideout.SpringApplication
|
import dev.usbharu.hideout.SpringApplication
|
||||||
|
import dev.usbharu.hideout.core.infrastructure.exposedquery.ActorQueryServiceImpl
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedquery.FollowerQueryServiceImpl
|
import dev.usbharu.hideout.core.infrastructure.exposedquery.FollowerQueryServiceImpl
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedquery.UserQueryServiceImpl
|
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.flywaydb.core.Flyway
|
import org.flywaydb.core.Flyway
|
||||||
|
@ -39,7 +39,7 @@ class AccountApiTest {
|
||||||
private lateinit var followerQueryServiceImpl: FollowerQueryServiceImpl
|
private lateinit var followerQueryServiceImpl: FollowerQueryServiceImpl
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var userQueryServiceImpl: UserQueryServiceImpl
|
private lateinit var userQueryServiceImpl: ActorQueryServiceImpl
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -2,7 +2,7 @@ package util
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUser
|
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureUser
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
import dev.usbharu.httpsignature.common.HttpRequest
|
import dev.usbharu.httpsignature.common.HttpRequest
|
||||||
|
@ -14,7 +14,7 @@ import org.springframework.security.web.authentication.preauth.PreAuthenticatedA
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
class WithHttpSignatureSecurityContextFactory(
|
class WithHttpSignatureSecurityContextFactory(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) : WithSecurityContextFactory<WithHttpSignature> {
|
) : WithSecurityContextFactory<WithHttpSignature> {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class WithHttpSignatureSecurityContextFactory(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val httpSignatureUser = transaction.transaction {
|
val httpSignatureUser = transaction.transaction {
|
||||||
val findByKeyId = userQueryService.findByKeyId(annotation.keyId)
|
val findByKeyId = actorQueryService.findByKeyId(annotation.keyId)
|
||||||
HttpSignatureUser(
|
HttpSignatureUser(
|
||||||
findByKeyId.name,
|
findByKeyId.name,
|
||||||
findByKeyId.domain,
|
findByKeyId.domain,
|
||||||
|
|
|
@ -23,7 +23,7 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
|
||||||
NoteQueryService {
|
NoteQueryService {
|
||||||
override suspend fun findById(id: Long): Pair<Note, Post> {
|
override suspend fun findById(id: Long): Pair<Note, Post> {
|
||||||
return Posts
|
return Posts
|
||||||
.leftJoin(Users)
|
.leftJoin(Actors)
|
||||||
.leftJoin(PostsMedia)
|
.leftJoin(PostsMedia)
|
||||||
.leftJoin(Media)
|
.leftJoin(Media)
|
||||||
.select { Posts.id eq id }
|
.select { Posts.id eq id }
|
||||||
|
@ -35,7 +35,7 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
|
||||||
|
|
||||||
override suspend fun findByApid(apId: String): Pair<Note, Post> {
|
override suspend fun findByApid(apId: String): Pair<Note, Post> {
|
||||||
return Posts
|
return Posts
|
||||||
.leftJoin(Users)
|
.leftJoin(Actors)
|
||||||
.leftJoin(PostsMedia)
|
.leftJoin(PostsMedia)
|
||||||
.leftJoin(Media)
|
.leftJoin(Media)
|
||||||
.select { Posts.apId eq apId }
|
.select { Posts.apId eq apId }
|
||||||
|
@ -61,11 +61,11 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v
|
||||||
val visibility1 =
|
val visibility1 =
|
||||||
visibility(
|
visibility(
|
||||||
Visibility.values().first { visibility -> visibility.ordinal == this[Posts.visibility] },
|
Visibility.values().first { visibility -> visibility.ordinal == this[Posts.visibility] },
|
||||||
this[Users.followers]
|
this[Actors.followers]
|
||||||
)
|
)
|
||||||
return Note(
|
return Note(
|
||||||
id = this[Posts.apId],
|
id = this[Posts.apId],
|
||||||
attributedTo = this[Users.url],
|
attributedTo = this[Actors.url],
|
||||||
content = this[Posts.text],
|
content = this[Posts.text],
|
||||||
published = Instant.ofEpochMilli(this[Posts.createdAt]).toString(),
|
published = Instant.ofEpochMilli(this[Posts.createdAt]).toString(),
|
||||||
to = visibility1.first,
|
to = visibility1.first,
|
||||||
|
|
|
@ -4,20 +4,20 @@ import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class APDeliverAcceptJobProcessor(
|
class APDeliverAcceptJobProcessor(
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val deliverAcceptJob: DeliverAcceptJob,
|
private val deliverAcceptJob: DeliverAcceptJob,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) :
|
) :
|
||||||
JobProcessor<DeliverAcceptJobParam, DeliverAcceptJob> {
|
JobProcessor<DeliverAcceptJobParam, DeliverAcceptJob> {
|
||||||
override suspend fun process(param: DeliverAcceptJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverAcceptJobParam): Unit = transaction.transaction {
|
||||||
apRequestService.apPost(param.inbox, param.accept, userQueryService.findById(param.signer))
|
apRequestService.apPost(param.inbox, param.accept, actorQueryService.findById(param.signer))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun job(): DeliverAcceptJob = deliverAcceptJob
|
override fun job(): DeliverAcceptJob = deliverAcceptJob
|
||||||
|
|
|
@ -7,14 +7,14 @@ import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcess
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApAcceptProcessor(
|
class ApAcceptProcessor(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val relationshipService: RelationshipService
|
private val relationshipService: RelationshipService
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Accept>(transaction) {
|
AbstractActivityPubProcessor<Accept>(transaction) {
|
||||||
|
@ -32,8 +32,8 @@ class ApAcceptProcessor(
|
||||||
val userUrl = follow.apObject
|
val userUrl = follow.apObject
|
||||||
val followerUrl = follow.actor
|
val followerUrl = follow.actor
|
||||||
|
|
||||||
val user = userQueryService.findByUrl(userUrl)
|
val user = actorQueryService.findByUrl(userUrl)
|
||||||
val follower = userQueryService.findByUrl(followerUrl)
|
val follower = actorQueryService.findByUrl(followerUrl)
|
||||||
|
|
||||||
relationshipService.acceptFollowRequest(user.id, follower.id)
|
relationshipService.acceptFollowRequest(user.id, follower.id)
|
||||||
logger.debug("SUCCESS Follow from ${user.url} to ${follower.url}.")
|
logger.debug("SUCCESS Follow from ${user.url} to ${follower.url}.")
|
||||||
|
|
|
@ -2,14 +2,14 @@ package dev.usbharu.hideout.activitypub.service.activity.accept
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
interface ApSendAcceptService {
|
interface ApSendAcceptService {
|
||||||
suspend fun sendAcceptFollow(user: User, target: User)
|
suspend fun sendAcceptFollow(actor: Actor, target: Actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -17,17 +17,17 @@ class ApSendAcceptServiceImpl(
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val deliverAcceptJob: DeliverAcceptJob
|
private val deliverAcceptJob: DeliverAcceptJob
|
||||||
) : ApSendAcceptService {
|
) : ApSendAcceptService {
|
||||||
override suspend fun sendAcceptFollow(user: User, target: User) {
|
override suspend fun sendAcceptFollow(actor: Actor, target: Actor) {
|
||||||
val deliverAcceptJobParam = DeliverAcceptJobParam(
|
val deliverAcceptJobParam = DeliverAcceptJobParam(
|
||||||
Accept(
|
Accept(
|
||||||
apObject = Follow(
|
apObject = Follow(
|
||||||
apObject = user.url,
|
apObject = actor.url,
|
||||||
actor = target.url
|
actor = target.url
|
||||||
),
|
),
|
||||||
actor = user.url
|
actor = actor.url
|
||||||
),
|
),
|
||||||
target.inbox,
|
target.inbox,
|
||||||
user.id
|
actor.id
|
||||||
)
|
)
|
||||||
|
|
||||||
jobQueueParentService.scheduleTypeSafe(deliverAcceptJob, deliverAcceptJobParam)
|
jobQueueParentService.scheduleTypeSafe(deliverAcceptJob, deliverAcceptJobParam)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.usbharu.hideout.activitypub.service.activity.block
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
|
@ -14,12 +14,12 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class APDeliverBlockJobProcessor(
|
class APDeliverBlockJobProcessor(
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val userRepository: UserRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val deliverBlockJob: DeliverBlockJob
|
private val deliverBlockJob: DeliverBlockJob
|
||||||
) : JobProcessor<DeliverBlockJobParam, DeliverBlockJob> {
|
) : JobProcessor<DeliverBlockJobParam, DeliverBlockJob> {
|
||||||
override suspend fun process(param: DeliverBlockJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverBlockJobParam): Unit = transaction.transaction {
|
||||||
val signer = userRepository.findById(param.signer)
|
val signer = actorRepository.findById(param.signer)
|
||||||
apRequestService.apPost(
|
apRequestService.apPost(
|
||||||
param.inbox,
|
param.inbox,
|
||||||
param.reject,
|
param.reject,
|
||||||
|
|
|
@ -4,14 +4,14 @@ import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
interface APSendBlockService {
|
interface APSendBlockService {
|
||||||
suspend fun sendBlock(user: User, target: User)
|
suspend fun sendBlock(actor: Actor, target: Actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -20,19 +20,19 @@ class ApSendBlockServiceImpl(
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val deliverBlockJob: DeliverBlockJob
|
private val deliverBlockJob: DeliverBlockJob
|
||||||
) : APSendBlockService {
|
) : APSendBlockService {
|
||||||
override suspend fun sendBlock(user: User, target: User) {
|
override suspend fun sendBlock(actor: Actor, target: Actor) {
|
||||||
val blockJobParam = DeliverBlockJobParam(
|
val blockJobParam = DeliverBlockJobParam(
|
||||||
user.id,
|
actor.id,
|
||||||
Block(
|
Block(
|
||||||
user.url,
|
actor.url,
|
||||||
"${applicationConfig.url}/block/${user.id}/${target.id}",
|
"${applicationConfig.url}/block/${actor.id}/${target.id}",
|
||||||
target.url
|
target.url
|
||||||
),
|
),
|
||||||
Reject(
|
Reject(
|
||||||
user.url,
|
actor.url,
|
||||||
"${applicationConfig.url}/reject/${user.id}/${target.id}",
|
"${applicationConfig.url}/reject/${actor.id}/${target.id}",
|
||||||
Follow(
|
Follow(
|
||||||
apObject = user.url,
|
apObject = actor.url,
|
||||||
actor = target.url
|
actor = target.url
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
|
@ -5,7 +5,7 @@ import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcess
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -14,14 +14,14 @@ import org.springframework.stereotype.Service
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
class BlockActivityPubProcessor(
|
class BlockActivityPubProcessor(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val relationshipService: RelationshipService,
|
private val relationshipService: RelationshipService,
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Block>(transaction) {
|
AbstractActivityPubProcessor<Block>(transaction) {
|
||||||
override suspend fun internalProcess(activity: ActivityPubProcessContext<Block>) {
|
override suspend fun internalProcess(activity: ActivityPubProcessContext<Block>) {
|
||||||
val user = userQueryService.findByUrl(activity.activity.actor)
|
val user = actorQueryService.findByUrl(activity.activity.actor)
|
||||||
val target = userQueryService.findByUrl(activity.activity.apObject)
|
val target = actorQueryService.findByUrl(activity.activity.apObject)
|
||||||
relationshipService.block(user.id, target.id)
|
relationshipService.block(user.id, target.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import dev.usbharu.hideout.activitypub.query.NoteQueryService
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -17,7 +17,7 @@ class ApSendCreateServiceImpl(
|
||||||
private val followerQueryService: FollowerQueryService,
|
private val followerQueryService: FollowerQueryService,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val noteQueryService: NoteQueryService,
|
private val noteQueryService: NoteQueryService,
|
||||||
private val applicationConfig: ApplicationConfig
|
private val applicationConfig: ApplicationConfig
|
||||||
) : ApSendCreateService {
|
) : ApSendCreateService {
|
||||||
|
@ -25,11 +25,11 @@ class ApSendCreateServiceImpl(
|
||||||
logger.info("CREATE Create Local Note ${post.url}")
|
logger.info("CREATE Create Local Note ${post.url}")
|
||||||
logger.debug("START Create Local Note ${post.url}")
|
logger.debug("START Create Local Note ${post.url}")
|
||||||
logger.trace("{}", post)
|
logger.trace("{}", post)
|
||||||
val followers = followerQueryService.findFollowersById(post.userId)
|
val followers = followerQueryService.findFollowersById(post.actorId)
|
||||||
|
|
||||||
logger.debug("DELIVER Deliver Note Create ${followers.size} accounts.")
|
logger.debug("DELIVER Deliver Note Create ${followers.size} accounts.")
|
||||||
|
|
||||||
val userEntity = userQueryService.findById(post.userId)
|
val userEntity = actorQueryService.findById(post.actorId)
|
||||||
val note = noteQueryService.findById(post.id).first
|
val note = noteQueryService.findById(post.id).first
|
||||||
val create = Create(
|
val create = Create(
|
||||||
name = "Create Note",
|
name = "Create Note",
|
||||||
|
|
|
@ -7,7 +7,7 @@ import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.ReceiveFollowJob
|
import dev.usbharu.hideout.core.external.job.ReceiveFollowJob
|
||||||
import dev.usbharu.hideout.core.external.job.ReceiveFollowJobParam
|
import dev.usbharu.hideout.core.external.job.ReceiveFollowJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
@ -16,7 +16,7 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class APReceiveFollowJobProcessor(
|
class APReceiveFollowJobProcessor(
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val apUserService: APUserService,
|
private val apUserService: APUserService,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val relationshipService: RelationshipService
|
private val relationshipService: RelationshipService
|
||||||
|
@ -28,9 +28,9 @@ class APReceiveFollowJobProcessor(
|
||||||
|
|
||||||
logger.info("START Follow from: {} to {}", param.targetActor, param.actor)
|
logger.info("START Follow from: {} to {}", param.targetActor, param.actor)
|
||||||
|
|
||||||
val targetEntity = userQueryService.findByUrl(param.targetActor)
|
val targetEntity = actorQueryService.findByUrl(param.targetActor)
|
||||||
val followActorEntity =
|
val followActorEntity =
|
||||||
userQueryService.findByUrl(follow.actor)
|
actorQueryService.findByUrl(follow.actor)
|
||||||
|
|
||||||
relationshipService.followRequest(followActorEntity.id, targetEntity.id)
|
relationshipService.followRequest(followActorEntity.id, targetEntity.id)
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ class APSendFollowServiceImpl(
|
||||||
) : APSendFollowService {
|
) : APSendFollowService {
|
||||||
override suspend fun sendFollow(sendFollowDto: SendFollowDto) {
|
override suspend fun sendFollow(sendFollowDto: SendFollowDto) {
|
||||||
val follow = Follow(
|
val follow = Follow(
|
||||||
apObject = sendFollowDto.followTargetUserId.url,
|
apObject = sendFollowDto.followTargetActorId.url,
|
||||||
actor = sendFollowDto.userId.url
|
actor = sendFollowDto.actorId.url
|
||||||
)
|
)
|
||||||
|
|
||||||
apRequestService.apPost(sendFollowDto.followTargetUserId.inbox, follow, sendFollowDto.userId)
|
apRequestService.apPost(sendFollowDto.followTargetActorId.inbox, follow, sendFollowDto.actorId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.beans.factory.annotation.Qualifier
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -19,14 +19,14 @@ interface APReactionService {
|
||||||
@Service
|
@Service
|
||||||
class APReactionServiceImpl(
|
class APReactionServiceImpl(
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val followerQueryService: FollowerQueryService,
|
private val followerQueryService: FollowerQueryService,
|
||||||
private val postQueryService: PostQueryService,
|
private val postQueryService: PostQueryService,
|
||||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
||||||
) : APReactionService {
|
) : APReactionService {
|
||||||
override suspend fun reaction(like: Reaction) {
|
override suspend fun reaction(like: Reaction) {
|
||||||
val followers = followerQueryService.findFollowersById(like.userId)
|
val followers = followerQueryService.findFollowersById(like.actorId)
|
||||||
val user = userQueryService.findById(like.userId)
|
val user = actorQueryService.findById(like.actorId)
|
||||||
val post =
|
val post =
|
||||||
postQueryService.findById(like.postId)
|
postQueryService.findById(like.postId)
|
||||||
followers.forEach { follower ->
|
followers.forEach { follower ->
|
||||||
|
@ -41,8 +41,8 @@ class APReactionServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun removeReaction(like: Reaction) {
|
override suspend fun removeReaction(like: Reaction) {
|
||||||
val followers = followerQueryService.findFollowersById(like.userId)
|
val followers = followerQueryService.findFollowersById(like.actorId)
|
||||||
val user = userQueryService.findById(like.userId)
|
val user = actorQueryService.findById(like.actorId)
|
||||||
val post =
|
val post =
|
||||||
postQueryService.findById(like.postId)
|
postQueryService.findById(like.postId)
|
||||||
followers.forEach { follower ->
|
followers.forEach { follower ->
|
||||||
|
|
|
@ -6,19 +6,19 @@ import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverReactionJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverReactionJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApReactionJobProcessor(
|
class ApReactionJobProcessor(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) : JobProcessor<DeliverReactionJobParam, DeliverReactionJob> {
|
) : JobProcessor<DeliverReactionJobParam, DeliverReactionJob> {
|
||||||
override suspend fun process(param: DeliverReactionJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverReactionJobParam): Unit = transaction.transaction {
|
||||||
val signer = userQueryService.findByUrl(param.actor)
|
val signer = actorQueryService.findByUrl(param.actor)
|
||||||
|
|
||||||
apRequestService.apPost(
|
apRequestService.apPost(
|
||||||
param.inbox,
|
param.inbox,
|
||||||
|
|
|
@ -9,14 +9,14 @@ import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApRemoveReactionJobProcessor(
|
class ApRemoveReactionJobProcessor(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
|
@ -25,7 +25,7 @@ class ApRemoveReactionJobProcessor(
|
||||||
override suspend fun process(param: DeliverRemoveReactionJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverRemoveReactionJobParam): Unit = transaction.transaction {
|
||||||
val like = objectMapper.readValue<Like>(param.like)
|
val like = objectMapper.readValue<Like>(param.like)
|
||||||
|
|
||||||
val signer = userQueryService.findByUrl(param.actor)
|
val signer = actorQueryService.findByUrl(param.actor)
|
||||||
|
|
||||||
apRequestService.apPost(
|
apRequestService.apPost(
|
||||||
param.inbox,
|
param.inbox,
|
||||||
|
|
|
@ -4,20 +4,20 @@ import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRejectJob
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class APDeliverRejectJobProcessor(
|
class APDeliverRejectJobProcessor(
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val deliverRejectJob: DeliverRejectJob,
|
private val deliverRejectJob: DeliverRejectJob,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) :
|
) :
|
||||||
JobProcessor<DeliverRejectJobParam, DeliverRejectJob> {
|
JobProcessor<DeliverRejectJobParam, DeliverRejectJob> {
|
||||||
override suspend fun process(param: DeliverRejectJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverRejectJobParam): Unit = transaction.transaction {
|
||||||
apRequestService.apPost(param.inbox, param.reject, userQueryService.findById(param.signer))
|
apRequestService.apPost(param.inbox, param.reject, actorQueryService.findById(param.signer))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun job(): DeliverRejectJob = deliverRejectJob
|
override fun job(): DeliverRejectJob = deliverRejectJob
|
||||||
|
|
|
@ -6,14 +6,14 @@ import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcess
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApRejectProcessor(
|
class ApRejectProcessor(
|
||||||
private val relationshipService: RelationshipService,
|
private val relationshipService: RelationshipService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Reject>(transaction) {
|
AbstractActivityPubProcessor<Reject>(transaction) {
|
||||||
|
@ -26,13 +26,13 @@ class ApRejectProcessor(
|
||||||
}
|
}
|
||||||
when (activityType) {
|
when (activityType) {
|
||||||
"Follow" -> {
|
"Follow" -> {
|
||||||
val user = userQueryService.findByUrl(activity.activity.actor)
|
val user = actorQueryService.findByUrl(activity.activity.actor)
|
||||||
|
|
||||||
activity.activity.apObject as Follow
|
activity.activity.apObject as Follow
|
||||||
|
|
||||||
val actor = activity.activity.apObject.actor
|
val actor = activity.activity.apObject.actor
|
||||||
|
|
||||||
val target = userQueryService.findByUrl(actor)
|
val target = actorQueryService.findByUrl(actor)
|
||||||
|
|
||||||
logger.debug("REJECT Follow user {} target {}", user.url, target.url)
|
logger.debug("REJECT Follow user {} target {}", user.url, target.url)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.reject
|
package dev.usbharu.hideout.activitypub.service.activity.reject
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
interface ApSendRejectService {
|
interface ApSendRejectService {
|
||||||
suspend fun sendRejectFollow(user: User, target: User)
|
suspend fun sendRejectFollow(actor: Actor, target: Actor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package dev.usbharu.hideout.activitypub.service.activity.reject
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRejectJob
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
|
@ -15,15 +15,15 @@ class ApSendRejectServiceImpl(
|
||||||
private val jobQueueParentService: JobQueueParentService,
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
private val deliverRejectJob: DeliverRejectJob
|
private val deliverRejectJob: DeliverRejectJob
|
||||||
) : ApSendRejectService {
|
) : ApSendRejectService {
|
||||||
override suspend fun sendRejectFollow(user: User, target: User) {
|
override suspend fun sendRejectFollow(actor: Actor, target: Actor) {
|
||||||
val deliverRejectJobParam = DeliverRejectJobParam(
|
val deliverRejectJobParam = DeliverRejectJobParam(
|
||||||
Reject(
|
Reject(
|
||||||
user.url,
|
actor.url,
|
||||||
"${applicationConfig.url}/reject/${user.id}/${target.id}",
|
"${applicationConfig.url}/reject/${actor.id}/${target.id}",
|
||||||
Follow(apObject = user.url, actor = target.url)
|
Follow(apObject = actor.url, actor = target.url)
|
||||||
),
|
),
|
||||||
target.inbox,
|
target.inbox,
|
||||||
user.id
|
actor.id
|
||||||
)
|
)
|
||||||
|
|
||||||
jobQueueParentService.scheduleTypeSafe(deliverRejectJob, deliverRejectJobParam)
|
jobQueueParentService.scheduleTypeSafe(deliverRejectJob, deliverRejectJobParam)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverUndoJob
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ import org.springframework.stereotype.Service
|
||||||
class APDeliverUndoJobProcessor(
|
class APDeliverUndoJobProcessor(
|
||||||
private val deliverUndoJob: DeliverUndoJob,
|
private val deliverUndoJob: DeliverUndoJob,
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) : JobProcessor<DeliverUndoJobParam, DeliverUndoJob> {
|
) : JobProcessor<DeliverUndoJobParam, DeliverUndoJob> {
|
||||||
override suspend fun process(param: DeliverUndoJobParam): Unit = transaction.transaction {
|
override suspend fun process(param: DeliverUndoJobParam): Unit = transaction.transaction {
|
||||||
apRequestService.apPost(param.inbox, param.undo, userQueryService.findById(param.signer))
|
apRequestService.apPost(param.inbox, param.undo, actorQueryService.findById(param.signer))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun job(): DeliverUndoJob = deliverUndoJob
|
override fun job(): DeliverUndoJob = deliverUndoJob
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.undo
|
package dev.usbharu.hideout.activitypub.service.activity.undo
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
interface APSendUndoService {
|
interface APSendUndoService {
|
||||||
suspend fun sendUndoFollow(user: User, target: User)
|
suspend fun sendUndoFollow(actor: Actor, target: Actor)
|
||||||
suspend fun sendUndoBlock(user: User, target: User)
|
suspend fun sendUndoBlock(actor: Actor, target: Actor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverUndoJob
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
|
@ -17,38 +17,38 @@ class APSendUndoServiceImpl(
|
||||||
private val deliverUndoJob: DeliverUndoJob,
|
private val deliverUndoJob: DeliverUndoJob,
|
||||||
private val applicationConfig: ApplicationConfig
|
private val applicationConfig: ApplicationConfig
|
||||||
) : APSendUndoService {
|
) : APSendUndoService {
|
||||||
override suspend fun sendUndoFollow(user: User, target: User) {
|
override suspend fun sendUndoFollow(actor: Actor, target: Actor) {
|
||||||
val deliverUndoJobParam = DeliverUndoJobParam(
|
val deliverUndoJobParam = DeliverUndoJobParam(
|
||||||
Undo(
|
Undo(
|
||||||
actor = user.url,
|
actor = actor.url,
|
||||||
id = "${applicationConfig.url}/undo/follow/${user.id}/${target.url}",
|
id = "${applicationConfig.url}/undo/follow/${actor.id}/${target.url}",
|
||||||
apObject = Follow(
|
apObject = Follow(
|
||||||
apObject = user.url,
|
apObject = actor.url,
|
||||||
actor = target.url
|
actor = target.url
|
||||||
),
|
),
|
||||||
published = Instant.now().toString()
|
published = Instant.now().toString()
|
||||||
),
|
),
|
||||||
target.inbox,
|
target.inbox,
|
||||||
user.id
|
actor.id
|
||||||
)
|
)
|
||||||
|
|
||||||
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendUndoBlock(user: User, target: User) {
|
override suspend fun sendUndoBlock(actor: Actor, target: Actor) {
|
||||||
val deliverUndoJobParam = DeliverUndoJobParam(
|
val deliverUndoJobParam = DeliverUndoJobParam(
|
||||||
Undo(
|
Undo(
|
||||||
actor = user.url,
|
actor = actor.url,
|
||||||
id = "${applicationConfig.url}/undo/block/${user.id}/${target.url}",
|
id = "${applicationConfig.url}/undo/block/${actor.id}/${target.url}",
|
||||||
apObject = Block(
|
apObject = Block(
|
||||||
apObject = user.url,
|
apObject = actor.url,
|
||||||
actor = target.url,
|
actor = target.url,
|
||||||
id = "${applicationConfig.url}/block/${user.id}/${target.id}"
|
id = "${applicationConfig.url}/block/${actor.id}/${target.id}"
|
||||||
),
|
),
|
||||||
published = Instant.now().toString()
|
published = Instant.now().toString()
|
||||||
),
|
),
|
||||||
target.inbox,
|
target.inbox,
|
||||||
user.id
|
actor.id
|
||||||
)
|
)
|
||||||
|
|
||||||
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import org.springframework.stereotype.Service
|
||||||
class APUndoProcessor(
|
class APUndoProcessor(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
private val apUserService: APUserService,
|
private val apUserService: APUserService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val relationshipService: RelationshipService
|
private val relationshipService: RelationshipService
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Undo>(transaction) {
|
AbstractActivityPubProcessor<Undo>(transaction) {
|
||||||
|
@ -35,8 +35,8 @@ class APUndoProcessor(
|
||||||
val follow = undo.apObject as Follow
|
val follow = undo.apObject as Follow
|
||||||
|
|
||||||
apUserService.fetchPerson(undo.actor, follow.apObject)
|
apUserService.fetchPerson(undo.actor, follow.apObject)
|
||||||
val follower = userQueryService.findByUrl(undo.actor)
|
val follower = actorQueryService.findByUrl(undo.actor)
|
||||||
val target = userQueryService.findByUrl(follow.apObject)
|
val target = actorQueryService.findByUrl(follow.apObject)
|
||||||
|
|
||||||
relationshipService.unfollow(follower.id, target.id)
|
relationshipService.unfollow(follower.id, target.id)
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ class APUndoProcessor(
|
||||||
val block = undo.apObject as Block
|
val block = undo.apObject as Block
|
||||||
|
|
||||||
val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second
|
val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second
|
||||||
val target = userQueryService.findByUrl(block.apObject)
|
val target = actorQueryService.findByUrl(block.apObject)
|
||||||
|
|
||||||
relationshipService.unblock(blocker.id, target.id)
|
relationshipService.unblock(blocker.id, target.id)
|
||||||
return
|
return
|
||||||
|
@ -65,7 +65,7 @@ class APUndoProcessor(
|
||||||
}
|
}
|
||||||
|
|
||||||
val accepter = apUserService.fetchPersonWithEntity(undo.actor, acceptObject).second
|
val accepter = apUserService.fetchPersonWithEntity(undo.actor, acceptObject).second
|
||||||
val target = userQueryService.findByUrl(acceptObject)
|
val target = actorQueryService.findByUrl(acceptObject)
|
||||||
|
|
||||||
relationshipService.rejectFollowRequest(accepter.id, target.id)
|
relationshipService.rejectFollowRequest(accepter.id, target.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
interface APRequestService {
|
interface APRequestService {
|
||||||
suspend fun <R : Object> apGet(url: String, signer: User? = null, responseClass: Class<R>): R
|
suspend fun <R : Object> apGet(url: String, signer: Actor? = null, responseClass: Class<R>): R
|
||||||
suspend fun <T : Object, R : Object> apPost(
|
suspend fun <T : Object, R : Object> apPost(
|
||||||
url: String,
|
url: String,
|
||||||
body: T? = null,
|
body: T? = null,
|
||||||
signer: User? = null,
|
signer: Actor? = null,
|
||||||
responseClass: Class<R>
|
responseClass: Class<R>
|
||||||
): R
|
): R
|
||||||
|
|
||||||
suspend fun <T : Object> apPost(url: String, body: T? = null, signer: User? = null): String
|
suspend fun <T : Object> apPost(url: String, body: T? = null, signer: Actor? = null): String
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <reified R : Object> APRequestService.apGet(url: String, signer: User? = null): R =
|
suspend inline fun <reified R : Object> APRequestService.apGet(url: String, signer: Actor? = null): R =
|
||||||
apGet(url, signer, R::class.java)
|
apGet(url, signer, R::class.java)
|
||||||
|
|
||||||
suspend inline fun <T : Object, reified R : Object> APRequestService.apPost(
|
suspend inline fun <T : Object, reified R : Object> APRequestService.apPost(
|
||||||
url: String,
|
url: String,
|
||||||
body: T? = null,
|
body: T? = null,
|
||||||
signer: User? = null
|
signer: Actor? = null
|
||||||
): R = apPost(url, body, signer, R::class.java)
|
): R = apPost(url, body, signer, R::class.java)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.util.Base64Util
|
import dev.usbharu.hideout.util.Base64Util
|
||||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||||
import dev.usbharu.hideout.util.RsaUtil
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
|
@ -33,7 +33,7 @@ class APRequestServiceImpl(
|
||||||
@Qualifier("http") private val dateTimeFormatter: DateTimeFormatter,
|
@Qualifier("http") private val dateTimeFormatter: DateTimeFormatter,
|
||||||
) : APRequestService {
|
) : APRequestService {
|
||||||
|
|
||||||
override suspend fun <R : Object> apGet(url: String, signer: User?, responseClass: Class<R>): R {
|
override suspend fun <R : Object> apGet(url: String, signer: Actor?, responseClass: Class<R>): R {
|
||||||
logger.debug("START ActivityPub Request GET url: {}, signer: {}", url, signer?.url)
|
logger.debug("START ActivityPub Request GET url: {}, signer: {}", url, signer?.url)
|
||||||
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
val date = dateTimeFormatter.format(ZonedDateTime.now(ZoneId.of("GMT")))
|
||||||
val u = URL(url)
|
val u = URL(url)
|
||||||
|
@ -57,7 +57,7 @@ class APRequestServiceImpl(
|
||||||
private suspend fun apGetSign(
|
private suspend fun apGetSign(
|
||||||
date: String,
|
date: String,
|
||||||
u: URL,
|
u: URL,
|
||||||
signer: User,
|
signer: Actor,
|
||||||
url: String
|
url: String
|
||||||
): HttpResponse {
|
): HttpResponse {
|
||||||
val headers = headers {
|
val headers = headers {
|
||||||
|
@ -100,14 +100,14 @@ class APRequestServiceImpl(
|
||||||
override suspend fun <T : Object, R : Object> apPost(
|
override suspend fun <T : Object, R : Object> apPost(
|
||||||
url: String,
|
url: String,
|
||||||
body: T?,
|
body: T?,
|
||||||
signer: User?,
|
signer: Actor?,
|
||||||
responseClass: Class<R>
|
responseClass: Class<R>
|
||||||
): R {
|
): R {
|
||||||
val bodyAsText = apPost(url, body, signer)
|
val bodyAsText = apPost(url, body, signer)
|
||||||
return objectMapper.readValue(bodyAsText, responseClass)
|
return objectMapper.readValue(bodyAsText, responseClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Object> apPost(url: String, body: T?, signer: User?): String {
|
override suspend fun <T : Object> apPost(url: String, body: T?, signer: Actor?): String {
|
||||||
logger.debug("START ActivityPub Request POST url: {}, signer: {}", url, signer?.url)
|
logger.debug("START ActivityPub Request POST url: {}, signer: {}", url, signer?.url)
|
||||||
val requestBody = addContextIfNotNull(body)
|
val requestBody = addContextIfNotNull(body)
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class APRequestServiceImpl(
|
||||||
date: String,
|
date: String,
|
||||||
u: URL,
|
u: URL,
|
||||||
digest: String,
|
digest: String,
|
||||||
signer: User,
|
signer: Actor,
|
||||||
requestBody: String?
|
requestBody: String?
|
||||||
): HttpResponse {
|
): HttpResponse {
|
||||||
val headers = headers {
|
val headers = headers {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
interface APResourceResolveService {
|
interface APResourceResolveService {
|
||||||
suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singer: User?): T
|
suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singer: Actor?): T
|
||||||
suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singerId: Long?): T
|
suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singerId: Long?): T
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <reified T : Object> APResourceResolveService.resolve(url: String, singer: User?): T =
|
suspend inline fun <reified T : Object> APResourceResolveService.resolve(url: String, singer: Actor?): T =
|
||||||
resolve(url, T::class.java, singer)
|
resolve(url, T::class.java, singer)
|
||||||
|
|
||||||
suspend inline fun <reified T : Object> APResourceResolveService.resolve(url: String, singerId: Long?): T =
|
suspend inline fun <reified T : Object> APResourceResolveService.resolve(url: String, singerId: Long?): T =
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.service.resource.CacheManager
|
import dev.usbharu.hideout.core.service.resource.CacheManager
|
||||||
import dev.usbharu.hideout.core.service.resource.ResolveResponse
|
import dev.usbharu.hideout.core.service.resource.ResolveResponse
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -11,7 +11,7 @@ import java.io.InputStream
|
||||||
@Service
|
@Service
|
||||||
class APResourceResolveServiceImpl(
|
class APResourceResolveServiceImpl(
|
||||||
private val apRequestService: APRequestService,
|
private val apRequestService: APRequestService,
|
||||||
private val userRepository: UserRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val cacheManager: CacheManager
|
private val cacheManager: CacheManager
|
||||||
) :
|
) :
|
||||||
APResourceResolveService {
|
APResourceResolveService {
|
||||||
|
@ -19,19 +19,19 @@ class APResourceResolveServiceImpl(
|
||||||
override suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singerId: Long?): T =
|
override suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singerId: Long?): T =
|
||||||
internalResolve(url, singerId, clazz)
|
internalResolve(url, singerId, clazz)
|
||||||
|
|
||||||
override suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singer: User?): T =
|
override suspend fun <T : Object> resolve(url: String, clazz: Class<T>, singer: Actor?): T =
|
||||||
internalResolve(url, singer, clazz)
|
internalResolve(url, singer, clazz)
|
||||||
|
|
||||||
private suspend fun <T : Object> internalResolve(url: String, singerId: Long?, clazz: Class<T>): T {
|
private suspend fun <T : Object> internalResolve(url: String, singerId: Long?, clazz: Class<T>): T {
|
||||||
val key = genCacheKey(url, singerId)
|
val key = genCacheKey(url, singerId)
|
||||||
|
|
||||||
cacheManager.putCache(key) {
|
cacheManager.putCache(key) {
|
||||||
runResolve(url, singerId?.let { userRepository.findById(it) }, clazz)
|
runResolve(url, singerId?.let { actorRepository.findById(it) }, clazz)
|
||||||
}
|
}
|
||||||
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T : Object> internalResolve(url: String, singer: User?, clazz: Class<T>): T {
|
private suspend fun <T : Object> internalResolve(url: String, singer: Actor?, clazz: Class<T>): T {
|
||||||
val key = genCacheKey(url, singer?.id)
|
val key = genCacheKey(url, singer?.id)
|
||||||
cacheManager.putCache(key) {
|
cacheManager.putCache(key) {
|
||||||
runResolve(url, singer, clazz)
|
runResolve(url, singer, clazz)
|
||||||
|
@ -39,7 +39,7 @@ class APResourceResolveServiceImpl(
|
||||||
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
return (cacheManager.getOrWait(key) as APResolveResponse<T>).objects
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T : Object> runResolve(url: String, singer: User?, clazz: Class<T>): ResolveResponse =
|
private suspend fun <T : Object> runResolve(url: String, singer: Actor?, clazz: Class<T>): ResolveResponse =
|
||||||
APResolveResponse(apRequestService.apGet(url, singer, clazz))
|
APResolveResponse(apRequestService.apGet(url, singer, clazz))
|
||||||
|
|
||||||
private fun genCacheKey(url: String, singerId: Long?): String {
|
private fun genCacheKey(url: String, singerId: Long?): String {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.external.job.InboxJob
|
import dev.usbharu.hideout.core.external.job.InboxJob
|
||||||
import dev.usbharu.hideout.core.external.job.InboxJobParam
|
import dev.usbharu.hideout.core.external.job.InboxJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import dev.usbharu.hideout.util.RsaUtil
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
|
@ -29,7 +29,7 @@ class InboxJobProcessor(
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val signatureHeaderParser: SignatureHeaderParser,
|
private val signatureHeaderParser: SignatureHeaderParser,
|
||||||
private val signatureVerifier: HttpSignatureVerifier,
|
private val signatureVerifier: HttpSignatureVerifier,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val apUserService: APUserService,
|
private val apUserService: APUserService,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) : JobProcessor<InboxJobParam, InboxJob> {
|
) : JobProcessor<InboxJobParam, InboxJob> {
|
||||||
|
@ -50,7 +50,7 @@ class InboxJobProcessor(
|
||||||
|
|
||||||
val user = transaction.transaction {
|
val user = transaction.transaction {
|
||||||
try {
|
try {
|
||||||
userQueryService.findByKeyId(signature.keyId)
|
actorQueryService.findByKeyId(signature.keyId)
|
||||||
} catch (_: FailedToGetResourcesException) {
|
} catch (_: FailedToGetResourcesException) {
|
||||||
apUserService.fetchPersonWithEntity(signature.keyId).second
|
apUserService.fetchPersonWithEntity(signature.keyId).second
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ class APNoteServiceImpl(
|
||||||
postService.createRemote(
|
postService.createRemote(
|
||||||
postBuilder.of(
|
postBuilder.of(
|
||||||
id = postRepository.generateId(),
|
id = postRepository.generateId(),
|
||||||
userId = person.second.id,
|
actorId = person.second.id,
|
||||||
text = note.content,
|
text = note.content,
|
||||||
createdAt = Instant.parse(note.published).toEpochMilli(),
|
createdAt = Instant.parse(note.published).toEpochMilli(),
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverPostJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverPostJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.job.JobProcessor
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -16,13 +16,13 @@ import org.springframework.stereotype.Service
|
||||||
class ApNoteJobProcessor(
|
class ApNoteJobProcessor(
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val apRequestService: APRequestService
|
private val apRequestService: APRequestService
|
||||||
) : JobProcessor<DeliverPostJobParam, DeliverPostJob> {
|
) : JobProcessor<DeliverPostJobParam, DeliverPostJob> {
|
||||||
override suspend fun process(param: DeliverPostJobParam) {
|
override suspend fun process(param: DeliverPostJobParam) {
|
||||||
val create = objectMapper.readValue<Create>(param.create)
|
val create = objectMapper.readValue<Create>(param.create)
|
||||||
transaction.transaction {
|
transaction.transaction {
|
||||||
val signer = userQueryService.findByUrl(param.actor)
|
val signer = actorQueryService.findByUrl(param.actor)
|
||||||
|
|
||||||
logger.debug("CreateNoteJob: actor: {} create: {} inbox: {}", param.actor, create, param.inbox)
|
logger.debug("CreateNoteJob: actor: {} create: {} inbox: {}", param.actor, create, param.inbox)
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class NoteApApiServiceImpl(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (followerQueryService.alreadyFollow(findById.second.userId, userId)) {
|
if (followerQueryService.alreadyFollow(findById.second.actorId, userId)) {
|
||||||
return findById.first
|
return findById.first
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -9,8 +9,8 @@ import dev.usbharu.hideout.activitypub.service.common.resolve
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
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.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.user.RemoteUserCreateDto
|
import dev.usbharu.hideout.core.service.user.RemoteUserCreateDto
|
||||||
import dev.usbharu.hideout.core.service.user.UserService
|
import dev.usbharu.hideout.core.service.user.UserService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -28,13 +28,13 @@ interface APUserService {
|
||||||
*/
|
*/
|
||||||
suspend fun fetchPerson(url: String, targetActor: String? = null): Person
|
suspend fun fetchPerson(url: String, targetActor: String? = null): Person
|
||||||
|
|
||||||
suspend fun fetchPersonWithEntity(url: String, targetActor: String? = null): Pair<Person, User>
|
suspend fun fetchPersonWithEntity(url: String, targetActor: String? = null): Pair<Person, Actor>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class APUserServiceImpl(
|
class APUserServiceImpl(
|
||||||
private val userService: UserService,
|
private val userService: UserService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val apResourceResolveService: APResourceResolveService
|
private val apResourceResolveService: APResourceResolveService
|
||||||
|
@ -43,7 +43,7 @@ class APUserServiceImpl(
|
||||||
|
|
||||||
override suspend fun getPersonByName(name: String): Person {
|
override suspend fun getPersonByName(name: String): Person {
|
||||||
val userEntity = transaction.transaction {
|
val userEntity = transaction.transaction {
|
||||||
userQueryService.findByNameAndDomain(name, applicationConfig.url.host)
|
actorQueryService.findByNameAndDomain(name, applicationConfig.url.host)
|
||||||
}
|
}
|
||||||
// TODO: JOINで書き直し
|
// TODO: JOINで書き直し
|
||||||
val userUrl = "${applicationConfig.url}/users/$name"
|
val userUrl = "${applicationConfig.url}/users/$name"
|
||||||
|
@ -76,9 +76,9 @@ class APUserServiceImpl(
|
||||||
fetchPersonWithEntity(url, targetActor).first
|
fetchPersonWithEntity(url, targetActor).first
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, User> {
|
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, Actor> {
|
||||||
return try {
|
return try {
|
||||||
val userEntity = userQueryService.findByUrl(url)
|
val userEntity = actorQueryService.findByUrl(url)
|
||||||
val id = userEntity.url
|
val id = userEntity.url
|
||||||
return entityToPerson(userEntity, id) to userEntity
|
return entityToPerson(userEntity, id) to userEntity
|
||||||
} catch (ignore: FailedToGetResourcesException) {
|
} catch (ignore: FailedToGetResourcesException) {
|
||||||
|
@ -86,7 +86,7 @@ class APUserServiceImpl(
|
||||||
|
|
||||||
val id = person.id
|
val id = person.id
|
||||||
try {
|
try {
|
||||||
val userEntity = userQueryService.findByUrl(id)
|
val userEntity = actorQueryService.findByUrl(id)
|
||||||
return entityToPerson(userEntity, id) to userEntity
|
return entityToPerson(userEntity, id) to userEntity
|
||||||
} catch (_: FailedToGetResourcesException) {
|
} catch (_: FailedToGetResourcesException) {
|
||||||
}
|
}
|
||||||
|
@ -111,14 +111,14 @@ class APUserServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun entityToPerson(
|
private fun entityToPerson(
|
||||||
userEntity: User,
|
actorEntity: Actor,
|
||||||
id: String
|
id: String
|
||||||
) = Person(
|
) = Person(
|
||||||
type = emptyList(),
|
type = emptyList(),
|
||||||
name = userEntity.name,
|
name = actorEntity.name,
|
||||||
id = id,
|
id = id,
|
||||||
preferredUsername = userEntity.name,
|
preferredUsername = actorEntity.name,
|
||||||
summary = userEntity.description,
|
summary = actorEntity.description,
|
||||||
inbox = "$id/inbox",
|
inbox = "$id/inbox",
|
||||||
outbox = "$id/outbox",
|
outbox = "$id/outbox",
|
||||||
url = id,
|
url = id,
|
||||||
|
@ -128,12 +128,12 @@ class APUserServiceImpl(
|
||||||
url = "$id/icon.jpg"
|
url = "$id/icon.jpg"
|
||||||
),
|
),
|
||||||
publicKey = Key(
|
publicKey = Key(
|
||||||
id = userEntity.keyId,
|
id = actorEntity.keyId,
|
||||||
owner = id,
|
owner = id,
|
||||||
publicKeyPem = userEntity.publicKey
|
publicKeyPem = actorEntity.publicKey
|
||||||
),
|
),
|
||||||
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
|
||||||
followers = userEntity.followers,
|
followers = actorEntity.followers,
|
||||||
following = userEntity.following
|
following = actorEntity.following
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.webfinger
|
package dev.usbharu.hideout.activitypub.service.webfinger
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
interface WebFingerApiService {
|
interface WebFingerApiService {
|
||||||
suspend fun findByNameAndDomain(name: String, domain: String): User
|
suspend fun findByNameAndDomain(name: String, domain: String): Actor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class WebFingerApiServiceImpl(private val transaction: Transaction, private val userQueryService: UserQueryService) :
|
class WebFingerApiServiceImpl(private val transaction: Transaction, private val actorQueryService: ActorQueryService) :
|
||||||
WebFingerApiService {
|
WebFingerApiService {
|
||||||
override suspend fun findByNameAndDomain(name: String, domain: String): User {
|
override suspend fun findByNameAndDomain(name: String, domain: String): Actor {
|
||||||
return transaction.transaction {
|
return transaction.transaction {
|
||||||
userQueryService.findByNameAndDomain(name, domain)
|
actorQueryService.findByNameAndDomain(name, domain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.Htt
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureVerifierComposite
|
import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureVerifierComposite
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsImpl
|
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsImpl
|
||||||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsServiceImpl
|
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.UserDetailsServiceImpl
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.util.RsaUtil
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
import dev.usbharu.hideout.util.hasAnyScope
|
import dev.usbharu.hideout.util.hasAnyScope
|
||||||
import dev.usbharu.httpsignature.sign.RsaSha256HttpSignatureSigner
|
import dev.usbharu.httpsignature.sign.RsaSha256HttpSignatureSigner
|
||||||
|
@ -69,7 +69,7 @@ import java.util.*
|
||||||
class SecurityConfig {
|
class SecurityConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun authenticationManager(authenticationConfiguration: AuthenticationConfiguration): AuthenticationManager? =
|
fun authenticationManager(authenticationConfiguration: AuthenticationConfiguration): AuthenticationManager? =
|
||||||
|
@ -135,7 +135,7 @@ class SecurityConfig {
|
||||||
val signatureHeaderParser = DefaultSignatureHeaderParser()
|
val signatureHeaderParser = DefaultSignatureHeaderParser()
|
||||||
provider.setPreAuthenticatedUserDetailsService(
|
provider.setPreAuthenticatedUserDetailsService(
|
||||||
HttpSignatureUserDetailsService(
|
HttpSignatureUserDetailsService(
|
||||||
userQueryService,
|
actorQueryService,
|
||||||
HttpSignatureVerifierComposite(
|
HttpSignatureVerifierComposite(
|
||||||
mapOf(
|
mapOf(
|
||||||
"rsa-sha256" to RsaSha256HttpSignatureVerifier(
|
"rsa-sha256" to RsaSha256HttpSignatureVerifier(
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.user
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
data class Acct(val username: String, val domain: String? = null, val isRemote: Boolean = domain == null)
|
data class Acct(val username: String, val domain: String? = null, val isRemote: Boolean = domain == null)
|
|
@ -1,4 +1,4 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.user
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||||
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
data class User private constructor(
|
data class Actor private constructor(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val name: String,
|
val name: String,
|
||||||
val domain: String,
|
val domain: String,
|
||||||
|
@ -53,7 +53,7 @@ data class User private constructor(
|
||||||
following: String? = null,
|
following: String? = null,
|
||||||
followers: String? = null,
|
followers: String? = null,
|
||||||
instance: Long? = null
|
instance: Long? = null
|
||||||
): User {
|
): Actor {
|
||||||
// idは0未満ではいけない
|
// idは0未満ではいけない
|
||||||
require(id >= 0) { "id must be greater than or equal to 0." }
|
require(id >= 0) { "id must be greater than or equal to 0." }
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ data class User private constructor(
|
||||||
"keyId must contain non-blank characters."
|
"keyId must contain non-blank characters."
|
||||||
}
|
}
|
||||||
|
|
||||||
return User(
|
return Actor(
|
||||||
id = id,
|
id = id,
|
||||||
name = limitedName,
|
name = limitedName,
|
||||||
domain = domain,
|
domain = domain,
|
|
@ -0,0 +1,14 @@
|
||||||
|
package dev.usbharu.hideout.core.domain.model.actor
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
interface ActorRepository {
|
||||||
|
suspend fun save(actor: Actor): Actor
|
||||||
|
|
||||||
|
suspend fun findById(id: Long): Actor?
|
||||||
|
|
||||||
|
suspend fun delete(id: Long)
|
||||||
|
|
||||||
|
suspend fun nextId(): Long
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import org.springframework.stereotype.Component
|
||||||
|
|
||||||
data class Post private constructor(
|
data class Post private constructor(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val userId: Long,
|
val actorId: Long,
|
||||||
val overview: String? = null,
|
val overview: String? = null,
|
||||||
val text: String,
|
val text: String,
|
||||||
val createdAt: Long,
|
val createdAt: Long,
|
||||||
|
@ -23,7 +23,7 @@ data class Post private constructor(
|
||||||
@Suppress("FunctionMinLength", "LongParameterList")
|
@Suppress("FunctionMinLength", "LongParameterList")
|
||||||
fun of(
|
fun of(
|
||||||
id: Long,
|
id: Long,
|
||||||
userId: Long,
|
actorId: Long,
|
||||||
overview: String? = null,
|
overview: String? = null,
|
||||||
text: String,
|
text: String,
|
||||||
createdAt: Long,
|
createdAt: Long,
|
||||||
|
@ -37,7 +37,7 @@ data class Post private constructor(
|
||||||
): Post {
|
): Post {
|
||||||
require(id >= 0) { "id must be greater than or equal to 0." }
|
require(id >= 0) { "id must be greater than or equal to 0." }
|
||||||
|
|
||||||
require(userId >= 0) { "userId must be greater than or equal to 0." }
|
require(actorId >= 0) { "actorId must be greater than or equal to 0." }
|
||||||
|
|
||||||
val limitedOverview = if ((overview?.length ?: 0) >= characterLimit.post.overview) {
|
val limitedOverview = if ((overview?.length ?: 0) >= characterLimit.post.overview) {
|
||||||
overview?.substring(0, characterLimit.post.overview)
|
overview?.substring(0, characterLimit.post.overview)
|
||||||
|
@ -61,7 +61,7 @@ data class Post private constructor(
|
||||||
|
|
||||||
return Post(
|
return Post(
|
||||||
id = id,
|
id = id,
|
||||||
userId = userId,
|
actorId = actorId,
|
||||||
overview = limitedOverview,
|
overview = limitedOverview,
|
||||||
text = limitedText,
|
text = limitedText,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.reaction
|
package dev.usbharu.hideout.core.domain.model.reaction
|
||||||
|
|
||||||
data class Reaction(val id: Long, val emojiId: Long, val postId: Long, val userId: Long)
|
data class Reaction(val id: Long, val emojiId: Long, val postId: Long, val actorId: Long)
|
||||||
|
|
|
@ -3,8 +3,8 @@ package dev.usbharu.hideout.core.domain.model.relationship
|
||||||
/**
|
/**
|
||||||
* ユーザーとの関係を表します
|
* ユーザーとの関係を表します
|
||||||
*
|
*
|
||||||
* @property userId ユーザー
|
* @property actorId ユーザー
|
||||||
* @property targetUserId 相手ユーザー
|
* @property targetActorId 相手ユーザー
|
||||||
* @property following フォローしているか
|
* @property following フォローしているか
|
||||||
* @property blocking ブロックしているか
|
* @property blocking ブロックしているか
|
||||||
* @property muting ミュートしているか
|
* @property muting ミュートしているか
|
||||||
|
@ -12,8 +12,8 @@ package dev.usbharu.hideout.core.domain.model.relationship
|
||||||
* @property ignoreFollowRequestFromTarget フォローリクエストを無視しているか
|
* @property ignoreFollowRequestFromTarget フォローリクエストを無視しているか
|
||||||
*/
|
*/
|
||||||
data class Relationship(
|
data class Relationship(
|
||||||
val userId: Long,
|
val actorId: Long,
|
||||||
val targetUserId: Long,
|
val targetActorId: Long,
|
||||||
val following: Boolean,
|
val following: Boolean,
|
||||||
val blocking: Boolean,
|
val blocking: Boolean,
|
||||||
val muting: Boolean,
|
val muting: Boolean,
|
||||||
|
|
|
@ -23,9 +23,9 @@ interface RelationshipRepository {
|
||||||
/**
|
/**
|
||||||
* userIdとtargetUserIdで[Relationship]を取得します
|
* userIdとtargetUserIdで[Relationship]を取得します
|
||||||
*
|
*
|
||||||
* @param userId 取得するユーザーID
|
* @param actorId 取得するユーザーID
|
||||||
* @param targetUserId 対象ユーザーID
|
* @param targetActorId 対象ユーザーID
|
||||||
* @return 取得された[Relationship] 存在しない場合nullが返ります
|
* @return 取得された[Relationship] 存在しない場合nullが返ります
|
||||||
*/
|
*/
|
||||||
suspend fun findByUserIdAndTargetUserId(userId: Long, targetUserId: Long): Relationship?
|
suspend fun findByUserIdAndTargetUserId(actorId: Long, targetActorId: Long): Relationship?
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.relationship
|
package dev.usbharu.hideout.core.domain.model.relationship
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Users
|
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
@ -12,15 +12,15 @@ class RelationshipRepositoryImpl : RelationshipRepository {
|
||||||
val singleOrNull =
|
val singleOrNull =
|
||||||
Relationships
|
Relationships
|
||||||
.select {
|
.select {
|
||||||
(Relationships.userId eq relationship.userId)
|
(Relationships.actorId eq relationship.actorId)
|
||||||
.and(Relationships.targetUserId eq relationship.targetUserId)
|
.and(Relationships.targetActorId eq relationship.targetActorId)
|
||||||
}
|
}
|
||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
|
|
||||||
if (singleOrNull == null) {
|
if (singleOrNull == null) {
|
||||||
Relationships.insert {
|
Relationships.insert {
|
||||||
it[userId] = relationship.userId
|
it[actorId] = relationship.actorId
|
||||||
it[targetUserId] = relationship.targetUserId
|
it[targetActorId] = relationship.targetActorId
|
||||||
it[following] = relationship.following
|
it[following] = relationship.following
|
||||||
it[blocking] = relationship.blocking
|
it[blocking] = relationship.blocking
|
||||||
it[muting] = relationship.muting
|
it[muting] = relationship.muting
|
||||||
|
@ -30,8 +30,8 @@ class RelationshipRepositoryImpl : RelationshipRepository {
|
||||||
} else {
|
} else {
|
||||||
Relationships
|
Relationships
|
||||||
.update({
|
.update({
|
||||||
(Relationships.userId eq relationship.userId)
|
(Relationships.actorId eq relationship.actorId)
|
||||||
.and(Relationships.targetUserId eq relationship.targetUserId)
|
.and(Relationships.targetActorId eq relationship.targetActorId)
|
||||||
}) {
|
}) {
|
||||||
it[following] = relationship.following
|
it[following] = relationship.following
|
||||||
it[blocking] = relationship.blocking
|
it[blocking] = relationship.blocking
|
||||||
|
@ -45,23 +45,23 @@ class RelationshipRepositoryImpl : RelationshipRepository {
|
||||||
|
|
||||||
override suspend fun delete(relationship: Relationship) {
|
override suspend fun delete(relationship: Relationship) {
|
||||||
Relationships.deleteWhere {
|
Relationships.deleteWhere {
|
||||||
(Relationships.userId eq relationship.userId)
|
(Relationships.actorId eq relationship.actorId)
|
||||||
.and(Relationships.targetUserId eq relationship.targetUserId)
|
.and(Relationships.targetActorId eq relationship.targetActorId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUserIdAndTargetUserId(userId: Long, targetUserId: Long): Relationship? {
|
override suspend fun findByUserIdAndTargetUserId(actorId: Long, targetActorId: Long): Relationship? {
|
||||||
return Relationships.select {
|
return Relationships.select {
|
||||||
(Relationships.userId eq userId)
|
(Relationships.actorId eq actorId)
|
||||||
.and(Relationships.targetUserId eq targetUserId)
|
.and(Relationships.targetActorId eq targetActorId)
|
||||||
}.singleOrNull()
|
}.singleOrNull()
|
||||||
?.toRelationships()
|
?.toRelationships()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ResultRow.toRelationships(): Relationship = Relationship(
|
fun ResultRow.toRelationships(): Relationship = Relationship(
|
||||||
userId = this[Relationships.userId],
|
actorId = this[Relationships.actorId],
|
||||||
targetUserId = this[Relationships.targetUserId],
|
targetActorId = this[Relationships.targetActorId],
|
||||||
following = this[Relationships.following],
|
following = this[Relationships.following],
|
||||||
blocking = this[Relationships.blocking],
|
blocking = this[Relationships.blocking],
|
||||||
muting = this[Relationships.muting],
|
muting = this[Relationships.muting],
|
||||||
|
@ -70,8 +70,8 @@ fun ResultRow.toRelationships(): Relationship = Relationship(
|
||||||
)
|
)
|
||||||
|
|
||||||
object Relationships : LongIdTable("relationships") {
|
object Relationships : LongIdTable("relationships") {
|
||||||
val userId = long("user_id").references(Users.id)
|
val actorId = long("actor_id").references(Actors.id)
|
||||||
val targetUserId = long("target_user_id").references(Users.id)
|
val targetActorId = long("target_actor_id").references(Actors.id)
|
||||||
val following = bool("following")
|
val following = bool("following")
|
||||||
val blocking = bool("blocking")
|
val blocking = bool("blocking")
|
||||||
val muting = bool("muting")
|
val muting = bool("muting")
|
||||||
|
@ -79,6 +79,6 @@ object Relationships : LongIdTable("relationships") {
|
||||||
val ignoreFollowRequestFromTarget = bool("ignore_follow_request")
|
val ignoreFollowRequestFromTarget = bool("ignore_follow_request")
|
||||||
|
|
||||||
init {
|
init {
|
||||||
uniqueIndex(userId, targetUserId)
|
uniqueIndex(actorId, targetActorId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ data class Timeline(
|
||||||
val userId: Long,
|
val userId: Long,
|
||||||
val timelineId: Long,
|
val timelineId: Long,
|
||||||
val postId: Long,
|
val postId: Long,
|
||||||
val postUserId: Long,
|
val postActorId: Long,
|
||||||
val createdAt: Long,
|
val createdAt: Long,
|
||||||
val replyId: Long?,
|
val replyId: Long?,
|
||||||
val repostId: Long?,
|
val repostId: Long?,
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.user
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
interface UserRepository {
|
|
||||||
suspend fun save(user: User): User
|
|
||||||
|
|
||||||
suspend fun findById(id: Long): User?
|
|
||||||
|
|
||||||
suspend fun delete(id: Long)
|
|
||||||
|
|
||||||
suspend fun nextId(): Long
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ class PostResultRowMapper(private val postBuilder: Post.PostBuilder) : ResultRow
|
||||||
override fun map(resultRow: ResultRow): Post {
|
override fun map(resultRow: ResultRow): Post {
|
||||||
return postBuilder.of(
|
return postBuilder.of(
|
||||||
id = resultRow[Posts.id],
|
id = resultRow[Posts.id],
|
||||||
userId = resultRow[Posts.userId],
|
actorId = resultRow[Posts.actorId],
|
||||||
overview = resultRow[Posts.overview],
|
overview = resultRow[Posts.overview],
|
||||||
text = resultRow[Posts.text],
|
text = resultRow[Posts.text],
|
||||||
createdAt = resultRow[Posts.createdAt],
|
createdAt = resultRow[Posts.createdAt],
|
||||||
|
|
|
@ -2,11 +2,11 @@ package dev.usbharu.hideout.core.infrastructure.exposed
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.QueryMapper
|
import dev.usbharu.hideout.application.infrastructure.exposed.QueryMapper
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import org.jetbrains.exposed.sql.Query
|
import org.jetbrains.exposed.sql.Query
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class UserQueryMapper(private val userResultRowMapper: ResultRowMapper<User>) : QueryMapper<User> {
|
class UserQueryMapper(private val actorResultRowMapper: ResultRowMapper<Actor>) : QueryMapper<Actor> {
|
||||||
override fun map(query: Query): List<User> = query.map(userResultRowMapper::map)
|
override fun map(query: Query): List<Actor> = query.map(actorResultRowMapper::map)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposed
|
package dev.usbharu.hideout.core.infrastructure.exposed
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Users
|
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class UserResultRowMapper(private val userBuilder: User.UserBuilder) : ResultRowMapper<User> {
|
class UserResultRowMapper(private val actorBuilder: Actor.UserBuilder) : ResultRowMapper<Actor> {
|
||||||
override fun map(resultRow: ResultRow): User {
|
override fun map(resultRow: ResultRow): Actor {
|
||||||
return userBuilder.of(
|
return actorBuilder.of(
|
||||||
id = resultRow[Users.id],
|
id = resultRow[Actors.id],
|
||||||
name = resultRow[Users.name],
|
name = resultRow[Actors.name],
|
||||||
domain = resultRow[Users.domain],
|
domain = resultRow[Actors.domain],
|
||||||
screenName = resultRow[Users.screenName],
|
screenName = resultRow[Actors.screenName],
|
||||||
description = resultRow[Users.description],
|
description = resultRow[Actors.description],
|
||||||
password = resultRow[Users.password],
|
password = resultRow[Actors.password],
|
||||||
inbox = resultRow[Users.inbox],
|
inbox = resultRow[Actors.inbox],
|
||||||
outbox = resultRow[Users.outbox],
|
outbox = resultRow[Actors.outbox],
|
||||||
url = resultRow[Users.url],
|
url = resultRow[Actors.url],
|
||||||
publicKey = resultRow[Users.publicKey],
|
publicKey = resultRow[Actors.publicKey],
|
||||||
privateKey = resultRow[Users.privateKey],
|
privateKey = resultRow[Actors.privateKey],
|
||||||
createdAt = Instant.ofEpochMilli((resultRow[Users.createdAt])),
|
createdAt = Instant.ofEpochMilli((resultRow[Actors.createdAt])),
|
||||||
keyId = resultRow[Users.keyId],
|
keyId = resultRow[Actors.keyId],
|
||||||
followers = resultRow[Users.followers],
|
followers = resultRow[Actors.followers],
|
||||||
following = resultRow[Users.following],
|
following = resultRow[Actors.following],
|
||||||
instance = resultRow[Users.instance]
|
instance = resultRow[Actors.instance]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package dev.usbharu.hideout.core.infrastructure.exposedquery
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.QueryMapper
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
|
import dev.usbharu.hideout.util.singleOr
|
||||||
|
import org.jetbrains.exposed.sql.and
|
||||||
|
import org.jetbrains.exposed.sql.select
|
||||||
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
class ActorQueryServiceImpl(
|
||||||
|
private val actorResultRowMapper: ResultRowMapper<Actor>,
|
||||||
|
private val actorQueryMapper: QueryMapper<Actor>
|
||||||
|
) : ActorQueryService {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(ActorQueryServiceImpl::class.java)
|
||||||
|
|
||||||
|
override suspend fun findAll(limit: Int, offset: Long): List<Actor> =
|
||||||
|
Actors.selectAll().limit(limit, offset).let(actorQueryMapper::map)
|
||||||
|
|
||||||
|
override suspend fun findById(id: Long): Actor = Actors.select { Actors.id eq id }
|
||||||
|
.singleOr { FailedToGetResourcesException("id: $id is duplicate or does not exist.", it) }
|
||||||
|
.let(actorResultRowMapper::map)
|
||||||
|
|
||||||
|
override suspend fun findByName(name: String): List<Actor> =
|
||||||
|
Actors.select { Actors.name eq name }.let(actorQueryMapper::map)
|
||||||
|
|
||||||
|
override suspend fun findByNameAndDomain(name: String, domain: String): Actor =
|
||||||
|
Actors
|
||||||
|
.select { Actors.name eq name and (Actors.domain eq domain) }
|
||||||
|
.singleOr {
|
||||||
|
FailedToGetResourcesException("name: $name,domain: $domain is duplicate or does not exist.", it)
|
||||||
|
}
|
||||||
|
.let(actorResultRowMapper::map)
|
||||||
|
|
||||||
|
override suspend fun findByUrl(url: String): Actor {
|
||||||
|
logger.trace("findByUrl url: $url")
|
||||||
|
return Actors.select { Actors.url eq url }
|
||||||
|
.singleOr { FailedToGetResourcesException("url: $url is duplicate or does not exist.", it) }
|
||||||
|
.let(actorResultRowMapper::map)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun findByIds(ids: List<Long>): List<Actor> =
|
||||||
|
Actors.select { Actors.id inList ids }.let(actorQueryMapper::map)
|
||||||
|
|
||||||
|
override suspend fun existByNameAndDomain(name: String, domain: String): Boolean =
|
||||||
|
Actors.select { Actors.name eq name and (Actors.domain eq domain) }.empty().not()
|
||||||
|
|
||||||
|
override suspend fun findByKeyId(keyId: String): Actor {
|
||||||
|
return Actors.select { Actors.keyId eq keyId }
|
||||||
|
.singleOr { FailedToGetResourcesException("keyId: $keyId is duplicate or does not exist.", it) }
|
||||||
|
.let(actorResultRowMapper::map)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,24 +1,24 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposedquery
|
package dev.usbharu.hideout.core.infrastructure.exposedquery
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.RelationshipQueryService
|
import dev.usbharu.hideout.core.query.RelationshipQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class FollowerQueryServiceImpl(
|
class FollowerQueryServiceImpl(
|
||||||
private val relationshipQueryService: RelationshipQueryService,
|
private val relationshipQueryService: RelationshipQueryService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val relationshipRepository: RelationshipRepository
|
private val relationshipRepository: RelationshipRepository
|
||||||
) : FollowerQueryService {
|
) : FollowerQueryService {
|
||||||
override suspend fun findFollowersById(id: Long): List<User> {
|
override suspend fun findFollowersById(id: Long): List<Actor> {
|
||||||
return userQueryService.findByIds(
|
return actorQueryService.findByIds(
|
||||||
relationshipQueryService.findByTargetIdAndFollowing(id, true).map { it.userId }
|
relationshipQueryService.findByTargetIdAndFollowing(id, true).map { it.actorId }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun alreadyFollow(userId: Long, followerId: Long): Boolean =
|
override suspend fun alreadyFollow(actorId: Long, followerId: Long): Boolean =
|
||||||
relationshipRepository.findByUserIdAndTargetUserId(followerId, userId)?.following ?: false
|
relationshipRepository.findByUserIdAndTargetUserId(followerId, actorId)?.following ?: false
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,44 +6,46 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Reactions
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction
|
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction
|
||||||
import dev.usbharu.hideout.core.query.ReactionQueryService
|
import dev.usbharu.hideout.core.query.ReactionQueryService
|
||||||
import dev.usbharu.hideout.util.singleOr
|
import dev.usbharu.hideout.util.singleOr
|
||||||
import org.jetbrains.exposed.sql.*
|
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.jetbrains.exposed.sql.and
|
||||||
|
import org.jetbrains.exposed.sql.deleteWhere
|
||||||
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class ReactionQueryServiceImpl : ReactionQueryService {
|
class ReactionQueryServiceImpl : ReactionQueryService {
|
||||||
override suspend fun findByPostId(postId: Long, userId: Long?): List<Reaction> {
|
override suspend fun findByPostId(postId: Long, actorId: Long?): List<Reaction> {
|
||||||
return Reactions.select {
|
return Reactions.select {
|
||||||
Reactions.postId.eq(postId)
|
Reactions.postId.eq(postId)
|
||||||
}.map { it.toReaction() }
|
}.map { it.toReaction() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionMaxLength")
|
@Suppress("FunctionMaxLength")
|
||||||
override suspend fun findByPostIdAndUserIdAndEmojiId(postId: Long, userId: Long, emojiId: Long): Reaction {
|
override suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction {
|
||||||
return Reactions
|
return Reactions
|
||||||
.select {
|
.select {
|
||||||
Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and(
|
Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)).and(
|
||||||
Reactions.emojiId.eq(emojiId)
|
Reactions.emojiId.eq(emojiId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.singleOr {
|
.singleOr {
|
||||||
FailedToGetResourcesException(
|
FailedToGetResourcesException(
|
||||||
"postId: $postId,userId: $userId,emojiId: $emojiId is duplicate or does not exist.",
|
"postId: $postId,userId: $actorId,emojiId: $emojiId is duplicate or does not exist.",
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.toReaction()
|
.toReaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun reactionAlreadyExist(postId: Long, userId: Long, emojiId: Long): Boolean {
|
override suspend fun reactionAlreadyExist(postId: Long, actorId: Long, emojiId: Long): Boolean {
|
||||||
return Reactions.select {
|
return Reactions.select {
|
||||||
Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and(
|
Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)).and(
|
||||||
Reactions.emojiId.eq(emojiId)
|
Reactions.emojiId.eq(emojiId)
|
||||||
)
|
)
|
||||||
}.empty().not()
|
}.empty().not()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteByPostIdAndUserId(postId: Long, userId: Long) {
|
override suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long) {
|
||||||
Reactions.deleteWhere { Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)) }
|
Reactions.deleteWhere { Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,6 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class RelationshipQueryServiceImpl : RelationshipQueryService {
|
class RelationshipQueryServiceImpl : RelationshipQueryService {
|
||||||
override suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship> =
|
override suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List<Relationship> =
|
||||||
Relationships.select { Relationships.targetUserId eq targetId and (Relationships.following eq following) }
|
Relationships.select { Relationships.targetActorId eq targetId and (Relationships.following eq following) }
|
||||||
.map { it.toRelationships() }
|
.map { it.toRelationships() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposedquery
|
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.QueryMapper
|
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
|
||||||
import dev.usbharu.hideout.core.infrastructure.exposedrepository.Users
|
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.util.singleOr
|
|
||||||
import org.jetbrains.exposed.sql.and
|
|
||||||
import org.jetbrains.exposed.sql.select
|
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
class UserQueryServiceImpl(
|
|
||||||
private val userResultRowMapper: ResultRowMapper<User>,
|
|
||||||
private val userQueryMapper: QueryMapper<User>
|
|
||||||
) : UserQueryService {
|
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(UserQueryServiceImpl::class.java)
|
|
||||||
|
|
||||||
override suspend fun findAll(limit: Int, offset: Long): List<User> =
|
|
||||||
Users.selectAll().limit(limit, offset).let(userQueryMapper::map)
|
|
||||||
|
|
||||||
override suspend fun findById(id: Long): User = Users.select { Users.id eq id }
|
|
||||||
.singleOr { FailedToGetResourcesException("id: $id is duplicate or does not exist.", it) }
|
|
||||||
.let(userResultRowMapper::map)
|
|
||||||
|
|
||||||
override suspend fun findByName(name: String): List<User> =
|
|
||||||
Users.select { Users.name eq name }.let(userQueryMapper::map)
|
|
||||||
|
|
||||||
override suspend fun findByNameAndDomain(name: String, domain: String): User =
|
|
||||||
Users
|
|
||||||
.select { Users.name eq name and (Users.domain eq domain) }
|
|
||||||
.singleOr {
|
|
||||||
FailedToGetResourcesException("name: $name,domain: $domain is duplicate or does not exist.", it)
|
|
||||||
}
|
|
||||||
.let(userResultRowMapper::map)
|
|
||||||
|
|
||||||
override suspend fun findByUrl(url: String): User {
|
|
||||||
logger.trace("findByUrl url: $url")
|
|
||||||
return Users.select { Users.url eq url }
|
|
||||||
.singleOr { FailedToGetResourcesException("url: $url is duplicate or does not exist.", it) }
|
|
||||||
.let(userResultRowMapper::map)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findByIds(ids: List<Long>): List<User> =
|
|
||||||
Users.select { Users.id inList ids }.let(userQueryMapper::map)
|
|
||||||
|
|
||||||
override suspend fun existByNameAndDomain(name: String, domain: String): Boolean =
|
|
||||||
Users.select { Users.name eq name and (Users.domain eq domain) }.empty().not()
|
|
||||||
|
|
||||||
override suspend fun findByKeyId(keyId: String): User {
|
|
||||||
return Users.select { Users.keyId eq keyId }
|
|
||||||
.singleOr { FailedToGetResourcesException("keyId: $keyId is duplicate or does not exist.", it) }
|
|
||||||
.let(userResultRowMapper::map)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
||||||
|
import dev.usbharu.hideout.application.service.id.IdGenerateService
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
class ActorRepositoryImpl(
|
||||||
|
private val idGenerateService: IdGenerateService,
|
||||||
|
private val actorResultRowMapper: ResultRowMapper<Actor>
|
||||||
|
) :
|
||||||
|
ActorRepository {
|
||||||
|
|
||||||
|
override suspend fun save(actor: Actor): Actor {
|
||||||
|
val singleOrNull = Actors.select { Actors.id eq actor.id }.empty()
|
||||||
|
if (singleOrNull) {
|
||||||
|
Actors.insert {
|
||||||
|
it[id] = actor.id
|
||||||
|
it[name] = actor.name
|
||||||
|
it[domain] = actor.domain
|
||||||
|
it[screenName] = actor.screenName
|
||||||
|
it[description] = actor.description
|
||||||
|
it[password] = actor.password
|
||||||
|
it[inbox] = actor.inbox
|
||||||
|
it[outbox] = actor.outbox
|
||||||
|
it[url] = actor.url
|
||||||
|
it[createdAt] = actor.createdAt.toEpochMilli()
|
||||||
|
it[publicKey] = actor.publicKey
|
||||||
|
it[privateKey] = actor.privateKey
|
||||||
|
it[keyId] = actor.keyId
|
||||||
|
it[following] = actor.following
|
||||||
|
it[followers] = actor.followers
|
||||||
|
it[instance] = actor.instance
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Actors.update({ Actors.id eq actor.id }) {
|
||||||
|
it[name] = actor.name
|
||||||
|
it[domain] = actor.domain
|
||||||
|
it[screenName] = actor.screenName
|
||||||
|
it[description] = actor.description
|
||||||
|
it[password] = actor.password
|
||||||
|
it[inbox] = actor.inbox
|
||||||
|
it[outbox] = actor.outbox
|
||||||
|
it[url] = actor.url
|
||||||
|
it[createdAt] = actor.createdAt.toEpochMilli()
|
||||||
|
it[publicKey] = actor.publicKey
|
||||||
|
it[privateKey] = actor.privateKey
|
||||||
|
it[keyId] = actor.keyId
|
||||||
|
it[following] = actor.following
|
||||||
|
it[followers] = actor.followers
|
||||||
|
it[instance] = actor.instance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return actor
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun findById(id: Long): Actor? =
|
||||||
|
Actors.select { Actors.id eq id }.singleOrNull()?.let(actorResultRowMapper::map)
|
||||||
|
|
||||||
|
override suspend fun delete(id: Long) {
|
||||||
|
Actors.deleteWhere { Actors.id.eq(id) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun nextId(): Long = idGenerateService.generateId()
|
||||||
|
}
|
||||||
|
|
||||||
|
object Actors : Table("users") {
|
||||||
|
val id: Column<Long> = long("id")
|
||||||
|
val name: Column<String> = varchar("name", length = 300)
|
||||||
|
val domain: Column<String> = varchar("domain", length = 1000)
|
||||||
|
val screenName: Column<String> = varchar("screen_name", length = 300)
|
||||||
|
val description: Column<String> = varchar(
|
||||||
|
"description",
|
||||||
|
length = 10000
|
||||||
|
)
|
||||||
|
val password: Column<String?> = varchar("password", length = 255).nullable()
|
||||||
|
val inbox: Column<String> = varchar("inbox", length = 1000).uniqueIndex()
|
||||||
|
val outbox: Column<String> = varchar("outbox", length = 1000).uniqueIndex()
|
||||||
|
val url: Column<String> = varchar("url", length = 1000).uniqueIndex()
|
||||||
|
val publicKey: Column<String> = varchar("public_key", length = 10000)
|
||||||
|
val privateKey: Column<String?> = varchar(
|
||||||
|
"private_key",
|
||||||
|
length = 10000
|
||||||
|
).nullable()
|
||||||
|
val createdAt: Column<Long> = long("created_at")
|
||||||
|
val keyId = varchar("key_id", length = 1000)
|
||||||
|
val following = varchar("following", length = 1000).nullable()
|
||||||
|
val followers = varchar("followers", length = 1000).nullable()
|
||||||
|
val instance = long("instance").references(Instance.id).nullable()
|
||||||
|
|
||||||
|
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||||
|
|
||||||
|
init {
|
||||||
|
uniqueIndex(name, domain)
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService
|
||||||
it[userId] = timeline.userId
|
it[userId] = timeline.userId
|
||||||
it[timelineId] = timeline.timelineId
|
it[timelineId] = timeline.timelineId
|
||||||
it[postId] = timeline.postId
|
it[postId] = timeline.postId
|
||||||
it[postUserId] = timeline.postUserId
|
it[postUserId] = timeline.postActorId
|
||||||
it[createdAt] = timeline.createdAt
|
it[createdAt] = timeline.createdAt
|
||||||
it[replyId] = timeline.replyId
|
it[replyId] = timeline.replyId
|
||||||
it[repostId] = timeline.repostId
|
it[repostId] = timeline.repostId
|
||||||
|
@ -37,7 +37,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService
|
||||||
it[userId] = timeline.userId
|
it[userId] = timeline.userId
|
||||||
it[timelineId] = timeline.timelineId
|
it[timelineId] = timeline.timelineId
|
||||||
it[postId] = timeline.postId
|
it[postId] = timeline.postId
|
||||||
it[postUserId] = timeline.postUserId
|
it[postUserId] = timeline.postActorId
|
||||||
it[createdAt] = timeline.createdAt
|
it[createdAt] = timeline.createdAt
|
||||||
it[replyId] = timeline.replyId
|
it[replyId] = timeline.replyId
|
||||||
it[repostId] = timeline.repostId
|
it[repostId] = timeline.repostId
|
||||||
|
@ -57,7 +57,7 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService
|
||||||
this[Timelines.userId] = it.userId
|
this[Timelines.userId] = it.userId
|
||||||
this[Timelines.timelineId] = it.timelineId
|
this[Timelines.timelineId] = it.timelineId
|
||||||
this[Timelines.postId] = it.postId
|
this[Timelines.postId] = it.postId
|
||||||
this[Timelines.postUserId] = it.postUserId
|
this[Timelines.postUserId] = it.postActorId
|
||||||
this[Timelines.createdAt] = it.createdAt
|
this[Timelines.createdAt] = it.createdAt
|
||||||
this[Timelines.replyId] = it.replyId
|
this[Timelines.replyId] = it.replyId
|
||||||
this[Timelines.repostId] = it.repostId
|
this[Timelines.repostId] = it.repostId
|
||||||
|
@ -84,7 +84,7 @@ fun ResultRow.toTimeline(): Timeline {
|
||||||
userId = this[Timelines.userId],
|
userId = this[Timelines.userId],
|
||||||
timelineId = this[Timelines.timelineId],
|
timelineId = this[Timelines.timelineId],
|
||||||
postId = this[Timelines.postId],
|
postId = this[Timelines.postId],
|
||||||
postUserId = this[Timelines.postUserId],
|
postActorId = this[Timelines.postUserId],
|
||||||
createdAt = this[Timelines.createdAt],
|
createdAt = this[Timelines.createdAt],
|
||||||
replyId = this[Timelines.replyId],
|
replyId = this[Timelines.replyId],
|
||||||
repostId = this[Timelines.repostId],
|
repostId = this[Timelines.repostId],
|
||||||
|
|
|
@ -23,7 +23,7 @@ class PostRepositoryImpl(
|
||||||
if (singleOrNull == null) {
|
if (singleOrNull == null) {
|
||||||
Posts.insert {
|
Posts.insert {
|
||||||
it[id] = post.id
|
it[id] = post.id
|
||||||
it[userId] = post.userId
|
it[actorId] = post.actorId
|
||||||
it[overview] = post.overview
|
it[overview] = post.overview
|
||||||
it[text] = post.text
|
it[text] = post.text
|
||||||
it[createdAt] = post.createdAt
|
it[createdAt] = post.createdAt
|
||||||
|
@ -47,7 +47,7 @@ class PostRepositoryImpl(
|
||||||
this[PostsMedia.mediaId] = it
|
this[PostsMedia.mediaId] = it
|
||||||
}
|
}
|
||||||
Posts.update({ Posts.id eq post.id }) {
|
Posts.update({ Posts.id eq post.id }) {
|
||||||
it[userId] = post.userId
|
it[actorId] = post.actorId
|
||||||
it[overview] = post.overview
|
it[overview] = post.overview
|
||||||
it[text] = post.text
|
it[text] = post.text
|
||||||
it[createdAt] = post.createdAt
|
it[createdAt] = post.createdAt
|
||||||
|
@ -75,7 +75,7 @@ class PostRepositoryImpl(
|
||||||
|
|
||||||
object Posts : Table() {
|
object Posts : Table() {
|
||||||
val id: Column<Long> = long("id")
|
val id: Column<Long> = long("id")
|
||||||
val userId: Column<Long> = long("user_id").references(Users.id)
|
val actorId: Column<Long> = long("actor_id").references(Actors.id)
|
||||||
val overview: Column<String?> = varchar("overview", 100).nullable()
|
val overview: Column<String?> = varchar("overview", 100).nullable()
|
||||||
val text: Column<String> = varchar("text", 3000)
|
val text: Column<String> = varchar("text", 3000)
|
||||||
val createdAt: Column<Long> = long("created_at")
|
val createdAt: Column<Long> = long("created_at")
|
||||||
|
|
|
@ -21,13 +21,13 @@ class ReactionRepositoryImpl(
|
||||||
it[id] = reaction.id
|
it[id] = reaction.id
|
||||||
it[emojiId] = reaction.emojiId
|
it[emojiId] = reaction.emojiId
|
||||||
it[postId] = reaction.postId
|
it[postId] = reaction.postId
|
||||||
it[userId] = reaction.userId
|
it[actorId] = reaction.actorId
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Reactions.update({ Reactions.id eq reaction.id }) {
|
Reactions.update({ Reactions.id eq reaction.id }) {
|
||||||
it[emojiId] = reaction.emojiId
|
it[emojiId] = reaction.emojiId
|
||||||
it[postId] = reaction.postId
|
it[postId] = reaction.postId
|
||||||
it[userId] = reaction.userId
|
it[actorId] = reaction.actorId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reaction
|
return reaction
|
||||||
|
@ -37,7 +37,7 @@ class ReactionRepositoryImpl(
|
||||||
Reactions.deleteWhere {
|
Reactions.deleteWhere {
|
||||||
id.eq(reaction.id)
|
id.eq(reaction.id)
|
||||||
.and(postId.eq(reaction.postId))
|
.and(postId.eq(reaction.postId))
|
||||||
.and(userId.eq(reaction.postId))
|
.and(actorId.eq(reaction.postId))
|
||||||
.and(emojiId.eq(reaction.emojiId))
|
.and(emojiId.eq(reaction.emojiId))
|
||||||
}
|
}
|
||||||
return reaction
|
return reaction
|
||||||
|
@ -49,16 +49,16 @@ fun ResultRow.toReaction(): Reaction {
|
||||||
this[Reactions.id].value,
|
this[Reactions.id].value,
|
||||||
this[Reactions.emojiId],
|
this[Reactions.emojiId],
|
||||||
this[Reactions.postId],
|
this[Reactions.postId],
|
||||||
this[Reactions.userId]
|
this[Reactions.actorId]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Reactions : LongIdTable("reactions") {
|
object Reactions : LongIdTable("reactions") {
|
||||||
val emojiId: Column<Long> = long("emoji_id")
|
val emojiId: Column<Long> = long("emoji_id")
|
||||||
val postId: Column<Long> = long("post_id").references(Posts.id)
|
val postId: Column<Long> = long("post_id").references(Posts.id)
|
||||||
val userId: Column<Long> = long("user_id").references(Users.id)
|
val actorId: Column<Long> = long("actor_id").references(Actors.id)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
uniqueIndex(emojiId, postId, userId)
|
uniqueIndex(emojiId, postId, actorId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.ResultRowMapper
|
|
||||||
import dev.usbharu.hideout.application.service.id.IdGenerateService
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
|
||||||
import org.jetbrains.exposed.sql.*
|
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
class UserRepositoryImpl(
|
|
||||||
private val idGenerateService: IdGenerateService,
|
|
||||||
private val userResultRowMapper: ResultRowMapper<User>
|
|
||||||
) :
|
|
||||||
UserRepository {
|
|
||||||
|
|
||||||
override suspend fun save(user: User): User {
|
|
||||||
val singleOrNull = Users.select { Users.id eq user.id }.empty()
|
|
||||||
if (singleOrNull) {
|
|
||||||
Users.insert {
|
|
||||||
it[id] = user.id
|
|
||||||
it[name] = user.name
|
|
||||||
it[domain] = user.domain
|
|
||||||
it[screenName] = user.screenName
|
|
||||||
it[description] = user.description
|
|
||||||
it[password] = user.password
|
|
||||||
it[inbox] = user.inbox
|
|
||||||
it[outbox] = user.outbox
|
|
||||||
it[url] = user.url
|
|
||||||
it[createdAt] = user.createdAt.toEpochMilli()
|
|
||||||
it[publicKey] = user.publicKey
|
|
||||||
it[privateKey] = user.privateKey
|
|
||||||
it[keyId] = user.keyId
|
|
||||||
it[following] = user.following
|
|
||||||
it[followers] = user.followers
|
|
||||||
it[instance] = user.instance
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Users.update({ Users.id eq user.id }) {
|
|
||||||
it[name] = user.name
|
|
||||||
it[domain] = user.domain
|
|
||||||
it[screenName] = user.screenName
|
|
||||||
it[description] = user.description
|
|
||||||
it[password] = user.password
|
|
||||||
it[inbox] = user.inbox
|
|
||||||
it[outbox] = user.outbox
|
|
||||||
it[url] = user.url
|
|
||||||
it[createdAt] = user.createdAt.toEpochMilli()
|
|
||||||
it[publicKey] = user.publicKey
|
|
||||||
it[privateKey] = user.privateKey
|
|
||||||
it[keyId] = user.keyId
|
|
||||||
it[following] = user.following
|
|
||||||
it[followers] = user.followers
|
|
||||||
it[instance] = user.instance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return user
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findById(id: Long): User? =
|
|
||||||
Users.select { Users.id eq id }.singleOrNull()?.let(userResultRowMapper::map)
|
|
||||||
|
|
||||||
override suspend fun delete(id: Long) {
|
|
||||||
Users.deleteWhere { Users.id.eq(id) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun nextId(): Long = idGenerateService.generateId()
|
|
||||||
}
|
|
||||||
|
|
||||||
object Users : Table("users") {
|
|
||||||
val id: Column<Long> = long("id")
|
|
||||||
val name: Column<String> = varchar("name", length = 300)
|
|
||||||
val domain: Column<String> = varchar("domain", length = 1000)
|
|
||||||
val screenName: Column<String> = varchar("screen_name", length = 300)
|
|
||||||
val description: Column<String> = varchar(
|
|
||||||
"description",
|
|
||||||
length = 10000
|
|
||||||
)
|
|
||||||
val password: Column<String?> = varchar("password", length = 255).nullable()
|
|
||||||
val inbox: Column<String> = varchar("inbox", length = 1000).uniqueIndex()
|
|
||||||
val outbox: Column<String> = varchar("outbox", length = 1000).uniqueIndex()
|
|
||||||
val url: Column<String> = varchar("url", length = 1000).uniqueIndex()
|
|
||||||
val publicKey: Column<String> = varchar("public_key", length = 10000)
|
|
||||||
val privateKey: Column<String?> = varchar(
|
|
||||||
"private_key",
|
|
||||||
length = 10000
|
|
||||||
).nullable()
|
|
||||||
val createdAt: Column<Long> = long("created_at")
|
|
||||||
val keyId = varchar("key_id", length = 1000)
|
|
||||||
val following = varchar("following", length = 1000).nullable()
|
|
||||||
val followers = varchar("followers", length = 1000).nullable()
|
|
||||||
val instance = long("instance").references(Instance.id).nullable()
|
|
||||||
|
|
||||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
|
||||||
|
|
||||||
init {
|
|
||||||
uniqueIndex(name, domain)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.httpsignature
|
||||||
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.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.exception.HttpSignatureVerifyException
|
import dev.usbharu.hideout.core.domain.exception.HttpSignatureVerifyException
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.util.RsaUtil
|
import dev.usbharu.hideout.util.RsaUtil
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
import dev.usbharu.httpsignature.common.HttpRequest
|
import dev.usbharu.httpsignature.common.HttpRequest
|
||||||
|
@ -20,7 +20,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException
|
||||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken
|
||||||
|
|
||||||
class HttpSignatureUserDetailsService(
|
class HttpSignatureUserDetailsService(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val httpSignatureVerifier: HttpSignatureVerifier,
|
private val httpSignatureVerifier: HttpSignatureVerifier,
|
||||||
private val transaction: Transaction,
|
private val transaction: Transaction,
|
||||||
private val httpSignatureHeaderParser: SignatureHeaderParser
|
private val httpSignatureHeaderParser: SignatureHeaderParser
|
||||||
|
@ -35,7 +35,7 @@ class HttpSignatureUserDetailsService(
|
||||||
val keyId = token.principal as String
|
val keyId = token.principal as String
|
||||||
val findByKeyId = transaction.transaction {
|
val findByKeyId = transaction.transaction {
|
||||||
try {
|
try {
|
||||||
userQueryService.findByKeyId(keyId)
|
actorQueryService.findByKeyId(keyId)
|
||||||
} catch (e: FailedToGetResourcesException) {
|
} catch (e: FailedToGetResourcesException) {
|
||||||
throw UsernameNotFoundException("User not found", e)
|
throw UsernameNotFoundException("User not found", e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.usbharu.hideout.core.infrastructure.springframework.oauth2
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.springframework.security.core.userdetails.UserDetails
|
import org.springframework.security.core.userdetails.UserDetails
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService
|
import org.springframework.security.core.userdetails.UserDetailsService
|
||||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class UserDetailsServiceImpl(
|
class UserDetailsServiceImpl(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) :
|
) :
|
||||||
|
@ -21,7 +21,7 @@ class UserDetailsServiceImpl(
|
||||||
throw UsernameNotFoundException("$username not found")
|
throw UsernameNotFoundException("$username not found")
|
||||||
}
|
}
|
||||||
transaction.transaction {
|
transaction.transaction {
|
||||||
val findById = userQueryService.findByNameAndDomain(username, applicationConfig.url.host)
|
val findById = actorQueryService.findByNameAndDomain(username, applicationConfig.url.host)
|
||||||
UserDetailsImpl(
|
UserDetailsImpl(
|
||||||
id = findById.id,
|
id = findById.id,
|
||||||
username = findById.name,
|
username = findById.name,
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package dev.usbharu.hideout.core.query
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
interface ActorQueryService {
|
||||||
|
suspend fun findAll(limit: Int, offset: Long): List<Actor>
|
||||||
|
suspend fun findById(id: Long): Actor
|
||||||
|
suspend fun findByName(name: String): List<Actor>
|
||||||
|
suspend fun findByNameAndDomain(name: String, domain: String): Actor
|
||||||
|
suspend fun findByUrl(url: String): Actor
|
||||||
|
suspend fun findByIds(ids: List<Long>): List<Actor>
|
||||||
|
suspend fun existByNameAndDomain(name: String, domain: String): Boolean
|
||||||
|
suspend fun findByKeyId(keyId: String): Actor
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
package dev.usbharu.hideout.core.query
|
package dev.usbharu.hideout.core.query
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
@Deprecated("Use RelationshipQueryService")
|
@Deprecated("Use RelationshipQueryService")
|
||||||
interface FollowerQueryService {
|
interface FollowerQueryService {
|
||||||
suspend fun findFollowersById(id: Long): List<User>
|
suspend fun findFollowersById(id: Long): List<Actor>
|
||||||
suspend fun alreadyFollow(userId: Long, followerId: Long): Boolean
|
suspend fun alreadyFollow(actorId: Long, followerId: Long): Boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@ import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface ReactionQueryService {
|
interface ReactionQueryService {
|
||||||
suspend fun findByPostId(postId: Long, userId: Long? = null): List<Reaction>
|
suspend fun findByPostId(postId: Long, actorId: Long? = null): List<Reaction>
|
||||||
|
|
||||||
@Suppress("FunctionMaxLength")
|
@Suppress("FunctionMaxLength")
|
||||||
suspend fun findByPostIdAndUserIdAndEmojiId(postId: Long, userId: Long, emojiId: Long): Reaction
|
suspend fun findByPostIdAndActorIdAndEmojiId(postId: Long, actorId: Long, emojiId: Long): Reaction
|
||||||
|
|
||||||
suspend fun reactionAlreadyExist(postId: Long, userId: Long, emojiId: Long): Boolean
|
suspend fun reactionAlreadyExist(postId: Long, actorId: Long, emojiId: Long): Boolean
|
||||||
|
|
||||||
suspend fun deleteByPostIdAndUserId(postId: Long, userId: Long)
|
suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.query
|
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
interface UserQueryService {
|
|
||||||
suspend fun findAll(limit: Int, offset: Long): List<User>
|
|
||||||
suspend fun findById(id: Long): User
|
|
||||||
suspend fun findByName(name: String): List<User>
|
|
||||||
suspend fun findByNameAndDomain(name: String, domain: String): User
|
|
||||||
suspend fun findByUrl(url: String): User
|
|
||||||
suspend fun findByIds(ids: List<Long>): List<User>
|
|
||||||
suspend fun existByNameAndDomain(name: String, domain: String): Boolean
|
|
||||||
suspend fun findByKeyId(keyId: String): User
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
package dev.usbharu.hideout.core.service.follow
|
package dev.usbharu.hideout.core.service.follow
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
|
||||||
data class SendFollowDto(val userId: User, val followTargetUserId: User)
|
data class SendFollowDto(val actorId: Actor, val followTargetActorId: Actor)
|
||||||
|
|
|
@ -2,9 +2,9 @@ package dev.usbharu.hideout.core.service.post
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
||||||
import dev.usbharu.hideout.core.domain.exception.UserNotFoundException
|
import dev.usbharu.hideout.core.domain.exception.UserNotFoundException
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
||||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||||
|
@ -16,7 +16,7 @@ import java.time.Instant
|
||||||
@Service
|
@Service
|
||||||
class PostServiceImpl(
|
class PostServiceImpl(
|
||||||
private val postRepository: PostRepository,
|
private val postRepository: PostRepository,
|
||||||
private val userRepository: UserRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val timelineService: TimelineService,
|
private val timelineService: TimelineService,
|
||||||
private val postQueryService: PostQueryService,
|
private val postQueryService: PostQueryService,
|
||||||
private val postBuilder: Post.PostBuilder,
|
private val postBuilder: Post.PostBuilder,
|
||||||
|
@ -32,7 +32,7 @@ class PostServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createRemote(post: Post): Post {
|
override suspend fun createRemote(post: Post): Post {
|
||||||
logger.info("START Create Remote Post user: {}, remote url: {}", post.userId, post.apId)
|
logger.info("START Create Remote Post user: {}, remote url: {}", post.actorId, post.apId)
|
||||||
val createdPost = internalCreate(post, false)
|
val createdPost = internalCreate(post, false)
|
||||||
logger.info("SUCCESS Create Remote Post url: {}", createdPost.url)
|
logger.info("SUCCESS Create Remote Post url: {}", createdPost.url)
|
||||||
return createdPost
|
return createdPost
|
||||||
|
@ -55,11 +55,11 @@ class PostServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
||||||
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
val user = actorRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
||||||
val id = postRepository.generateId()
|
val id = postRepository.generateId()
|
||||||
val createPost = postBuilder.of(
|
val createPost = postBuilder.of(
|
||||||
id = id,
|
id = id,
|
||||||
userId = post.userId,
|
actorId = post.userId,
|
||||||
overview = post.overview,
|
overview = post.overview,
|
||||||
text = post.text,
|
text = post.text,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
interface ReactionService {
|
interface ReactionService {
|
||||||
suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long)
|
suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long)
|
||||||
suspend fun sendReaction(name: String, userId: Long, postId: Long)
|
suspend fun sendReaction(name: String, actorId: Long, postId: Long)
|
||||||
suspend fun removeReaction(userId: Long, postId: Long)
|
suspend fun removeReaction(actorId: Long, postId: Long)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,34 +16,34 @@ class ReactionServiceImpl(
|
||||||
private val apReactionService: APReactionService,
|
private val apReactionService: APReactionService,
|
||||||
private val reactionQueryService: ReactionQueryService
|
private val reactionQueryService: ReactionQueryService
|
||||||
) : ReactionService {
|
) : ReactionService {
|
||||||
override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) {
|
override suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long) {
|
||||||
if (reactionQueryService.reactionAlreadyExist(postId, userId, 0).not()) {
|
if (reactionQueryService.reactionAlreadyExist(postId, actorId, 0).not()) {
|
||||||
try {
|
try {
|
||||||
reactionRepository.save(
|
reactionRepository.save(
|
||||||
Reaction(reactionRepository.generateId(), 0, postId, userId)
|
Reaction(reactionRepository.generateId(), 0, postId, actorId)
|
||||||
)
|
)
|
||||||
} catch (_: ExposedSQLException) {
|
} catch (_: ExposedSQLException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendReaction(name: String, userId: Long, postId: Long) {
|
override suspend fun sendReaction(name: String, actorId: Long, postId: Long) {
|
||||||
try {
|
try {
|
||||||
val findByPostIdAndUserIdAndEmojiId =
|
val findByPostIdAndUserIdAndEmojiId =
|
||||||
reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0)
|
reactionQueryService.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
|
||||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||||
} catch (_: FailedToGetResourcesException) {
|
} catch (_: FailedToGetResourcesException) {
|
||||||
}
|
}
|
||||||
val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId)
|
val reaction = Reaction(reactionRepository.generateId(), 0, postId, actorId)
|
||||||
reactionRepository.save(reaction)
|
reactionRepository.save(reaction)
|
||||||
apReactionService.reaction(reaction)
|
apReactionService.reaction(reaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun removeReaction(userId: Long, postId: Long) {
|
override suspend fun removeReaction(actorId: Long, postId: Long) {
|
||||||
try {
|
try {
|
||||||
val findByPostIdAndUserIdAndEmojiId =
|
val findByPostIdAndUserIdAndEmojiId =
|
||||||
reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0)
|
reactionQueryService.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
|
||||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||||
} catch (_: FailedToGetResourcesException) {
|
} catch (_: FailedToGetResourcesException) {
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
package dev.usbharu.hideout.core.service.relationship
|
package dev.usbharu.hideout.core.service.relationship
|
||||||
|
|
||||||
interface RelationshipService {
|
interface RelationshipService {
|
||||||
suspend fun followRequest(userId: Long, targetId: Long)
|
suspend fun followRequest(actorId: Long, targetId: Long)
|
||||||
suspend fun block(userId: Long, targetId: Long)
|
suspend fun block(actorId: Long, targetId: Long)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* フォローリクエストを承認します
|
* フォローリクエストを承認します
|
||||||
* [userId]が[targetId]からのフォローリクエストを承認します
|
* [actorId]が[targetId]からのフォローリクエストを承認します
|
||||||
*
|
*
|
||||||
* @param userId 承認操作をするユーザー
|
* @param actorId 承認操作をするユーザー
|
||||||
* @param targetId 承認するフォローリクエストを送ってきたユーザー
|
* @param targetId 承認するフォローリクエストを送ってきたユーザー
|
||||||
* @param force 強制的にAcceptアクティビティを発行する
|
* @param force 強制的にAcceptアクティビティを発行する
|
||||||
*/
|
*/
|
||||||
suspend fun acceptFollowRequest(userId: Long, targetId: Long, force: Boolean = false)
|
suspend fun acceptFollowRequest(actorId: Long, targetId: Long, force: Boolean = false)
|
||||||
suspend fun rejectFollowRequest(userId: Long, targetId: Long)
|
suspend fun rejectFollowRequest(actorId: Long, targetId: Long)
|
||||||
suspend fun ignoreFollowRequest(userId: Long, targetId: Long)
|
suspend fun ignoreFollowRequest(actorId: Long, targetId: Long)
|
||||||
suspend fun unfollow(userId: Long, targetId: Long)
|
suspend fun unfollow(actorId: Long, targetId: Long)
|
||||||
suspend fun unblock(userId: Long, targetId: Long)
|
suspend fun unblock(actorId: Long, targetId: Long)
|
||||||
suspend fun mute(userId: Long, targetId: Long)
|
suspend fun mute(actorId: Long, targetId: Long)
|
||||||
suspend fun unmute(userId: Long, targetId: Long)
|
suspend fun unmute(actorId: Long, targetId: Long)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectServi
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService
|
import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.follow.SendFollowDto
|
import dev.usbharu.hideout.core.service.follow.SendFollowDto
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
@ -18,7 +18,7 @@ import org.springframework.stereotype.Service
|
||||||
@Service
|
@Service
|
||||||
class RelationshipServiceImpl(
|
class RelationshipServiceImpl(
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val relationshipRepository: RelationshipRepository,
|
private val relationshipRepository: RelationshipRepository,
|
||||||
private val apSendFollowService: APSendFollowService,
|
private val apSendFollowService: APSendFollowService,
|
||||||
private val apSendBlockService: APSendBlockService,
|
private val apSendBlockService: APSendBlockService,
|
||||||
|
@ -26,14 +26,14 @@ class RelationshipServiceImpl(
|
||||||
private val apSendRejectService: ApSendRejectService,
|
private val apSendRejectService: ApSendRejectService,
|
||||||
private val apSendUndoService: APSendUndoService
|
private val apSendUndoService: APSendUndoService
|
||||||
) : RelationshipService {
|
) : RelationshipService {
|
||||||
override suspend fun followRequest(userId: Long, targetId: Long) {
|
override suspend fun followRequest(actorId: Long, targetId: Long) {
|
||||||
logger.info("START Follow Request userId: {} targetId: {}", userId, targetId)
|
logger.info("START Follow Request userId: {} targetId: {}", actorId, targetId)
|
||||||
|
|
||||||
val relationship =
|
val relationship =
|
||||||
relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)?.copy(followRequest = true)
|
relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)?.copy(followRequest = true)
|
||||||
?: Relationship(
|
?: Relationship(
|
||||||
userId = userId,
|
actorId = actorId,
|
||||||
targetUserId = targetId,
|
targetActorId = targetId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -41,9 +41,9 @@ class RelationshipServiceImpl(
|
||||||
ignoreFollowRequestFromTarget = false
|
ignoreFollowRequestFromTarget = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userId) ?: Relationship(
|
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, actorId) ?: Relationship(
|
||||||
userId = targetId,
|
actorId = targetId,
|
||||||
targetUserId = userId,
|
targetActorId = actorId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -52,22 +52,22 @@ class RelationshipServiceImpl(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (inverseRelationship.blocking) {
|
if (inverseRelationship.blocking) {
|
||||||
logger.debug("FAILED Blocked by target. userId: {} targetId: {}", userId, targetId)
|
logger.debug("FAILED Blocked by target. userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.blocking) {
|
if (relationship.blocking) {
|
||||||
logger.debug("FAILED Blocking user. userId: {} targetId: {}", userId, targetId)
|
logger.debug("FAILED Blocking user. userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (inverseRelationship.ignoreFollowRequestFromTarget) {
|
if (inverseRelationship.ignoreFollowRequestFromTarget) {
|
||||||
logger.debug("SUCCESS Ignore Follow Request. userId: {} targetId: {}", userId, targetId)
|
logger.debug("SUCCESS Ignore Follow Request. userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.following) {
|
if (relationship.following) {
|
||||||
logger.debug("SUCCESS User already follow. userId: {} targetId: {}", userId, targetId)
|
logger.debug("SUCCESS User already follow. userId: {} targetId: {}", actorId, targetId)
|
||||||
acceptFollowRequest(targetId, userId, true)
|
acceptFollowRequest(targetId, actorId, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,21 +76,21 @@ class RelationshipServiceImpl(
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendFollowService.sendFollow(SendFollowDto(user, remoteUser))
|
apSendFollowService.sendFollow(SendFollowDto(user, remoteUser))
|
||||||
} else {
|
} else {
|
||||||
// TODO: フォロー許可制ユーザーを実装したら消す
|
// TODO: フォロー許可制ユーザーを実装したら消す
|
||||||
acceptFollowRequest(targetId, userId)
|
acceptFollowRequest(targetId, actorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("SUCCESS Follow Request userId: {} targetId: {}", userId, targetId)
|
logger.info("SUCCESS Follow Request userId: {} targetId: {}", actorId, targetId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun block(userId: Long, targetId: Long) {
|
override suspend fun block(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)
|
||||||
?.copy(blocking = true, followRequest = false, following = false) ?: Relationship(
|
?.copy(blocking = true, followRequest = false, following = false) ?: Relationship(
|
||||||
userId = userId,
|
actorId = actorId,
|
||||||
targetUserId = targetId,
|
targetActorId = targetId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -98,7 +98,7 @@ class RelationshipServiceImpl(
|
||||||
ignoreFollowRequestFromTarget = false
|
ignoreFollowRequestFromTarget = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userId)
|
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, actorId)
|
||||||
?.copy(followRequest = false, following = false)
|
?.copy(followRequest = false, following = false)
|
||||||
|
|
||||||
relationshipRepository.save(relationship)
|
relationshipRepository.save(relationship)
|
||||||
|
@ -109,19 +109,19 @@ class RelationshipServiceImpl(
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendBlockService.sendBlock(user, remoteUser)
|
apSendBlockService.sendBlock(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun acceptFollowRequest(userId: Long, targetId: Long, force: Boolean) {
|
override suspend fun acceptFollowRequest(actorId: Long, targetId: Long, force: Boolean) {
|
||||||
logger.info("START Accept follow request userId: {} targetId: {}", userId, targetId)
|
logger.info("START Accept follow request userId: {} targetId: {}", actorId, targetId)
|
||||||
|
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, actorId)
|
||||||
|
|
||||||
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId) ?: Relationship(
|
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId) ?: Relationship(
|
||||||
userId = targetId,
|
actorId = targetId,
|
||||||
targetUserId = userId,
|
targetActorId = actorId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -130,26 +130,26 @@ class RelationshipServiceImpl(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (relationship == null) {
|
if (relationship == null) {
|
||||||
logger.warn("FAILED Follow Request Not Found. (Relationship) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Follow Request Not Found. (Relationship) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.followRequest.not() && force.not()) {
|
if (relationship.followRequest.not() && force.not()) {
|
||||||
logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.blocking) {
|
if (relationship.blocking) {
|
||||||
logger.warn("FAILED Blocking user userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Blocking user userId: {} targetId: {}", actorId, targetId)
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(
|
||||||
"Cannot accept a follow request from a blocked user. userId: $userId targetId: $targetId"
|
"Cannot accept a follow request from a blocked user. userId: $actorId targetId: $targetId"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inverseRelationship.blocking) {
|
if (inverseRelationship.blocking) {
|
||||||
logger.warn("FAILED BLocked by user userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED BLocked by user userId: {} targetId: {}", actorId, targetId)
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(
|
||||||
"Cannot accept a follow request from a blocking user. userId: $userId targetId: $targetId"
|
"Cannot accept a follow request from a blocking user. userId: $actorId targetId: $targetId"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,21 +160,21 @@ class RelationshipServiceImpl(
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendAcceptService.sendAcceptFollow(user, remoteUser)
|
apSendAcceptService.sendAcceptFollow(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun rejectFollowRequest(userId: Long, targetId: Long) {
|
override suspend fun rejectFollowRequest(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, actorId)
|
||||||
|
|
||||||
if (relationship == null) {
|
if (relationship == null) {
|
||||||
logger.warn("FAILED Follow Request Not Found. (Relationship) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Follow Request Not Found. (Relationship) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.followRequest.not() && relationship.following.not()) {
|
if (relationship.followRequest.not() && relationship.following.not()) {
|
||||||
logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,17 +185,17 @@ class RelationshipServiceImpl(
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendRejectService.sendRejectFollow(user, remoteUser)
|
apSendRejectService.sendRejectFollow(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun ignoreFollowRequest(userId: Long, targetId: Long) {
|
override suspend fun ignoreFollowRequest(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)
|
||||||
?.copy(ignoreFollowRequestFromTarget = true)
|
?.copy(ignoreFollowRequestFromTarget = true)
|
||||||
?: Relationship(
|
?: Relationship(
|
||||||
userId = userId,
|
actorId = actorId,
|
||||||
targetUserId = targetId,
|
targetActorId = targetId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -206,16 +206,16 @@ class RelationshipServiceImpl(
|
||||||
relationshipRepository.save(relationship)
|
relationshipRepository.save(relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unfollow(userId: Long, targetId: Long) {
|
override suspend fun unfollow(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)
|
||||||
|
|
||||||
if (relationship == null) {
|
if (relationship == null) {
|
||||||
logger.warn("FAILED Unfollow. (Relationship) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Unfollow. (Relationship) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.following.not()) {
|
if (relationship.following.not()) {
|
||||||
logger.warn("SUCCESS User already unfollow. userId: {} targetId: {}", userId, targetId)
|
logger.warn("SUCCESS User already unfollow. userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,21 +226,21 @@ class RelationshipServiceImpl(
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendUndoService.sendUndoFollow(user, remoteUser)
|
apSendUndoService.sendUndoFollow(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unblock(userId: Long, targetId: Long) {
|
override suspend fun unblock(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)
|
||||||
|
|
||||||
if (relationship == null) {
|
if (relationship == null) {
|
||||||
logger.warn("FAILED Unblock. (Relationship) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Unblock. (Relationship) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship.blocking.not()) {
|
if (relationship.blocking.not()) {
|
||||||
logger.warn("SUCCESS User is not blocking. userId: {] targetId: {}", userId, targetId)
|
logger.warn("SUCCESS User is not blocking. userId: {] targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,16 +249,16 @@ class RelationshipServiceImpl(
|
||||||
|
|
||||||
val remoteUser = isRemoteUser(targetId)
|
val remoteUser = isRemoteUser(targetId)
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = actorQueryService.findById(actorId)
|
||||||
apSendUndoService.sendUndoBlock(user, remoteUser)
|
apSendUndoService.sendUndoBlock(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun mute(userId: Long, targetId: Long) {
|
override suspend fun mute(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)?.copy(muting = true)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)?.copy(muting = true)
|
||||||
?: Relationship(
|
?: Relationship(
|
||||||
userId = userId,
|
actorId = actorId,
|
||||||
targetUserId = targetId,
|
targetActorId = targetId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = true,
|
muting = true,
|
||||||
|
@ -269,21 +269,21 @@ class RelationshipServiceImpl(
|
||||||
relationshipRepository.save(relationship)
|
relationshipRepository.save(relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unmute(userId: Long, targetId: Long) {
|
override suspend fun unmute(actorId: Long, targetId: Long) {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId)?.copy(muting = false)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(actorId, targetId)?.copy(muting = false)
|
||||||
|
|
||||||
if (relationship == null) {
|
if (relationship == null) {
|
||||||
logger.warn("FAILED Mute. (Relationship) userId: {} targetId: {}", userId, targetId)
|
logger.warn("FAILED Mute. (Relationship) userId: {} targetId: {}", actorId, targetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
relationshipRepository.save(relationship)
|
relationshipRepository.save(relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun isRemoteUser(userId: Long): User? {
|
private suspend fun isRemoteUser(userId: Long): Actor? {
|
||||||
logger.trace("isRemoteUser({})", userId)
|
logger.trace("isRemoteUser({})", userId)
|
||||||
val user = try {
|
val user = try {
|
||||||
userQueryService.findById(userId)
|
actorQueryService.findById(userId)
|
||||||
} catch (e: FailedToGetResourcesException) {
|
} catch (e: FailedToGetResourcesException) {
|
||||||
logger.warn("User not found.", e)
|
logger.warn("User not found.", e)
|
||||||
throw IllegalStateException("User not found.", e)
|
throw IllegalStateException("User not found.", e)
|
||||||
|
|
|
@ -4,22 +4,22 @@ import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||||
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
|
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
|
||||||
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class TimelineService(
|
class TimelineService(
|
||||||
private val followerQueryService: FollowerQueryService,
|
private val followerQueryService: FollowerQueryService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val timelineRepository: TimelineRepository
|
private val timelineRepository: TimelineRepository
|
||||||
) {
|
) {
|
||||||
suspend fun publishTimeline(post: Post, isLocal: Boolean) {
|
suspend fun publishTimeline(post: Post, isLocal: Boolean) {
|
||||||
val findFollowersById = followerQueryService.findFollowersById(post.userId).toMutableList()
|
val findFollowersById = followerQueryService.findFollowersById(post.actorId).toMutableList()
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
// 自分自身も含める必要がある
|
// 自分自身も含める必要がある
|
||||||
val user = userQueryService.findById(post.userId)
|
val user = actorQueryService.findById(post.actorId)
|
||||||
findFollowersById.add(user)
|
findFollowersById.add(user)
|
||||||
}
|
}
|
||||||
val timelines = findFollowersById.map {
|
val timelines = findFollowersById.map {
|
||||||
|
@ -28,7 +28,7 @@ class TimelineService(
|
||||||
userId = it.id,
|
userId = it.id,
|
||||||
timelineId = 0,
|
timelineId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
postUserId = post.userId,
|
postActorId = post.actorId,
|
||||||
createdAt = post.createdAt,
|
createdAt = post.createdAt,
|
||||||
replyId = post.replyId,
|
replyId = post.replyId,
|
||||||
repostId = post.repostId,
|
repostId = post.repostId,
|
||||||
|
@ -46,7 +46,7 @@ class TimelineService(
|
||||||
userId = 0,
|
userId = 0,
|
||||||
timelineId = 0,
|
timelineId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
postUserId = post.userId,
|
postActorId = post.actorId,
|
||||||
createdAt = post.createdAt,
|
createdAt = post.createdAt,
|
||||||
replyId = post.replyId,
|
replyId = post.replyId,
|
||||||
repostId = post.repostId,
|
repostId = post.repostId,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.service.user
|
package dev.usbharu.hideout.core.service.user
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.security.*
|
import java.security.*
|
||||||
|
@ -8,13 +8,13 @@ import java.util.*
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class UserAuthServiceImpl(
|
class UserAuthServiceImpl(
|
||||||
val userQueryService: UserQueryService
|
val actorQueryService: ActorQueryService
|
||||||
) : UserAuthService {
|
) : UserAuthService {
|
||||||
|
|
||||||
override fun hash(password: String): String = BCryptPasswordEncoder().encode(password)
|
override fun hash(password: String): String = BCryptPasswordEncoder().encode(password)
|
||||||
|
|
||||||
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
||||||
userQueryService.findByName(username)
|
actorQueryService.findByName(username)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.service.user
|
package dev.usbharu.hideout.core.service.user
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -8,7 +8,7 @@ interface UserService {
|
||||||
|
|
||||||
suspend fun usernameAlreadyUse(username: String): Boolean
|
suspend fun usernameAlreadyUse(username: String): Boolean
|
||||||
|
|
||||||
suspend fun createLocalUser(user: UserCreateDto): User
|
suspend fun createLocalUser(user: UserCreateDto): Actor
|
||||||
|
|
||||||
suspend fun createRemoteUser(user: RemoteUserCreateDto): User
|
suspend fun createRemoteUser(user: RemoteUserCreateDto): Actor
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package dev.usbharu.hideout.core.service.user
|
package dev.usbharu.hideout.core.service.user
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.instance.InstanceService
|
import dev.usbharu.hideout.core.service.instance.InstanceService
|
||||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
@ -13,26 +13,26 @@ import java.time.Instant
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class UserServiceImpl(
|
class UserServiceImpl(
|
||||||
private val userRepository: UserRepository,
|
private val actorRepository: ActorRepository,
|
||||||
private val userAuthService: UserAuthService,
|
private val userAuthService: UserAuthService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val userBuilder: User.UserBuilder,
|
private val actorBuilder: Actor.UserBuilder,
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val instanceService: InstanceService
|
private val instanceService: InstanceService
|
||||||
) :
|
) :
|
||||||
UserService {
|
UserService {
|
||||||
|
|
||||||
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
||||||
val findByNameAndDomain = userQueryService.findByNameAndDomain(username, applicationConfig.url.host)
|
val findByNameAndDomain = actorQueryService.findByNameAndDomain(username, applicationConfig.url.host)
|
||||||
return findByNameAndDomain != null
|
return findByNameAndDomain != null
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createLocalUser(user: UserCreateDto): User {
|
override suspend fun createLocalUser(user: UserCreateDto): Actor {
|
||||||
val nextId = userRepository.nextId()
|
val nextId = actorRepository.nextId()
|
||||||
val hashedPassword = userAuthService.hash(user.password)
|
val hashedPassword = userAuthService.hash(user.password)
|
||||||
val keyPair = userAuthService.generateKeyPair()
|
val keyPair = userAuthService.generateKeyPair()
|
||||||
val userUrl = "${applicationConfig.url}/users/${user.name}"
|
val userUrl = "${applicationConfig.url}/users/${user.name}"
|
||||||
val userEntity = userBuilder.of(
|
val userEntity = actorBuilder.of(
|
||||||
id = nextId,
|
id = nextId,
|
||||||
name = user.name,
|
name = user.name,
|
||||||
domain = applicationConfig.url.host,
|
domain = applicationConfig.url.host,
|
||||||
|
@ -49,11 +49,11 @@ class UserServiceImpl(
|
||||||
followers = "$userUrl/followers",
|
followers = "$userUrl/followers",
|
||||||
keyId = "$userUrl#pubkey"
|
keyId = "$userUrl#pubkey"
|
||||||
)
|
)
|
||||||
return userRepository.save(userEntity)
|
return actorRepository.save(userEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
override suspend fun createRemoteUser(user: RemoteUserCreateDto): User {
|
override suspend fun createRemoteUser(user: RemoteUserCreateDto): Actor {
|
||||||
logger.info("START Create New remote user. name: {} url: {}", user.name, user.url)
|
logger.info("START Create New remote user. name: {} url: {}", user.name, user.url)
|
||||||
@Suppress("TooGenericExceptionCaught")
|
@Suppress("TooGenericExceptionCaught")
|
||||||
val instance = try {
|
val instance = try {
|
||||||
|
@ -63,8 +63,8 @@ class UserServiceImpl(
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
val nextId = userRepository.nextId()
|
val nextId = actorRepository.nextId()
|
||||||
val userEntity = userBuilder.of(
|
val userEntity = actorBuilder.of(
|
||||||
id = nextId,
|
id = nextId,
|
||||||
name = user.name,
|
name = user.name,
|
||||||
domain = user.domain,
|
domain = user.domain,
|
||||||
|
@ -81,12 +81,12 @@ class UserServiceImpl(
|
||||||
instance = instance?.id
|
instance = instance?.id
|
||||||
)
|
)
|
||||||
return try {
|
return try {
|
||||||
val save = userRepository.save(userEntity)
|
val save = actorRepository.save(userEntity)
|
||||||
logger.warn("SUCCESS Create New remote user. id: {} name: {} url: {}", userEntity.id, user.name, user.url)
|
logger.warn("SUCCESS Create New remote user. id: {} name: {} url: {}", userEntity.id, user.name, user.url)
|
||||||
save
|
save
|
||||||
} catch (_: ExposedSQLException) {
|
} catch (_: ExposedSQLException) {
|
||||||
logger.warn("FAILED User already exists. name: {} url: {}", user.name, user.url)
|
logger.warn("FAILED User already exists. name: {} url: {}", user.name, user.url)
|
||||||
userQueryService.findByUrl(user.url)
|
actorQueryService.findByUrl(user.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class StatusQueryServiceImpl : StatusQueryService {
|
||||||
val mediaIdSet = mutableSetOf<Long>()
|
val mediaIdSet = mutableSetOf<Long>()
|
||||||
mediaIdSet.addAll(statusQueries.flatMap { it.mediaIds })
|
mediaIdSet.addAll(statusQueries.flatMap { it.mediaIds })
|
||||||
val postMap = Posts
|
val postMap = Posts
|
||||||
.leftJoin(Users)
|
.leftJoin(Actors)
|
||||||
.select { Posts.id inList postIdSet }
|
.select { Posts.id inList postIdSet }
|
||||||
.associate { it[Posts.id] to toStatus(it) }
|
.associate { it[Posts.id] to toStatus(it) }
|
||||||
val mediaMap = Media.select { Media.id inList mediaIdSet }
|
val mediaMap = Media.select { Media.id inList mediaIdSet }
|
||||||
|
@ -57,9 +57,9 @@ class StatusQueryServiceImpl : StatusQueryService {
|
||||||
): List<Status> {
|
): List<Status> {
|
||||||
val query = Posts
|
val query = Posts
|
||||||
.leftJoin(PostsMedia)
|
.leftJoin(PostsMedia)
|
||||||
.leftJoin(Users)
|
.leftJoin(Actors)
|
||||||
.leftJoin(Media)
|
.leftJoin(Media)
|
||||||
.select { Posts.userId eq accountId }.limit(20)
|
.select { Posts.actorId eq accountId }.limit(20)
|
||||||
|
|
||||||
if (maxId != null) {
|
if (maxId != null) {
|
||||||
query.andWhere { Posts.id eq maxId }
|
query.andWhere { Posts.id eq maxId }
|
||||||
|
@ -120,7 +120,7 @@ class StatusQueryServiceImpl : StatusQueryService {
|
||||||
private suspend fun findByPostIdsWithMedia(ids: List<Long>): List<Status> {
|
private suspend fun findByPostIdsWithMedia(ids: List<Long>): List<Status> {
|
||||||
val pairs = Posts
|
val pairs = Posts
|
||||||
.leftJoin(PostsMedia)
|
.leftJoin(PostsMedia)
|
||||||
.leftJoin(Users)
|
.leftJoin(Actors)
|
||||||
.leftJoin(Media)
|
.leftJoin(Media)
|
||||||
.select { Posts.id inList ids }
|
.select { Posts.id inList ids }
|
||||||
.groupBy { it[Posts.id] }
|
.groupBy { it[Posts.id] }
|
||||||
|
@ -141,24 +141,24 @@ private fun toStatus(it: ResultRow) = Status(
|
||||||
uri = it[Posts.apId],
|
uri = it[Posts.apId],
|
||||||
createdAt = Instant.ofEpochMilli(it[Posts.createdAt]).toString(),
|
createdAt = Instant.ofEpochMilli(it[Posts.createdAt]).toString(),
|
||||||
account = Account(
|
account = Account(
|
||||||
id = it[Users.id].toString(),
|
id = it[Actors.id].toString(),
|
||||||
username = it[Users.name],
|
username = it[Actors.name],
|
||||||
acct = "${it[Users.name]}@${it[Users.domain]}",
|
acct = "${it[Actors.name]}@${it[Actors.domain]}",
|
||||||
url = it[Users.url],
|
url = it[Actors.url],
|
||||||
displayName = it[Users.screenName],
|
displayName = it[Actors.screenName],
|
||||||
note = it[Users.description],
|
note = it[Actors.description],
|
||||||
avatar = it[Users.url] + "/icon.jpg",
|
avatar = it[Actors.url] + "/icon.jpg",
|
||||||
avatarStatic = it[Users.url] + "/icon.jpg",
|
avatarStatic = it[Actors.url] + "/icon.jpg",
|
||||||
header = it[Users.url] + "/header.jpg",
|
header = it[Actors.url] + "/header.jpg",
|
||||||
headerStatic = it[Users.url] + "/header.jpg",
|
headerStatic = it[Actors.url] + "/header.jpg",
|
||||||
locked = false,
|
locked = false,
|
||||||
fields = emptyList(),
|
fields = emptyList(),
|
||||||
emojis = emptyList(),
|
emojis = emptyList(),
|
||||||
bot = false,
|
bot = false,
|
||||||
group = false,
|
group = false,
|
||||||
discoverable = true,
|
discoverable = true,
|
||||||
createdAt = Instant.ofEpochMilli(it[Users.createdAt]).toString(),
|
createdAt = Instant.ofEpochMilli(it[Actors.createdAt]).toString(),
|
||||||
lastStatusAt = Instant.ofEpochMilli(it[Users.createdAt]).toString(),
|
lastStatusAt = Instant.ofEpochMilli(it[Actors.createdAt]).toString(),
|
||||||
statusesCount = 0,
|
statusesCount = 0,
|
||||||
followersCount = 0,
|
followersCount = 0,
|
||||||
followingCount = 0,
|
followingCount = 0,
|
||||||
|
|
|
@ -194,8 +194,8 @@ class AccountApiServiceImpl(
|
||||||
private suspend fun fetchRelationship(userid: Long, targetId: Long): Relationship {
|
private suspend fun fetchRelationship(userid: Long, targetId: Long): Relationship {
|
||||||
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userid, targetId)
|
val relationship = relationshipRepository.findByUserIdAndTargetUserId(userid, targetId)
|
||||||
?: dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
?: dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
||||||
userId = userid,
|
actorId = userid,
|
||||||
targetUserId = targetId,
|
targetActorId = targetId,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -205,8 +205,8 @@ class AccountApiServiceImpl(
|
||||||
|
|
||||||
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userid)
|
val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userid)
|
||||||
?: dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
?: dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
||||||
userId = targetId,
|
actorId = targetId,
|
||||||
targetUserId = userid,
|
targetActorId = userid,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package dev.usbharu.hideout.mastodon.service.account
|
package dev.usbharu.hideout.mastodon.service.account
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Account
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Account
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ interface AccountService {
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class AccountServiceImpl(
|
class AccountServiceImpl(
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val applicationConfig: ApplicationConfig
|
private val applicationConfig: ApplicationConfig
|
||||||
) : AccountService {
|
) : AccountService {
|
||||||
override suspend fun findById(id: Long): Account {
|
override suspend fun findById(id: Long): Account {
|
||||||
val findById = userQueryService.findById(id)
|
val findById = actorQueryService.findById(id)
|
||||||
val userUrl = applicationConfig.url.toString() + "/users/" + findById.id.toString()
|
val userUrl = applicationConfig.url.toString() + "/users/" + findById.id.toString()
|
||||||
|
|
||||||
return Account(
|
return Account(
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.model.media.MediaRepository
|
import dev.usbharu.hideout.core.domain.model.media.MediaRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.media.toMediaAttachments
|
import dev.usbharu.hideout.core.domain.model.media.toMediaAttachments
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.post.PostCreateDto
|
import dev.usbharu.hideout.core.service.post.PostCreateDto
|
||||||
import dev.usbharu.hideout.core.service.post.PostService
|
import dev.usbharu.hideout.core.service.post.PostService
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||||
|
@ -30,7 +30,7 @@ class StatsesApiServiceImpl(
|
||||||
private val postService: PostService,
|
private val postService: PostService,
|
||||||
private val accountService: AccountService,
|
private val accountService: AccountService,
|
||||||
private val postQueryService: PostQueryService,
|
private val postQueryService: PostQueryService,
|
||||||
private val userQueryService: UserQueryService,
|
private val actorQueryService: ActorQueryService,
|
||||||
private val mediaRepository: MediaRepository,
|
private val mediaRepository: MediaRepository,
|
||||||
private val transaction: Transaction
|
private val transaction: Transaction
|
||||||
) :
|
) :
|
||||||
|
@ -55,7 +55,7 @@ class StatsesApiServiceImpl(
|
||||||
|
|
||||||
val replyUser = if (post.replyId != null) {
|
val replyUser = if (post.replyId != null) {
|
||||||
try {
|
try {
|
||||||
userQueryService.findById(postQueryService.findById(post.replyId).userId).id
|
actorQueryService.findById(postQueryService.findById(post.replyId).actorId).id
|
||||||
} catch (ignore: FailedToGetResourcesException) {
|
} catch (ignore: FailedToGetResourcesException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.util
|
package dev.usbharu.hideout.util
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.Acct
|
import dev.usbharu.hideout.core.domain.model.actor.Acct
|
||||||
|
|
||||||
object AcctUtil {
|
object AcctUtil {
|
||||||
fun parse(string: String): Acct {
|
fun parse(string: String): Acct {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.post
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
class UserAPControllerImplTest {
|
class ActorAPControllerImplTest {
|
||||||
|
|
||||||
private lateinit var mockMvc: MockMvc
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
|
@ -5,7 +5,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -25,7 +25,7 @@ class APDeliverAcceptJobProcessorTest {
|
||||||
private lateinit var apRequestService: APRequestService
|
private lateinit var apRequestService: APRequestService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var deliverAcceptJob: DeliverAcceptJob
|
private lateinit var deliverAcceptJob: DeliverAcceptJob
|
||||||
|
@ -40,7 +40,7 @@ class APDeliverAcceptJobProcessorTest {
|
||||||
fun `process apPostが発行される`() = runTest {
|
fun `process apPostが発行される`() = runTest {
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
|
|
||||||
whenever(userQueryService.findById(eq(1))).doReturn(user)
|
whenever(actorQueryService.findById(eq(1))).doReturn(user)
|
||||||
|
|
||||||
val accept = Accept(
|
val accept = Accept(
|
||||||
apObject = Follow(
|
apObject = Follow(
|
||||||
|
|
|
@ -7,7 +7,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
|
@ -34,7 +34,7 @@ import java.net.URL
|
||||||
class ApAcceptProcessorTest {
|
class ApAcceptProcessorTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var relationshipService: RelationshipService
|
private lateinit var relationshipService: RelationshipService
|
||||||
|
@ -67,9 +67,9 @@ class ApAcceptProcessorTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
whenever(userQueryService.findByUrl(eq("https://example.com"))).doReturn(user)
|
whenever(actorQueryService.findByUrl(eq("https://example.com"))).doReturn(user)
|
||||||
val remoteUser = UserBuilder.remoteUserOf()
|
val remoteUser = UserBuilder.remoteUserOf()
|
||||||
whenever(userQueryService.findByUrl(eq("https://remote.example.com"))).doReturn(remoteUser)
|
whenever(actorQueryService.findByUrl(eq("https://remote.example.com"))).doReturn(remoteUser)
|
||||||
|
|
||||||
apAcceptProcessor.internalProcess(activity)
|
apAcceptProcessor.internalProcess(activity)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
@ -26,7 +26,7 @@ class APDeliverBlockJobProcessorTest {
|
||||||
private lateinit var apRequestService: APRequestService
|
private lateinit var apRequestService: APRequestService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userRepository: UserRepository
|
private lateinit var actorRepository: ActorRepository
|
||||||
|
|
||||||
@Spy
|
@Spy
|
||||||
private val transaction = TestTransaction
|
private val transaction = TestTransaction
|
||||||
|
@ -40,7 +40,7 @@ class APDeliverBlockJobProcessorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `process rejectとblockがapPostされる`() = runTest {
|
fun `process rejectとblockがapPostされる`() = runTest {
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
whenever(userRepository.findById(eq(user.id))).doReturn(user)
|
whenever(actorRepository.findById(eq(user.id))).doReturn(user)
|
||||||
|
|
||||||
|
|
||||||
val block = Block(
|
val block = Block(
|
||||||
|
|
|
@ -7,8 +7,8 @@ import dev.usbharu.hideout.activitypub.service.objects.note.APNoteServiceImpl
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -36,7 +36,7 @@ class ApSendCreateServiceImplTest {
|
||||||
private lateinit var jobQueueParentService: JobQueueParentService
|
private lateinit var jobQueueParentService: JobQueueParentService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var noteQueryService: NoteQueryService
|
private lateinit var noteQueryService: NoteQueryService
|
||||||
|
@ -50,7 +50,7 @@ class ApSendCreateServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createNote 正常なPostでCreateのジョブを発行できる`() = runTest {
|
fun `createNote 正常なPostでCreateのジョブを発行できる`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
val user = UserBuilder.localUserOf(id = post.userId)
|
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||||
val note = Note(
|
val note = Note(
|
||||||
id = post.apId,
|
id = post.apId,
|
||||||
attributedTo = user.url,
|
attributedTo = user.url,
|
||||||
|
@ -67,8 +67,8 @@ class ApSendCreateServiceImplTest {
|
||||||
UserBuilder.remoteUserOf()
|
UserBuilder.remoteUserOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
whenever(followerQueryService.findFollowersById(eq(post.userId))).doReturn(followers)
|
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(followers)
|
||||||
whenever(userQueryService.findById(eq(post.userId))).doReturn(user)
|
whenever(actorQueryService.findById(eq(post.actorId))).doReturn(user)
|
||||||
whenever(noteQueryService.findById(eq(post.id))).doReturn(note to post)
|
whenever(noteQueryService.findById(eq(post.id))).doReturn(note to post)
|
||||||
|
|
||||||
apSendCreateServiceImpl.createNote(post)
|
apSendCreateServiceImpl.createNote(post)
|
||||||
|
|
|
@ -24,13 +24,13 @@ class APSendFollowServiceImplTest {
|
||||||
apSendFollowServiceImpl.sendFollow(sendFollowDto)
|
apSendFollowServiceImpl.sendFollow(sendFollowDto)
|
||||||
|
|
||||||
val value = Follow(
|
val value = Follow(
|
||||||
apObject = sendFollowDto.followTargetUserId.url,
|
apObject = sendFollowDto.followTargetActorId.url,
|
||||||
actor = sendFollowDto.userId.url
|
actor = sendFollowDto.actorId.url
|
||||||
)
|
)
|
||||||
verify(apRequestService, times(1)).apPost(
|
verify(apRequestService, times(1)).apPost(
|
||||||
eq(sendFollowDto.followTargetUserId.inbox),
|
eq(sendFollowDto.followTargetActorId.inbox),
|
||||||
eq(value),
|
eq(value),
|
||||||
eq(sendFollowDto.userId)
|
eq(sendFollowDto.actorId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class APReactionServiceImplTest {
|
||||||
val jobQueueParentService = mock<JobQueueParentService>()
|
val jobQueueParentService = mock<JobQueueParentService>()
|
||||||
val apReactionServiceImpl = APReactionServiceImpl(
|
val apReactionServiceImpl = APReactionServiceImpl(
|
||||||
jobQueueParentService = jobQueueParentService,
|
jobQueueParentService = jobQueueParentService,
|
||||||
userQueryService = mock(),
|
actorQueryService = mock(),
|
||||||
followerQueryService = followerQueryService,
|
followerQueryService = followerQueryService,
|
||||||
postQueryService = postQueryService,
|
postQueryService = postQueryService,
|
||||||
objectMapper = objectMapper
|
objectMapper = objectMapper
|
||||||
|
@ -46,7 +46,7 @@ class APReactionServiceImplTest {
|
||||||
id = TwitterSnowflakeIdGenerateService.generateId(),
|
id = TwitterSnowflakeIdGenerateService.generateId(),
|
||||||
emojiId = 0,
|
emojiId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
userId = user.id
|
actorId = user.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class APReactionServiceImplTest {
|
||||||
val jobQueueParentService = mock<JobQueueParentService>()
|
val jobQueueParentService = mock<JobQueueParentService>()
|
||||||
val apReactionServiceImpl = APReactionServiceImpl(
|
val apReactionServiceImpl = APReactionServiceImpl(
|
||||||
jobQueueParentService = jobQueueParentService,
|
jobQueueParentService = jobQueueParentService,
|
||||||
userQueryService = mock(),
|
actorQueryService = mock(),
|
||||||
followerQueryService = followerQueryService,
|
followerQueryService = followerQueryService,
|
||||||
postQueryService = postQueryService,
|
postQueryService = postQueryService,
|
||||||
objectMapper = objectMapper
|
objectMapper = objectMapper
|
||||||
|
@ -83,7 +83,7 @@ class APReactionServiceImplTest {
|
||||||
id = TwitterSnowflakeIdGenerateService.generateId(),
|
id = TwitterSnowflakeIdGenerateService.generateId(),
|
||||||
emojiId = 0,
|
emojiId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
userId = user.id
|
actorId = user.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.service.resource.InMemoryCacheManager
|
import dev.usbharu.hideout.core.service.resource.InMemoryCacheManager
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
|
@ -20,10 +20,10 @@ class APResourceResolveServiceImplTest {
|
||||||
fun `単純な一回のリクエスト`() = runTest {
|
fun `単純な一回のリクエスト`() = runTest {
|
||||||
|
|
||||||
|
|
||||||
val userRepository = mock<UserRepository>()
|
val actorRepository = mock<ActorRepository>()
|
||||||
|
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
whenever(userRepository.findById(any())) doReturn user
|
whenever(actorRepository.findById(any())) doReturn user
|
||||||
|
|
||||||
val apRequestService = mock<APRequestService> {
|
val apRequestService = mock<APRequestService> {
|
||||||
onBlocking {
|
onBlocking {
|
||||||
|
@ -37,7 +37,7 @@ class APResourceResolveServiceImplTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val apResourceResolveService =
|
val apResourceResolveService =
|
||||||
APResourceResolveServiceImpl(apRequestService, userRepository, InMemoryCacheManager())
|
APResourceResolveServiceImpl(apRequestService, actorRepository, InMemoryCacheManager())
|
||||||
|
|
||||||
apResourceResolveService.resolve<APObject>("https", 0)
|
apResourceResolveService.resolve<APObject>("https", 0)
|
||||||
|
|
||||||
|
@ -48,10 +48,10 @@ class APResourceResolveServiceImplTest {
|
||||||
fun 複数回の同じリクエストが重複して発行されない() = runTest {
|
fun 複数回の同じリクエストが重複して発行されない() = runTest {
|
||||||
|
|
||||||
|
|
||||||
val userRepository = mock<UserRepository>()
|
val actorRepository = mock<ActorRepository>()
|
||||||
|
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
whenever(userRepository.findById(any())) doReturn user
|
whenever(actorRepository.findById(any())) doReturn user
|
||||||
|
|
||||||
val apRequestService = mock<APRequestService> {
|
val apRequestService = mock<APRequestService> {
|
||||||
onBlocking {
|
onBlocking {
|
||||||
|
@ -65,7 +65,7 @@ class APResourceResolveServiceImplTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val apResourceResolveService =
|
val apResourceResolveService =
|
||||||
APResourceResolveServiceImpl(apRequestService, userRepository, InMemoryCacheManager())
|
APResourceResolveServiceImpl(apRequestService, actorRepository, InMemoryCacheManager())
|
||||||
|
|
||||||
apResourceResolveService.resolve<APObject>("https", 0)
|
apResourceResolveService.resolve<APObject>("https", 0)
|
||||||
apResourceResolveService.resolve<APObject>("https", 0)
|
apResourceResolveService.resolve<APObject>("https", 0)
|
||||||
|
@ -83,10 +83,10 @@ class APResourceResolveServiceImplTest {
|
||||||
fun 複数回の同じリクエストが同時に発行されても重複して発行されない() = runTest {
|
fun 複数回の同じリクエストが同時に発行されても重複して発行されない() = runTest {
|
||||||
|
|
||||||
|
|
||||||
val userRepository = mock<UserRepository>()
|
val actorRepository = mock<ActorRepository>()
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
|
|
||||||
whenever(userRepository.findById(any())) doReturn user
|
whenever(actorRepository.findById(any())) doReturn user
|
||||||
|
|
||||||
|
|
||||||
val apRequestService = mock<APRequestService> {
|
val apRequestService = mock<APRequestService> {
|
||||||
|
@ -101,7 +101,7 @@ class APResourceResolveServiceImplTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val apResourceResolveService =
|
val apResourceResolveService =
|
||||||
APResourceResolveServiceImpl(apRequestService, userRepository, InMemoryCacheManager())
|
APResourceResolveServiceImpl(apRequestService, actorRepository, InMemoryCacheManager())
|
||||||
|
|
||||||
repeat(10) {
|
repeat(10) {
|
||||||
awaitAll(
|
awaitAll(
|
||||||
|
@ -129,10 +129,10 @@ class APResourceResolveServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun 関係のないリクエストは発行する() = runTest {
|
fun 関係のないリクエストは発行する() = runTest {
|
||||||
|
|
||||||
val userRepository = mock<UserRepository>()
|
val actorRepository = mock<ActorRepository>()
|
||||||
|
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
whenever(userRepository.findById(any())).doReturn(
|
whenever(actorRepository.findById(any())).doReturn(
|
||||||
user
|
user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class APResourceResolveServiceImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
val apResourceResolveService =
|
val apResourceResolveService =
|
||||||
APResourceResolveServiceImpl(apRequestService, userRepository, InMemoryCacheManager())
|
APResourceResolveServiceImpl(apRequestService, actorRepository, InMemoryCacheManager())
|
||||||
|
|
||||||
apResourceResolveService.resolve<APObject>("abcd", 0)
|
apResourceResolveService.resolve<APObject>("abcd", 0)
|
||||||
apResourceResolveService.resolve<APObject>("1234", 0)
|
apResourceResolveService.resolve<APObject>("1234", 0)
|
||||||
|
|
|
@ -16,8 +16,8 @@ import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateServ
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import dev.usbharu.hideout.core.service.post.PostService
|
import dev.usbharu.hideout.core.service.post.PostService
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.*
|
||||||
|
@ -51,9 +51,9 @@ class APNoteServiceImplTest {
|
||||||
val url = "https://example.com/note"
|
val url = "https://example.com/note"
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
|
|
||||||
val user = UserBuilder.localUserOf(id = post.userId)
|
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||||
val userQueryService = mock<UserQueryService> {
|
val actorQueryService = mock<ActorQueryService> {
|
||||||
onBlocking { findById(eq(post.userId)) } doReturn user
|
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||||
}
|
}
|
||||||
val expected = Note(
|
val expected = Note(
|
||||||
id = post.apId,
|
id = post.apId,
|
||||||
|
@ -92,9 +92,9 @@ class APNoteServiceImplTest {
|
||||||
val postQueryService = mock<PostQueryService> {
|
val postQueryService = mock<PostQueryService> {
|
||||||
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
||||||
}
|
}
|
||||||
val user = UserBuilder.localUserOf(id = post.userId)
|
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||||
val userQueryService = mock<UserQueryService> {
|
val actorQueryService = mock<ActorQueryService> {
|
||||||
onBlocking { findById(eq(post.userId)) } doReturn user
|
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||||
}
|
}
|
||||||
val note = Note(
|
val note = Note(
|
||||||
id = post.apId,
|
id = post.apId,
|
||||||
|
@ -167,9 +167,9 @@ class APNoteServiceImplTest {
|
||||||
val postQueryService = mock<PostQueryService> {
|
val postQueryService = mock<PostQueryService> {
|
||||||
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
||||||
}
|
}
|
||||||
val user = UserBuilder.localUserOf(id = post.userId)
|
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||||
val userQueryService = mock<UserQueryService> {
|
val actorQueryService = mock<ActorQueryService> {
|
||||||
onBlocking { findById(eq(post.userId)) } doReturn user
|
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||||
}
|
}
|
||||||
val note = Note(
|
val note = Note(
|
||||||
id = post.apId,
|
id = post.apId,
|
||||||
|
@ -299,7 +299,7 @@ class APNoteServiceImplTest {
|
||||||
val user = UserBuilder.localUserOf()
|
val user = UserBuilder.localUserOf()
|
||||||
val post = PostBuilder.of(userId = user.id)
|
val post = PostBuilder.of(userId = user.id)
|
||||||
|
|
||||||
val userQueryService = mock<UserQueryService> {
|
val actorQueryService = mock<ActorQueryService> {
|
||||||
onBlocking { findById(eq(user.id)) } doReturn user
|
onBlocking { findById(eq(user.id)) } doReturn user
|
||||||
}
|
}
|
||||||
val note = Note(
|
val note = Note(
|
||||||
|
|
|
@ -2,9 +2,9 @@ package dev.usbharu.hideout.core.service.post
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
||||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
@ -31,7 +31,7 @@ class PostServiceImplTest {
|
||||||
private lateinit var postRepository: PostRepository
|
private lateinit var postRepository: PostRepository
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userRepository: UserRepository
|
private lateinit var actorRepository: ActorRepository
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var timelineService: TimelineService
|
private lateinit var timelineService: TimelineService
|
||||||
|
@ -56,7 +56,7 @@ class PostServiceImplTest {
|
||||||
|
|
||||||
whenever(postRepository.save(eq(post))).doReturn(true)
|
whenever(postRepository.save(eq(post))).doReturn(true)
|
||||||
whenever(postRepository.generateId()).doReturn(post.id)
|
whenever(postRepository.generateId()).doReturn(post.id)
|
||||||
whenever(userRepository.findById(eq(post.userId))).doReturn(UserBuilder.localUserOf(id = post.userId))
|
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.localUserOf(id = post.actorId))
|
||||||
whenever(timelineService.publishTimeline(eq(post), eq(true))).doReturn(Unit)
|
whenever(timelineService.publishTimeline(eq(post), eq(true))).doReturn(Unit)
|
||||||
|
|
||||||
mockStatic(Instant::class.java, Mockito.CALLS_REAL_METHODS).use {
|
mockStatic(Instant::class.java, Mockito.CALLS_REAL_METHODS).use {
|
||||||
|
@ -69,7 +69,7 @@ class PostServiceImplTest {
|
||||||
post.visibility,
|
post.visibility,
|
||||||
post.repostId,
|
post.repostId,
|
||||||
post.replyId,
|
post.replyId,
|
||||||
post.userId,
|
post.actorId,
|
||||||
post.mediaIds
|
post.mediaIds
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,20 +37,20 @@ class ReactionServiceImplTest {
|
||||||
|
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
|
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(false)
|
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(false)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
reactionServiceImpl.receiveReaction("❤", "example.com", post.userId, post.id)
|
reactionServiceImpl.receiveReaction("❤", "example.com", post.actorId, post.id)
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `receiveReaction リアクションが既に作成されていることを検知出来ずに例外が発生した場合は何もしない`() = runTest {
|
fun `receiveReaction リアクションが既に作成されていることを検知出来ずに例外が発生した場合は何もしない`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
|
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(false)
|
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(false)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(
|
whenever(
|
||||||
reactionRepository.save(
|
reactionRepository.save(
|
||||||
|
@ -59,7 +59,7 @@ class ReactionServiceImplTest {
|
||||||
id = generateId,
|
id = generateId,
|
||||||
emojiId = 0,
|
emojiId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
userId = post.userId
|
actorId = post.actorId
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -71,17 +71,17 @@ class ReactionServiceImplTest {
|
||||||
}
|
}
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
reactionServiceImpl.receiveReaction("❤", "example.com", post.userId, post.id)
|
reactionServiceImpl.receiveReaction("❤", "example.com", post.actorId, post.id)
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `receiveReaction リアクションが既に作成されている場合は何もしない`() = runTest() {
|
fun `receiveReaction リアクションが既に作成されている場合は何もしない`() = runTest() {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(true)
|
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(true)
|
||||||
|
|
||||||
reactionServiceImpl.receiveReaction("❤", "example.com", post.userId, post.id)
|
reactionServiceImpl.receiveReaction("❤", "example.com", post.actorId, post.id)
|
||||||
|
|
||||||
verify(reactionRepository, never()).save(any())
|
verify(reactionRepository, never()).save(any())
|
||||||
}
|
}
|
||||||
|
@ -89,47 +89,47 @@ class ReactionServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest {
|
fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doThrow(
|
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doThrow(
|
||||||
FailedToGetResourcesException::class
|
FailedToGetResourcesException::class
|
||||||
)
|
)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
reactionServiceImpl.sendReaction("❤", post.userId, post.id)
|
reactionServiceImpl.sendReaction("❤", post.actorId, post.id)
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest {
|
fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
val id = TwitterSnowflakeIdGenerateService.generateId()
|
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn(
|
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||||
Reaction(id, 0, post.id, post.userId)
|
Reaction(id, 0, post.id, post.actorId)
|
||||||
)
|
)
|
||||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||||
|
|
||||||
reactionServiceImpl.sendReaction("❤", post.userId, post.id)
|
reactionServiceImpl.sendReaction("❤", post.actorId, post.id)
|
||||||
|
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).delete(eq(Reaction(id, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).delete(eq(Reaction(id, 0, post.id, post.actorId)))
|
||||||
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
verify(apReactionService, times(1)).removeReaction(eq(Reaction(id, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).removeReaction(eq(Reaction(id, 0, post.id, post.actorId)))
|
||||||
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.actorId)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `removeReaction リアクションが存在する場合削除して配送`() = runTest {
|
fun `removeReaction リアクションが存在する場合削除して配送`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn(
|
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||||
Reaction(0, 0, post.id, post.userId)
|
Reaction(0, 0, post.id, post.actorId)
|
||||||
)
|
)
|
||||||
|
|
||||||
reactionServiceImpl.removeReaction(post.userId, post.id)
|
reactionServiceImpl.removeReaction(post.actorId, post.id)
|
||||||
|
|
||||||
verify(reactionRepository, times(1)).delete(eq(Reaction(0, 0, post.id, post.userId)))
|
verify(reactionRepository, times(1)).delete(eq(Reaction(0, 0, post.id, post.actorId)))
|
||||||
verify(apReactionService, times(1)).removeReaction(eq(Reaction(0, 0, post.id, post.userId)))
|
verify(apReactionService, times(1)).removeReaction(eq(Reaction(0, 0, post.id, post.actorId)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.service.follow.SendFollowDto
|
import dev.usbharu.hideout.core.service.follow.SendFollowDto
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -29,7 +29,7 @@ class RelationshipServiceImplTest {
|
||||||
private val applicationConfig = ApplicationConfig(URL("https://example.com"))
|
private val applicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var relationshipRepository: RelationshipRepository
|
private lateinit var relationshipRepository: RelationshipRepository
|
||||||
|
@ -54,15 +54,15 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `followRequest ローカルの場合followRequestフラグがtrueで永続化される`() = runTest {
|
fun `followRequest ローカルの場合followRequestフラグがtrueで永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
|
|
||||||
relationshipServiceImpl.followRequest(1234, 5678)
|
relationshipServiceImpl.followRequest(1234, 5678)
|
||||||
|
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -76,17 +76,17 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `followRequest リモートの場合Followアクティビティが配送される`() = runTest {
|
fun `followRequest リモートの場合Followアクティビティが配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
relationshipServiceImpl.followRequest(1234, 5678)
|
relationshipServiceImpl.followRequest(1234, 5678)
|
||||||
|
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -104,8 +104,8 @@ class RelationshipServiceImplTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(null)
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(null)
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -123,8 +123,8 @@ class RelationshipServiceImplTest {
|
||||||
fun `followRequest ブロックしている場合フォローリクエスト出来ない`() = runTest {
|
fun `followRequest ブロックしている場合フォローリクエスト出来ない`() = runTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -141,13 +141,13 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `followRequest 既にフォローしている場合は念の為フォロー承認を自動で行う`() = runTest {
|
fun `followRequest 既にフォローしている場合は念の為フォロー承認を自動で行う`() = runTest {
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(remoteUser)
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(localUser)
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -161,8 +161,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -180,8 +180,8 @@ class RelationshipServiceImplTest {
|
||||||
fun `followRequest フォローリクエスト無視の場合は無視する`() = runTest {
|
fun `followRequest フォローリクエスト無視の場合は無視する`() = runTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -192,8 +192,8 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -209,15 +209,15 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `block ローカルユーザーの場合永続化される`() = runTest {
|
fun `block ローカルユーザーの場合永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
|
|
||||||
relationshipServiceImpl.block(1234, 5678)
|
relationshipServiceImpl.block(1234, 5678)
|
||||||
|
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -231,17 +231,17 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `block リモートユーザーの場合永続化されて配送される`() = runTest {
|
fun `block リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
relationshipServiceImpl.block(1234, 5678)
|
relationshipServiceImpl.block(1234, 5678)
|
||||||
|
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -256,12 +256,12 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `acceptFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
fun `acceptFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -274,8 +274,8 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -290,14 +290,14 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `acceptFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
fun `acceptFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -311,8 +311,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -347,7 +347,7 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `acceptFollowRequest フォローリクエストが存在せずforceがtrueのときフォローを承認する`() = runTest {
|
fun `acceptFollowRequest フォローリクエストが存在せずforceがtrueのときフォローを承認する`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
|
@ -360,8 +360,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -410,12 +410,12 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `rejectFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
fun `rejectFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -429,8 +429,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -446,15 +446,15 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `rejectFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
fun `rejectFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
|
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -468,8 +468,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -494,8 +494,8 @@ class RelationshipServiceImplTest {
|
||||||
fun `rejectFollowRequest フォローリクエストが存在しない場合何もしない`() = runTest {
|
fun `rejectFollowRequest フォローリクエストが存在しない場合何もしない`() = runTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 5678,
|
actorId = 5678,
|
||||||
targetUserId = 1234,
|
targetActorId = 1234,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -516,8 +516,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -530,11 +530,11 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `unfollow ローカルユーザーの場合永続化される`() = runTest {
|
fun `unfollow ローカルユーザーの場合永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -548,8 +548,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -565,15 +565,15 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `unfollow リモートユーザー場合永続化されて配送される`() = runTest {
|
fun `unfollow リモートユーザー場合永続化されて配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
|
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -587,8 +587,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -612,8 +612,8 @@ class RelationshipServiceImplTest {
|
||||||
fun `unfollow フォローしていなかった場合は何もしない`() = runTest {
|
fun `unfollow フォローしていなかった場合は何もしない`() = runTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -629,11 +629,11 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `unblock ローカルユーザーの場合永続化される`() = runTest {
|
fun `unblock ローカルユーザーの場合永続化される`() = runTest {
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -647,8 +647,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -664,15 +664,15 @@ class RelationshipServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `unblock リモートユーザーの場合永続化されて配送される`() = runTest {
|
fun `unblock リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||||
whenever(userQueryService.findById(eq(1234))).doReturn(localUser)
|
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||||
|
|
||||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||||
whenever(userQueryService.findById(eq(5678))).doReturn(remoteUser)
|
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = true,
|
blocking = true,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -711,8 +711,8 @@ class RelationshipServiceImplTest {
|
||||||
fun `unblock ブロックしていない場合は何もしない`() = runTest {
|
fun `unblock ブロックしていない場合は何もしない`() = runTest {
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -733,8 +733,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = true,
|
muting = true,
|
||||||
|
@ -750,8 +750,8 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = true,
|
muting = true,
|
||||||
|
@ -765,8 +765,8 @@ class RelationshipServiceImplTest {
|
||||||
verify(relationshipRepository, times(1)).save(
|
verify(relationshipRepository, times(1)).save(
|
||||||
eq(
|
eq(
|
||||||
Relationship(
|
Relationship(
|
||||||
userId = 1234,
|
actorId = 1234,
|
||||||
targetUserId = 5678,
|
targetActorId = 5678,
|
||||||
following = false,
|
following = false,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package dev.usbharu.hideout.core.service.timeline
|
package dev.usbharu.hideout.core.service.timeline
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
import dev.usbharu.hideout.core.domain.model.post.Visibility
|
||||||
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
|
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
|
||||||
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.core.query.UserQueryService
|
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -27,7 +27,7 @@ class TimelineServiceTest {
|
||||||
private lateinit var followerQueryService: FollowerQueryService
|
private lateinit var followerQueryService: FollowerQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userQueryService: UserQueryService
|
private lateinit var actorQueryService: ActorQueryService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var timelineRepository: TimelineRepository
|
private lateinit var timelineRepository: TimelineRepository
|
||||||
|
@ -41,11 +41,11 @@ class TimelineServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `publishTimeline ローカルの投稿はローカルのフォロワーと投稿者のタイムラインに追加される`() = runTest {
|
fun `publishTimeline ローカルの投稿はローカルのフォロワーと投稿者のタイムラインに追加される`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
val listOf = listOf<User>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
val listOf = listOf<Actor>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
||||||
val localUserOf = UserBuilder.localUserOf(id = post.userId)
|
val localUserOf = UserBuilder.localUserOf(id = post.actorId)
|
||||||
|
|
||||||
whenever(followerQueryService.findFollowersById(eq(post.userId))).doReturn(listOf)
|
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(listOf)
|
||||||
whenever(userQueryService.findById(eq(post.userId))).doReturn(localUserOf)
|
whenever(actorQueryService.findById(eq(post.actorId))).doReturn(localUserOf)
|
||||||
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,15 +54,15 @@ class TimelineServiceTest {
|
||||||
verify(timelineRepository).saveAll(capture(captor))
|
verify(timelineRepository).saveAll(capture(captor))
|
||||||
val timelineList = captor.value
|
val timelineList = captor.value
|
||||||
|
|
||||||
assertThat(timelineList).hasSize(4).anyMatch { it.userId == post.userId }
|
assertThat(timelineList).hasSize(4).anyMatch { it.userId == post.actorId }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `publishTimeline リモートの投稿はローカルのフォロワーのタイムラインに追加される`() = runTest {
|
fun `publishTimeline リモートの投稿はローカルのフォロワーのタイムラインに追加される`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
val listOf = listOf<User>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
val listOf = listOf<Actor>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
||||||
|
|
||||||
whenever(followerQueryService.findFollowersById(eq(post.userId))).doReturn(listOf)
|
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(listOf)
|
||||||
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,9 +77,9 @@ class TimelineServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `publishTimeline パブリック投稿はパブリックタイムラインにも追加される`() = runTest {
|
fun `publishTimeline パブリック投稿はパブリックタイムラインにも追加される`() = runTest {
|
||||||
val post = PostBuilder.of()
|
val post = PostBuilder.of()
|
||||||
val listOf = listOf<User>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
val listOf = listOf<Actor>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
||||||
|
|
||||||
whenever(followerQueryService.findFollowersById(eq(post.userId))).doReturn(listOf)
|
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(listOf)
|
||||||
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ class TimelineServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `publishTimeline パブリック投稿ではない場合はローカルのフォロワーのみに追加される`() = runTest {
|
fun `publishTimeline パブリック投稿ではない場合はローカルのフォロワーのみに追加される`() = runTest {
|
||||||
val post = PostBuilder.of(visibility = Visibility.UNLISTED)
|
val post = PostBuilder.of(visibility = Visibility.UNLISTED)
|
||||||
val listOf = listOf<User>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
val listOf = listOf<Actor>(UserBuilder.localUserOf(), UserBuilder.localUserOf())
|
||||||
|
|
||||||
whenever(followerQueryService.findFollowersById(eq(post.userId))).doReturn(listOf)
|
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(listOf)
|
||||||
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ package dev.usbharu.hideout.core.service.user
|
||||||
|
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
|
||||||
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -18,13 +18,13 @@ import java.security.KeyPairGenerator
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class UserServiceTest {
|
class ActorServiceTest {
|
||||||
val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com")))
|
val actorBuilder = Actor.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com")))
|
||||||
val postBuilder = Post.PostBuilder(CharacterLimit())
|
val postBuilder = Post.PostBuilder(CharacterLimit())
|
||||||
@Test
|
@Test
|
||||||
fun `createLocalUser ローカルユーザーを作成できる`() = runTest {
|
fun `createLocalUser ローカルユーザーを作成できる`() = runTest {
|
||||||
|
|
||||||
val userRepository = mock<UserRepository> {
|
val actorRepository = mock<ActorRepository> {
|
||||||
onBlocking { nextId() } doReturn 110001L
|
onBlocking { nextId() } doReturn 110001L
|
||||||
}
|
}
|
||||||
val generateKeyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair()
|
val generateKeyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair()
|
||||||
|
@ -34,17 +34,17 @@ class UserServiceTest {
|
||||||
}
|
}
|
||||||
val userService =
|
val userService =
|
||||||
UserServiceImpl(
|
UserServiceImpl(
|
||||||
userRepository,
|
actorRepository,
|
||||||
userAuthService,
|
userAuthService,
|
||||||
mock(),
|
mock(),
|
||||||
userBuilder,
|
actorBuilder,
|
||||||
testApplicationConfig,
|
testApplicationConfig,
|
||||||
mock()
|
mock()
|
||||||
)
|
)
|
||||||
userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test"))
|
userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test"))
|
||||||
verify(userRepository, times(1)).save(any())
|
verify(actorRepository, times(1)).save(any())
|
||||||
argumentCaptor<User> {
|
argumentCaptor<Actor> {
|
||||||
verify(userRepository, times(1)).save(capture())
|
verify(actorRepository, times(1)).save(capture())
|
||||||
assertEquals("test", firstValue.name)
|
assertEquals("test", firstValue.name)
|
||||||
assertEquals("testUser", firstValue.screenName)
|
assertEquals("testUser", firstValue.screenName)
|
||||||
assertEquals("XXXXXXXXXXXXX", firstValue.description)
|
assertEquals("XXXXXXXXXXXXX", firstValue.description)
|
||||||
|
@ -62,11 +62,11 @@ class UserServiceTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
|
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
|
||||||
|
|
||||||
val userRepository = mock<UserRepository> {
|
val actorRepository = mock<ActorRepository> {
|
||||||
onBlocking { nextId() } doReturn 113345L
|
onBlocking { nextId() } doReturn 113345L
|
||||||
}
|
}
|
||||||
val userService =
|
val userService =
|
||||||
UserServiceImpl(userRepository, mock(), mock(), userBuilder, testApplicationConfig, mock())
|
UserServiceImpl(actorRepository, mock(), mock(), actorBuilder, testApplicationConfig, mock())
|
||||||
val user = RemoteUserCreateDto(
|
val user = RemoteUserCreateDto(
|
||||||
name = "test",
|
name = "test",
|
||||||
domain = "remote.example.com",
|
domain = "remote.example.com",
|
||||||
|
@ -82,9 +82,9 @@ class UserServiceTest {
|
||||||
sharedInbox = null
|
sharedInbox = null
|
||||||
)
|
)
|
||||||
userService.createRemoteUser(user)
|
userService.createRemoteUser(user)
|
||||||
verify(userRepository, times(1)).save(any())
|
verify(actorRepository, times(1)).save(any())
|
||||||
argumentCaptor<User> {
|
argumentCaptor<Actor> {
|
||||||
verify(userRepository, times(1)).save(capture())
|
verify(actorRepository, times(1)).save(capture())
|
||||||
assertEquals("test", firstValue.name)
|
assertEquals("test", firstValue.name)
|
||||||
assertEquals("testUser", firstValue.screenName)
|
assertEquals("testUser", firstValue.screenName)
|
||||||
assertEquals("test user", firstValue.description)
|
assertEquals("test user", firstValue.description)
|
|
@ -1,8 +1,8 @@
|
||||||
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.model.actor.ActorRepository
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
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.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
import dev.usbharu.hideout.core.service.user.UserService
|
import dev.usbharu.hideout.core.service.user.UserService
|
||||||
|
@ -31,7 +31,7 @@ class AccountApiServiceImplTest {
|
||||||
private lateinit var userService: UserService
|
private lateinit var userService: UserService
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var userRepository: UserRepository
|
private lateinit var actorRepository: ActorRepository
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private lateinit var followerQueryService: FollowerQueryService
|
private lateinit var followerQueryService: FollowerQueryService
|
||||||
|
@ -204,8 +204,8 @@ class AccountApiServiceImplTest {
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(loginUser), eq(userId))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(loginUser), eq(userId))).doReturn(
|
||||||
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
||||||
userId = loginUser,
|
actorId = loginUser,
|
||||||
targetUserId = userId,
|
targetActorId = userId,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -239,8 +239,8 @@ class AccountApiServiceImplTest {
|
||||||
|
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(followeeId), eq(userId))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(followeeId), eq(userId))).doReturn(
|
||||||
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
||||||
userId = followeeId,
|
actorId = followeeId,
|
||||||
targetUserId = userId,
|
targetActorId = userId,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
@ -250,8 +250,8 @@ class AccountApiServiceImplTest {
|
||||||
)
|
)
|
||||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(userId), eq(followeeId))).doReturn(
|
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(userId), eq(followeeId))).doReturn(
|
||||||
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
dev.usbharu.hideout.core.domain.model.relationship.Relationship(
|
||||||
userId = userId,
|
actorId = userId,
|
||||||
targetUserId = followeeId,
|
targetActorId = followeeId,
|
||||||
following = true,
|
following = true,
|
||||||
blocking = false,
|
blocking = false,
|
||||||
muting = false,
|
muting = false,
|
||||||
|
|
|
@ -24,7 +24,7 @@ object PostBuilder {
|
||||||
): Post {
|
): Post {
|
||||||
return postBuilder.of(
|
return postBuilder.of(
|
||||||
id = id,
|
id = id,
|
||||||
userId = userId,
|
actorId = userId,
|
||||||
overview = overview,
|
overview = overview,
|
||||||
text = text,
|
text = text,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
|
|
|
@ -3,13 +3,13 @@ package utils
|
||||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
object UserBuilder {
|
object UserBuilder {
|
||||||
private val userBuilder = User.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com")))
|
private val actorBuilder = Actor.UserBuilder(CharacterLimit(), ApplicationConfig(URL("https://example.com")))
|
||||||
|
|
||||||
private val idGenerator = TwitterSnowflakeIdGenerateService
|
private val idGenerator = TwitterSnowflakeIdGenerateService
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ object UserBuilder {
|
||||||
keyId: String = "https://$domain/users/$id#pubkey",
|
keyId: String = "https://$domain/users/$id#pubkey",
|
||||||
followers: String = "https://$domain/users/$id/followers",
|
followers: String = "https://$domain/users/$id/followers",
|
||||||
following: String = "https://$domain/users/$id/following"
|
following: String = "https://$domain/users/$id/following"
|
||||||
): User {
|
): Actor {
|
||||||
return userBuilder.of(
|
return actorBuilder.of(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
domain = domain,
|
domain = domain,
|
||||||
|
@ -63,8 +63,8 @@ object UserBuilder {
|
||||||
keyId: String = "https://$domain/$id#pubkey",
|
keyId: String = "https://$domain/$id#pubkey",
|
||||||
followers: String = "https://$domain/$id/followers",
|
followers: String = "https://$domain/$id/followers",
|
||||||
following: String = "https://$domain/$id/following"
|
following: String = "https://$domain/$id/following"
|
||||||
): User {
|
): Actor {
|
||||||
return userBuilder.of(
|
return actorBuilder.of(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
domain = domain,
|
domain = domain,
|
||||||
|
|
Loading…
Reference in New Issue