mirror of https://github.com/usbharu/Hideout.git
feat: 仮の実装をちゃんと実装
This commit is contained in:
parent
eae606e0e3
commit
6dead7462e
|
@ -8,7 +8,6 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
|
||||||
|
|
||||||
open class Accept @JsonCreator constructor(
|
open class Accept @JsonCreator constructor(
|
||||||
type: List<String> = emptyList(),
|
type: List<String> = emptyList(),
|
||||||
override val name: String,
|
|
||||||
@JsonDeserialize(using = ObjectDeserializer::class)
|
@JsonDeserialize(using = ObjectDeserializer::class)
|
||||||
@JsonProperty("object")
|
@JsonProperty("object")
|
||||||
val apObject: Object,
|
val apObject: Object,
|
||||||
|
@ -16,9 +15,7 @@ open class Accept @JsonCreator constructor(
|
||||||
) : Object(
|
) : Object(
|
||||||
type = add(type, "Accept")
|
type = add(type, "Accept")
|
||||||
),
|
),
|
||||||
HasActor,
|
HasActor {
|
||||||
HasName {
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -26,7 +23,6 @@ open class Accept @JsonCreator constructor(
|
||||||
|
|
||||||
other as Accept
|
other as Accept
|
||||||
|
|
||||||
if (name != other.name) return false
|
|
||||||
if (apObject != other.apObject) return false
|
if (apObject != other.apObject) return false
|
||||||
if (actor != other.actor) return false
|
if (actor != other.actor) return false
|
||||||
|
|
||||||
|
@ -35,7 +31,6 @@ open class Accept @JsonCreator constructor(
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var result = super.hashCode()
|
var result = super.hashCode()
|
||||||
result = 31 * result + name.hashCode()
|
|
||||||
result = 31 * result + apObject.hashCode()
|
result = 31 * result + apObject.hashCode()
|
||||||
result = 31 * result + actor.hashCode()
|
result = 31 * result + actor.hashCode()
|
||||||
return result
|
return result
|
||||||
|
@ -43,10 +38,9 @@ open class Accept @JsonCreator constructor(
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Accept(" +
|
return "Accept(" +
|
||||||
"name='$name', " +
|
"apObject=$apObject, " +
|
||||||
"apObject=$apObject, " +
|
"actor='$actor'" +
|
||||||
"actor='$actor'" +
|
")" +
|
||||||
")" +
|
" ${super.toString()}"
|
||||||
" ${super.toString()}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,36 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.accept
|
package dev.usbharu.hideout.activitypub.service.activity.accept
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.user.User
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
||||||
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
interface ApSendAcceptService {
|
interface ApSendAcceptService {
|
||||||
suspend fun sendAccept(user: User, target: User)
|
suspend fun sendAcceptFollow(user: User, target: User)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApSendAcceptServiceImpl : ApSendAcceptService {
|
class ApSendAcceptServiceImpl(
|
||||||
override suspend fun sendAccept(user: User, target: User) {
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
TODO("Not yet implemented")
|
private val deliverAcceptJob: DeliverAcceptJob
|
||||||
|
) : ApSendAcceptService {
|
||||||
|
override suspend fun sendAcceptFollow(user: User, target: User) {
|
||||||
|
val deliverAcceptJobParam = DeliverAcceptJobParam(
|
||||||
|
Accept(
|
||||||
|
apObject = Follow(
|
||||||
|
apObject = target.url,
|
||||||
|
actor = user.url
|
||||||
|
),
|
||||||
|
actor = user.url
|
||||||
|
),
|
||||||
|
target.inbox,
|
||||||
|
user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
jobQueueParentService.scheduleTypeSafe(deliverAcceptJob, deliverAcceptJobParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,5 @@ package dev.usbharu.hideout.activitypub.service.activity.reject
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.user.User
|
||||||
|
|
||||||
interface ApSendRejectService {
|
interface ApSendRejectService {
|
||||||
suspend fun sendReject(user: User, target: User)
|
suspend fun sendRejectFollow(user: User, target: User)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,32 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.reject
|
package dev.usbharu.hideout.activitypub.service.activity.reject
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.user.User
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJob
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverRejectJobParam
|
||||||
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ApSendRejectServiceImpl : ApSendRejectService {
|
class ApSendRejectServiceImpl(
|
||||||
override suspend fun sendReject(user: User, target: User) {
|
private val applicationConfig: ApplicationConfig,
|
||||||
TODO("Not yet implemented")
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
|
private val deliverRejectJob: DeliverRejectJob
|
||||||
|
) : ApSendRejectService {
|
||||||
|
override suspend fun sendRejectFollow(user: User, target: User) {
|
||||||
|
|
||||||
|
val deliverRejectJobParam = DeliverRejectJobParam(
|
||||||
|
Reject(
|
||||||
|
user.url,
|
||||||
|
"${applicationConfig.url}/reject/${user.id}/${target.id}",
|
||||||
|
Follow(apObject = user.url, actor = target.url)
|
||||||
|
),
|
||||||
|
target.inbox,
|
||||||
|
user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
jobQueueParentService.scheduleTypeSafe(deliverRejectJob, deliverRejectJobParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,56 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.undo
|
package dev.usbharu.hideout.activitypub.service.activity.undo
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
||||||
|
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||||
import dev.usbharu.hideout.core.domain.model.user.User
|
import dev.usbharu.hideout.core.domain.model.user.User
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJob
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverUndoJobParam
|
||||||
|
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class APSendUndoServiceImpl : APSendUndoService {
|
class APSendUndoServiceImpl(
|
||||||
|
private val jobQueueParentService: JobQueueParentService,
|
||||||
|
private val deliverUndoJob: DeliverUndoJob,
|
||||||
|
private val applicationConfig: ApplicationConfig
|
||||||
|
) : APSendUndoService {
|
||||||
override suspend fun sendUndoFollow(user: User, target: User) {
|
override suspend fun sendUndoFollow(user: User, target: User) {
|
||||||
TODO("Not yet implemented")
|
val deliverUndoJobParam = DeliverUndoJobParam(
|
||||||
|
Undo(
|
||||||
|
actor = user.url,
|
||||||
|
id = "${applicationConfig.url}/undo/follow/${user.id}/${target.url}",
|
||||||
|
`object` = Follow(
|
||||||
|
apObject = user.url,
|
||||||
|
actor = target.url
|
||||||
|
),
|
||||||
|
published = Instant.now().toString()
|
||||||
|
),
|
||||||
|
target.inbox,
|
||||||
|
user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendUndoBlock(user: User, target: User) {
|
override suspend fun sendUndoBlock(user: User, target: User) {
|
||||||
TODO("Not yet implemented")
|
val deliverUndoJobParam = DeliverUndoJobParam(
|
||||||
|
Undo(
|
||||||
|
actor = user.url,
|
||||||
|
id = "${applicationConfig.url}/undo/block/${user.id}/${target.url}",
|
||||||
|
`object` = Block(
|
||||||
|
apObject = user.url,
|
||||||
|
actor = target.url,
|
||||||
|
id = "${applicationConfig.url}/block/${user.id}/${target.id}"
|
||||||
|
),
|
||||||
|
published = Instant.now().toString()
|
||||||
|
),
|
||||||
|
target.inbox,
|
||||||
|
user.id
|
||||||
|
)
|
||||||
|
|
||||||
|
jobQueueParentService.scheduleTypeSafe(deliverUndoJob, deliverUndoJobParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package dev.usbharu.hideout.core.external.job
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
||||||
|
import kjob.core.dsl.ScheduleContext
|
||||||
|
import kjob.core.job.JobProps
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
data class DeliverAcceptJobParam(
|
||||||
|
val accept: Accept,
|
||||||
|
val inbox: String,
|
||||||
|
val signer: Long
|
||||||
|
)
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class DeliverAcceptJob(private val objectMapper: ObjectMapper) : HideoutJob<DeliverAcceptJobParam, DeliverAcceptJob>() {
|
||||||
|
|
||||||
|
val accept = string("accept")
|
||||||
|
val inbox = string("inbox")
|
||||||
|
val signer = long("signer")
|
||||||
|
|
||||||
|
override fun convert(value: DeliverAcceptJobParam): ScheduleContext<DeliverAcceptJob>.(DeliverAcceptJob) -> Unit = {
|
||||||
|
props[accept] = objectMapper.writeValueAsString(value.accept)
|
||||||
|
props[inbox] = value.inbox
|
||||||
|
props[signer] = value.signer
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun convert(props: JobProps<DeliverAcceptJob>): DeliverAcceptJobParam {
|
||||||
|
return DeliverAcceptJobParam(
|
||||||
|
objectMapper.readValue(props[accept]),
|
||||||
|
props[inbox],
|
||||||
|
props[signer]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package dev.usbharu.hideout.core.external.job
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
|
import kjob.core.dsl.ScheduleContext
|
||||||
|
import kjob.core.job.JobProps
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
data class DeliverRejectJobParam(
|
||||||
|
val reject: Reject,
|
||||||
|
val inbox: String,
|
||||||
|
val signer: Long
|
||||||
|
)
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class DeliverRejectJob(@Qualifier("activitypub") private val objectMapper: ObjectMapper) :
|
||||||
|
HideoutJob<DeliverRejectJobParam, DeliverRejectJob>() {
|
||||||
|
val reject = string("reject")
|
||||||
|
val inbox = string("inbox")
|
||||||
|
val signer = long("signer")
|
||||||
|
|
||||||
|
override fun convert(value: DeliverRejectJobParam): ScheduleContext<DeliverRejectJob>.(DeliverRejectJob) -> Unit =
|
||||||
|
{
|
||||||
|
props[reject] = objectMapper.writeValueAsString(value.reject)
|
||||||
|
props[inbox] = value.inbox
|
||||||
|
props[signer] = value.signer
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun convert(props: JobProps<DeliverRejectJob>): DeliverRejectJobParam = DeliverRejectJobParam(
|
||||||
|
objectMapper.readValue<Reject>(props[reject]),
|
||||||
|
props[inbox],
|
||||||
|
props[signer]
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package dev.usbharu.hideout.core.external.job
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Undo
|
||||||
|
import kjob.core.dsl.ScheduleContext
|
||||||
|
import kjob.core.job.JobProps
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
data class DeliverUndoJobParam(
|
||||||
|
val undo: Undo,
|
||||||
|
val inbox: String,
|
||||||
|
val signer: Long
|
||||||
|
)
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class DeliverUndoJob(@Qualifier("activitypub") private val objectMapper: ObjectMapper) :
|
||||||
|
HideoutJob<DeliverUndoJobParam, DeliverUndoJob>() {
|
||||||
|
|
||||||
|
val undo = string("undo")
|
||||||
|
val inbox = string("inbox")
|
||||||
|
val signer = long("signer")
|
||||||
|
|
||||||
|
override fun convert(value: DeliverUndoJobParam): ScheduleContext<DeliverUndoJob>.(DeliverUndoJob) -> Unit = {
|
||||||
|
props[undo] = objectMapper.writeValueAsString(value.undo)
|
||||||
|
props[inbox] = value.inbox
|
||||||
|
props[signer] = value.signer
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun convert(props: JobProps<DeliverUndoJob>): DeliverUndoJobParam {
|
||||||
|
return DeliverUndoJobParam(
|
||||||
|
objectMapper.readValue(props[undo]),
|
||||||
|
props[inbox],
|
||||||
|
props[signer]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -146,7 +146,7 @@ class RelationshipServiceImpl(
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = userQueryService.findById(userId)
|
||||||
apSendAcceptService.sendAccept(user, remoteUser)
|
apSendAcceptService.sendAcceptFollow(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ class RelationshipServiceImpl(
|
||||||
|
|
||||||
if (remoteUser != null) {
|
if (remoteUser != null) {
|
||||||
val user = userQueryService.findById(userId)
|
val user = userQueryService.findById(userId)
|
||||||
apSendRejectService.sendReject(user, remoteUser)
|
apSendRejectService.sendRejectFollow(user, remoteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ class ContextSerializerTest {
|
||||||
@Test
|
@Test
|
||||||
fun serialize() {
|
fun serialize() {
|
||||||
val accept = Accept(
|
val accept = Accept(
|
||||||
name = "aaa",
|
|
||||||
actor = "bbb",
|
actor = "bbb",
|
||||||
apObject = Follow(
|
apObject = Follow(
|
||||||
apObject = "ddd",
|
apObject = "ddd",
|
||||||
|
|
|
@ -172,7 +172,7 @@ class RelationshipServiceImplTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(apSendAcceptService, times(1)).sendAccept(eq(localUser), eq(remoteUser))
|
verify(apSendAcceptService, times(1)).sendAcceptFollow(eq(localUser), eq(remoteUser))
|
||||||
verify(apSendFollowService, never()).sendFollow(any())
|
verify(apSendFollowService, never()).sendFollow(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ class RelationshipServiceImplTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(apSendAcceptService, never()).sendAccept(any(), any())
|
verify(apSendAcceptService, never()).sendAcceptFollow(any(), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -322,14 +322,14 @@ class RelationshipServiceImplTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(apSendAcceptService, times(1)).sendAccept(eq(localUser), eq(remoteUser))
|
verify(apSendAcceptService, times(1)).sendAcceptFollow(eq(localUser), eq(remoteUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `acceptFollowRequest Relationshipが存在しないときは何もしない`() = runTest {
|
fun `acceptFollowRequest Relationshipが存在しないときは何もしない`() = runTest {
|
||||||
relationshipServiceImpl.acceptFollowRequest(1234, 5678, false)
|
relationshipServiceImpl.acceptFollowRequest(1234, 5678, false)
|
||||||
|
|
||||||
verify(apSendAcceptService, never()).sendAccept(any(), any())
|
verify(apSendAcceptService, never()).sendAcceptFollow(any(), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -342,7 +342,7 @@ class RelationshipServiceImplTest {
|
||||||
|
|
||||||
relationshipServiceImpl.acceptFollowRequest(1234, 5678, false)
|
relationshipServiceImpl.acceptFollowRequest(1234, 5678, false)
|
||||||
|
|
||||||
verify(apSendAcceptService, never()).sendAccept(any(), any())
|
verify(apSendAcceptService, never()).sendAcceptFollow(any(), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -440,7 +440,7 @@ class RelationshipServiceImplTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(apSendRejectService, never()).sendReject(any(), any())
|
verify(apSendRejectService, never()).sendRejectFollow(any(), any())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -479,7 +479,7 @@ class RelationshipServiceImplTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
verify(apSendRejectService, times(1)).sendReject(eq(localUser), eq(remoteUser))
|
verify(apSendRejectService, times(1)).sendRejectFollow(eq(localUser), eq(remoteUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue