mirror of https://github.com/usbharu/Hideout.git
refactor: 一括検索を都度検索に変更
This commit is contained in:
parent
6265d0772a
commit
d2524a5684
|
@ -8,6 +8,7 @@ import dev.usbharu.hideout.domain.model.ap.Accept
|
|||
import dev.usbharu.hideout.domain.model.ap.Follow
|
||||
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
|
||||
import dev.usbharu.hideout.plugins.postAp
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import io.ktor.client.*
|
||||
|
@ -20,7 +21,8 @@ class ActivityPubReceiveFollowServiceImpl(
|
|||
private val jobQueueParentService: JobQueueParentService,
|
||||
private val activityPubUserService: ActivityPubUserService,
|
||||
private val userService: IUserService,
|
||||
private val httpClient: HttpClient
|
||||
private val httpClient: HttpClient,
|
||||
private val userQueryService: UserQueryService
|
||||
) : ActivityPubReceiveFollowService {
|
||||
override suspend fun receiveFollow(follow: Follow): ActivityPubResponse {
|
||||
// TODO: Verify HTTP Signature
|
||||
|
@ -46,9 +48,11 @@ class ActivityPubReceiveFollowServiceImpl(
|
|||
actor = targetActor
|
||||
)
|
||||
)
|
||||
val users =
|
||||
userService.findByUrls(listOf(targetActor, follow.actor ?: throw IllegalArgumentException("actor is null")))
|
||||
|
||||
userService.followRequest(users.first { it.url == targetActor }.id, users.first { it.url == follow.actor }.id)
|
||||
val targetEntity = userQueryService.findByUrl(targetActor)
|
||||
val followActorEntity =
|
||||
userQueryService.findByUrl(follow.actor ?: throw java.lang.IllegalArgumentException("Actor is null"))
|
||||
|
||||
userService.followRequest(targetEntity.id, followActorEntity.id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,6 @@ class UserService(
|
|||
) :
|
||||
IUserService {
|
||||
|
||||
override suspend fun findByNameLocalUser(name: String): User {
|
||||
return userRepository.findByNameAndDomain(name, Config.configData.domain)
|
||||
?: throw UserNotFoundException("$name was not found.")
|
||||
}
|
||||
|
||||
override suspend fun findByUrl(url: String): User =
|
||||
userRepository.findByUrl(url) ?: throw UserNotFoundException("$url was not found.")
|
||||
|
||||
override suspend fun findByUrls(urls: List<String>): List<User> = userRepository.findByUrls(urls)
|
||||
|
||||
override suspend fun usernameAlreadyUse(username: String): Boolean {
|
||||
|
|
|
@ -9,6 +9,7 @@ import dev.usbharu.hideout.config.ConfigData
|
|||
import dev.usbharu.hideout.domain.model.ap.*
|
||||
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
|
||||
import dev.usbharu.hideout.query.UserQueryService
|
||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||
import dev.usbharu.hideout.service.user.IUserService
|
||||
import io.ktor.client.*
|
||||
|
@ -32,7 +33,7 @@ class ActivityPubReceiveFollowServiceImplTest {
|
|||
onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit
|
||||
}
|
||||
val activityPubFollowService =
|
||||
ActivityPubReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock())
|
||||
ActivityPubReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock())
|
||||
activityPubFollowService.receiveFollow(
|
||||
Follow(
|
||||
emptyList(),
|
||||
|
@ -97,8 +98,8 @@ class ActivityPubReceiveFollowServiceImplTest {
|
|||
val activityPubUserService = mock<ActivityPubUserService> {
|
||||
onBlocking { fetchPerson(anyString(), any()) } doReturn person
|
||||
}
|
||||
val userService = mock<IUserService> {
|
||||
onBlocking { findByUrls(any()) } doReturn listOf(
|
||||
val userQueryService = mock<UserQueryService> {
|
||||
onBlocking { findByUrl(eq("https://example.com")) } doReturn
|
||||
User(
|
||||
id = 1L,
|
||||
name = "test",
|
||||
|
@ -110,7 +111,8 @@ class ActivityPubReceiveFollowServiceImplTest {
|
|||
url = "https://example.com",
|
||||
publicKey = "",
|
||||
createdAt = Instant.now()
|
||||
),
|
||||
)
|
||||
onBlocking { findByUrl(eq("https://follower.example.com")) } doReturn
|
||||
User(
|
||||
id = 2L,
|
||||
name = "follower",
|
||||
|
@ -123,7 +125,9 @@ class ActivityPubReceiveFollowServiceImplTest {
|
|||
publicKey = "",
|
||||
createdAt = Instant.now()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val userService = mock<IUserService> {
|
||||
onBlocking { followRequest(any(), any()) } doReturn false
|
||||
}
|
||||
val activityPubFollowService =
|
||||
|
@ -156,7 +160,8 @@ class ActivityPubReceiveFollowServiceImplTest {
|
|||
)
|
||||
respondOk()
|
||||
}
|
||||
)
|
||||
),
|
||||
userQueryService
|
||||
)
|
||||
activityPubFollowService.receiveFollowJob(
|
||||
JobProps(
|
||||
|
|
Loading…
Reference in New Issue