Merge branch 'develop' into bugfix/deliver-local-post-delete

This commit is contained in:
usbharu 2024-01-16 16:14:55 +09:00 committed by GitHub
commit 65991f9093
6 changed files with 30 additions and 9 deletions

View File

@ -316,3 +316,7 @@ koverReport {
} }
} }
} }
springBoot {
buildInfo()
}

View File

@ -6,12 +6,12 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Follow( open class Follow(
type: List<String> = emptyList(), type: List<String> = emptyList(),
@JsonProperty("object") val apObject: String, @JsonProperty("object") val apObject: String,
override val actor: String override val actor: String,
val id: String? = null
) : Object( ) : Object(
type = add(type, "Follow") type = add(type, "Follow")
), ),
HasActor { HasActor {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (javaClass != other?.javaClass) return false if (javaClass != other?.javaClass) return false
@ -21,6 +21,7 @@ open class Follow(
if (apObject != other.apObject) return false if (apObject != other.apObject) return false
if (actor != other.actor) return false if (actor != other.actor) return false
if (id != other.id) return false
return true return true
} }
@ -29,13 +30,15 @@ open class Follow(
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + apObject.hashCode() result = 31 * result + apObject.hashCode()
result = 31 * result + actor.hashCode() result = 31 * result + actor.hashCode()
result = 31 * result + (id?.hashCode() ?: 0)
return result return result
} }
override fun toString(): String { override fun toString(): String {
return "Follow(" + return "Follow(" +
"apObject='$apObject', " + "apObject='$apObject', " +
"actor='$actor'" + "actor='$actor', " +
"id=$id" +
")" + ")" +
" ${super.toString()}" " ${super.toString()}"
} }

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.activitypub.service.activity.follow
import dev.usbharu.hideout.activitypub.domain.model.Follow 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.application.config.ApplicationConfig
import dev.usbharu.hideout.core.service.follow.SendFollowDto import dev.usbharu.hideout.core.service.follow.SendFollowDto
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -12,11 +13,13 @@ interface APSendFollowService {
@Service @Service
class APSendFollowServiceImpl( class APSendFollowServiceImpl(
private val apRequestService: APRequestService, private val apRequestService: APRequestService,
private val applicationConfig: ApplicationConfig,
) : APSendFollowService { ) : APSendFollowService {
override suspend fun sendFollow(sendFollowDto: SendFollowDto) { override suspend fun sendFollow(sendFollowDto: SendFollowDto) {
val follow = Follow( val follow = Follow(
apObject = sendFollowDto.followTargetActorId.url, apObject = sendFollowDto.followTargetActorId.url,
actor = sendFollowDto.actorId.url actor = sendFollowDto.actorId.url,
id = "${applicationConfig.url}/follow/${sendFollowDto.actorId.id}/${sendFollowDto.followTargetActorId.id}"
) )
apRequestService.apPost(sendFollowDto.followTargetActorId.inbox, follow, sendFollowDto.actorId) apRequestService.apPost(sendFollowDto.followTargetActorId.inbox, follow, sendFollowDto.actorId)

View File

@ -2,15 +2,18 @@ package dev.usbharu.hideout.application.config
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.engine.cio.* import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.cache.* import io.ktor.client.plugins.cache.*
import io.ktor.client.plugins.logging.* import io.ktor.client.plugins.logging.*
import org.springframework.boot.info.BuildProperties
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
@Configuration @Configuration
class HttpClientConfig { class HttpClientConfig {
@Bean @Bean
fun httpClient(): HttpClient = HttpClient(CIO).config { fun httpClient(buildProperties: BuildProperties, applicationConfig: ApplicationConfig): HttpClient =
HttpClient(CIO).config {
install(Logging) { install(Logging) {
logger = Logger.DEFAULT logger = Logger.DEFAULT
level = LogLevel.ALL level = LogLevel.ALL
@ -18,5 +21,8 @@ class HttpClientConfig {
install(HttpCache) { install(HttpCache) {
} }
expectSuccess = true expectSuccess = true
} install(UserAgent) {
agent = "Hideout/${buildProperties.version} (${applicationConfig.url})"
}
}
} }

View File

@ -53,7 +53,8 @@ class RejectTest {
"https://misskey.usbharu.dev/06407419-5aeb-4e2d-8885-aa54b03decf0", "https://misskey.usbharu.dev/06407419-5aeb-4e2d-8885-aa54b03decf0",
Follow( Follow(
apObject = "https://misskey.usbharu.dev/users/97ws8y3rj6", apObject = "https://misskey.usbharu.dev/users/97ws8y3rj6",
actor = "https://test-hideout.usbharu.dev/users/test-user2" actor = "https://test-hideout.usbharu.dev/users/test-user2",
id = "https://misskey.usbharu.dev/follows/9mxh6mawru/97ws8y3rj6"
) )
).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") } ).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") }

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.activitypub.service.activity.follow
import dev.usbharu.hideout.activitypub.domain.model.Follow 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.application.config.ApplicationConfig
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
@ -10,12 +11,14 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.times import org.mockito.kotlin.times
import org.mockito.kotlin.verify import org.mockito.kotlin.verify
import utils.UserBuilder import utils.UserBuilder
import java.net.URL
class APSendFollowServiceImplTest { class APSendFollowServiceImplTest {
@Test @Test
fun `sendFollow フォローするユーザーのinboxにFollowオブジェクトが送られる`() = runTest { fun `sendFollow フォローするユーザーのinboxにFollowオブジェクトが送られる`() = runTest {
val apRequestService = mock<APRequestService>() val apRequestService = mock<APRequestService>()
val apSendFollowServiceImpl = APSendFollowServiceImpl(apRequestService) val applicationConfig = ApplicationConfig(URL("https://example.com"))
val apSendFollowServiceImpl = APSendFollowServiceImpl(apRequestService, applicationConfig)
val sendFollowDto = SendFollowDto( val sendFollowDto = SendFollowDto(
UserBuilder.localUserOf(), UserBuilder.localUserOf(),
@ -25,7 +28,8 @@ class APSendFollowServiceImplTest {
val value = Follow( val value = Follow(
apObject = sendFollowDto.followTargetActorId.url, apObject = sendFollowDto.followTargetActorId.url,
actor = sendFollowDto.actorId.url actor = sendFollowDto.actorId.url,
id = "${applicationConfig.url}/follow/${sendFollowDto.actorId.id}/${sendFollowDto.followTargetActorId.id}"
) )
verify(apRequestService, times(1)).apPost( verify(apRequestService, times(1)).apPost(
eq(sendFollowDto.followTargetActorId.inbox), eq(sendFollowDto.followTargetActorId.inbox),