diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt index e7c3d132..00b51262 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImpl.kt @@ -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) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt b/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt index 43bda21e..c2464ca3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/user/UserService.kt @@ -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): List = userRepository.findByUrls(urls) override suspend fun usernameAlreadyUse(username: String): Boolean { diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt index 0d703801..34b96781 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt @@ -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 { onBlocking { fetchPerson(anyString(), any()) } doReturn person } - val userService = mock { - onBlocking { findByUrls(any()) } doReturn listOf( + val userQueryService = mock { + 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 { onBlocking { followRequest(any(), any()) } doReturn false } val activityPubFollowService = @@ -156,7 +160,8 @@ class ActivityPubReceiveFollowServiceImplTest { ) respondOk() } - ) + ), + userQueryService ) activityPubFollowService.receiveFollowJob( JobProps(