mirror of https://github.com/usbharu/Hideout.git
fix: Exposedの変更を修正
This commit is contained in:
parent
4506a47a19
commit
fd0a90ee51
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 usbharu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dev.usbharu.hideout.activitypub.domain.model
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||
|
||||
open class Block(
|
||||
override val actor: String,
|
||||
override val id: String,
|
||||
@JsonProperty("object") val apObject: String
|
||||
) :
|
||||
Object(listOf("Block")), HasId, HasActor {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
if (!super.equals(other)) return false
|
||||
|
||||
other as Block
|
||||
|
||||
if (actor != other.actor) return false
|
||||
if (id != other.id) return false
|
||||
if (apObject != other.apObject) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = super.hashCode()
|
||||
result = 31 * result + actor.hashCode()
|
||||
result = 31 * result + id.hashCode()
|
||||
result = 31 * result + apObject.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Block(" +
|
||||
"actor='$actor', " +
|
||||
"id='$id', " +
|
||||
"apObject='$apObject'" +
|
||||
")" +
|
||||
" ${super.toString()}"
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
|
|||
ExtendedActivityVocabulary.Add -> null
|
||||
ExtendedActivityVocabulary.Announce -> p.codec.treeToValue(treeNode, Announce::class.java)
|
||||
ExtendedActivityVocabulary.Arrive -> null
|
||||
ExtendedActivityVocabulary.Block -> p.codec.treeToValue(treeNode, Block::class.java)
|
||||
ExtendedActivityVocabulary.Block -> null
|
||||
ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java)
|
||||
ExtendedActivityVocabulary.Delete -> p.codec.treeToValue(treeNode, Delete::class.java)
|
||||
ExtendedActivityVocabulary.Dislike -> null
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 usbharu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dev.usbharu.hideout.activitypub.service.activity.block
|
||||
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||
import dev.usbharu.owl.producer.api.OwlProducer
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
interface APSendBlockService {
|
||||
suspend fun sendBlock(actor: Actor, target: Actor)
|
||||
}
|
||||
|
||||
@Service
|
||||
class ApSendBlockServiceImpl(
|
||||
private val applicationConfig: ApplicationConfig,
|
||||
private val owlProducer: OwlProducer,
|
||||
) : APSendBlockService {
|
||||
override suspend fun sendBlock(actor: Actor, target: Actor) {
|
||||
// val blockJobParam = DeliverBlockJobParam(
|
||||
// actor.id,
|
||||
// Block(
|
||||
// actor.url,
|
||||
// "${applicationConfig.url}/block/${actor.id}/${target.id}",
|
||||
// target.url
|
||||
// ),
|
||||
// Reject(
|
||||
// actor.url,
|
||||
// "${applicationConfig.url}/reject/${actor.id}/${target.id}",
|
||||
// Follow(
|
||||
// apObject = actor.url,
|
||||
// actor = target.url
|
||||
// )
|
||||
// ),
|
||||
// target.inbox
|
||||
// )
|
||||
// owlProducer.publishTask(blockJobParam)
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 usbharu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dev.usbharu.hideout.activitypub.service.activity.block
|
||||
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||
import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor
|
||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||
import dev.usbharu.hideout.application.external.Transaction
|
||||
import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
/**
|
||||
* ブロックアクティビティを処理します
|
||||
*/
|
||||
@Service
|
||||
class BlockActivityPubProcessor(
|
||||
private val relationshipService: RelationshipService,
|
||||
private val actorRepository: ActorRepository,
|
||||
transaction: Transaction
|
||||
) :
|
||||
AbstractActivityPubProcessor<Block>(transaction) {
|
||||
override suspend fun internalProcess(activity: ActivityPubProcessContext<Block>) {
|
||||
val user = actorRepository.findByUrl(activity.activity.actor)
|
||||
?: throw UserNotFoundException.withUrl(activity.activity.actor)
|
||||
val target = actorRepository.findByUrl(activity.activity.apObject) ?: throw UserNotFoundException.withUrl(
|
||||
activity.activity.apObject
|
||||
)
|
||||
relationshipService.block(user.id, target.id)
|
||||
}
|
||||
|
||||
override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Block
|
||||
|
||||
override fun type(): Class<Block> = Block::class.java
|
||||
}
|
|
@ -20,5 +20,4 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor
|
|||
|
||||
interface APSendUndoService {
|
||||
suspend fun sendUndoFollow(actor: Actor, target: Actor)
|
||||
suspend fun sendUndoBlock(actor: Actor, target: Actor)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
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
|
||||
|
@ -49,22 +48,4 @@ class APSendUndoServiceImpl(
|
|||
owlProducer.publishTask(deliverUndoTask)
|
||||
}
|
||||
|
||||
override suspend fun sendUndoBlock(actor: Actor, target: Actor) {
|
||||
val deliverUndoTask = DeliverUndoTask(
|
||||
Undo(
|
||||
actor = actor.url,
|
||||
id = "${applicationConfig.url}/undo/block/${actor.id}/${target.url}",
|
||||
apObject = Block(
|
||||
apObject = actor.url,
|
||||
actor = target.url,
|
||||
id = "${applicationConfig.url}/block/${actor.id}/${target.id}"
|
||||
),
|
||||
published = Instant.now().toString()
|
||||
),
|
||||
target.inbox,
|
||||
actor.id
|
||||
)
|
||||
|
||||
owlProducer.publishTask(deliverUndoTask)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,11 +56,6 @@ class APUndoProcessor(
|
|||
return
|
||||
}
|
||||
|
||||
"Block" -> {
|
||||
block(undo)
|
||||
return
|
||||
}
|
||||
|
||||
"Accept" -> {
|
||||
accept(undo)
|
||||
return
|
||||
|
@ -112,16 +107,6 @@ class APUndoProcessor(
|
|||
return
|
||||
}
|
||||
|
||||
private suspend fun block(undo: Undo) {
|
||||
val block = undo.apObject as Block
|
||||
|
||||
val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second
|
||||
val target = actorRepository.findByUrl(block.apObject) ?: throw UserNotFoundException.withUrl(block.apObject)
|
||||
|
||||
relationshipService.unblock(blocker.id, target.id)
|
||||
return
|
||||
}
|
||||
|
||||
private suspend fun follow(undo: Undo) {
|
||||
val follow = undo.apObject as Follow
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package dev.usbharu.hideout.core.service.relationship
|
||||
|
||||
import dev.usbharu.hideout.activitypub.service.activity.accept.ApSendAcceptService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.block.APSendBlockService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.follow.APSendFollowService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService
|
||||
|
@ -39,12 +38,11 @@ class RelationshipServiceImpl(
|
|||
private val applicationConfig: ApplicationConfig,
|
||||
private val relationshipRepository: RelationshipRepository,
|
||||
private val apSendFollowService: APSendFollowService,
|
||||
private val apSendBlockService: APSendBlockService,
|
||||
private val apSendAcceptService: ApSendAcceptService,
|
||||
private val apSendRejectService: ApSendRejectService,
|
||||
private val apSendUndoService: APSendUndoService,
|
||||
private val actorRepository: ActorRepository,
|
||||
private val notificationService: NotificationService
|
||||
private val notificationService: NotificationService,
|
||||
) : RelationshipService {
|
||||
override suspend fun followRequest(actorId: Long, targetId: Long) {
|
||||
logger.info("START Follow Request userId: {} targetId: {}", actorId, targetId)
|
||||
|
@ -145,12 +143,6 @@ class RelationshipServiceImpl(
|
|||
if (blockedInverseRelationship != null) {
|
||||
relationshipRepository.save(blockedInverseRelationship)
|
||||
}
|
||||
|
||||
val remoteUser = isRemoteUser(targetId)
|
||||
|
||||
if (remoteUser != null) {
|
||||
apSendBlockService.sendBlock(user, remoteUser)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun acceptFollowRequest(actorId: Long, targetId: Long, force: Boolean) {
|
||||
|
@ -298,12 +290,6 @@ class RelationshipServiceImpl(
|
|||
|
||||
val copy = relationship.copy(blocking = false)
|
||||
relationshipRepository.save(copy)
|
||||
|
||||
val remoteUser = isRemoteUser(targetId)
|
||||
if (remoteUser != null) {
|
||||
val user = actorRepository.findById(actorId) ?: throw UserNotFoundException.withId(actorId)
|
||||
apSendUndoService.sendUndoBlock(user, remoteUser)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun mute(actorId: Long, targetId: Long) {
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 usbharu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dev.usbharu.hideout.activitypub.domain.model
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.json.BasicJsonTester
|
||||
|
||||
class BlockTest {
|
||||
@Test
|
||||
fun blockDeserializeTest() {
|
||||
@Language("JSON") val json = """{
|
||||
"@context" : [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", {
|
||||
"manuallyApprovesFollowers" : "as:manuallyApprovesFollowers",
|
||||
"sensitive" : "as:sensitive",
|
||||
"Hashtag" : "as:Hashtag",
|
||||
"quoteUrl" : "as:quoteUrl",
|
||||
"toot" : "http://joinmastodon.org/ns#",
|
||||
"Emoji" : "toot:Emoji",
|
||||
"featured" : "toot:featured",
|
||||
"discoverable" : "toot:discoverable",
|
||||
"schema" : "http://schema.org#",
|
||||
"PropertyValue" : "schema:PropertyValue",
|
||||
"value" : "schema:value",
|
||||
"misskey" : "https://misskey-hub.net/ns#",
|
||||
"_misskey_content" : "misskey:_misskey_content",
|
||||
"_misskey_quote" : "misskey:_misskey_quote",
|
||||
"_misskey_reaction" : "misskey:_misskey_reaction",
|
||||
"_misskey_votes" : "misskey:_misskey_votes",
|
||||
"_misskey_summary" : "misskey:_misskey_summary",
|
||||
"isCat" : "misskey:isCat",
|
||||
"vcard" : "http://www.w3.org/2006/vcard/ns#"
|
||||
} ],
|
||||
"type" : "Block",
|
||||
"id" : "https://misskey.usbharu.dev/blocks/9myf6e40vm",
|
||||
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
|
||||
"object" : "https://test-hideout.usbharu.dev/users/test-user2"
|
||||
}
|
||||
"""
|
||||
|
||||
val objectMapper = ActivityPubConfig().objectMapper()
|
||||
|
||||
val block = objectMapper.readValue<Block>(json)
|
||||
|
||||
val expected = Block(
|
||||
"https://misskey.usbharu.dev/users/97ws8y3rj6",
|
||||
"https://misskey.usbharu.dev/blocks/9myf6e40vm",
|
||||
"https://test-hideout.usbharu.dev/users/test-user2"
|
||||
).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") }
|
||||
assertThat(block).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blockSerializeTest() {
|
||||
val basicJsonTester = BasicJsonTester(javaClass)
|
||||
|
||||
val block = Block(
|
||||
"https://misskey.usbharu.dev/users/97ws8y3rj6",
|
||||
"https://misskey.usbharu.dev/blocks/9myf6e40vm",
|
||||
"https://test-hideout.usbharu.dev/users/test-user2"
|
||||
).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") }
|
||||
|
||||
val objectMapper = ActivityPubConfig().objectMapper()
|
||||
|
||||
val writeValueAsString = objectMapper.writeValueAsString(block)
|
||||
|
||||
val from = basicJsonTester.from(writeValueAsString)
|
||||
assertThat(from).extractingJsonPathStringValue("$.actor")
|
||||
.isEqualTo("https://misskey.usbharu.dev/users/97ws8y3rj6")
|
||||
assertThat(from).extractingJsonPathStringValue("$.id")
|
||||
.isEqualTo("https://misskey.usbharu.dev/blocks/9myf6e40vm")
|
||||
assertThat(from).extractingJsonPathStringValue("$.object")
|
||||
.isEqualTo("https://test-hideout.usbharu.dev/users/test-user2")
|
||||
assertThat(from).extractingJsonPathStringValue("$.type").isEqualTo("Block")
|
||||
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
package dev.usbharu.hideout.core.service.relationship
|
||||
|
||||
import dev.usbharu.hideout.activitypub.service.activity.accept.ApSendAcceptService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.block.APSendBlockService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.follow.APSendFollowService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectService
|
||||
import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService
|
||||
|
@ -55,9 +54,6 @@ class RelationshipServiceImplTest {
|
|||
@Mock
|
||||
private lateinit var apSendFollowService: APSendFollowService
|
||||
|
||||
@Mock
|
||||
private lateinit var apSendBlockService: APSendBlockService
|
||||
|
||||
@Mock
|
||||
private lateinit var apSendAcceptService: ApSendAcceptService
|
||||
|
||||
|
@ -272,8 +268,6 @@ class RelationshipServiceImplTest {
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
verify(apSendBlockService, times(1)).sendBlock(eq(localUser), eq(remoteUser))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -657,7 +651,6 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `unblock ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
actorId = 1234,
|
||||
|
@ -685,17 +678,10 @@ class RelationshipServiceImplTest {
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
verify(apSendUndoService, never()).sendUndoBlock(any(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unblock リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
|
@ -724,8 +710,6 @@ class RelationshipServiceImplTest {
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
verify(apSendUndoService, times(1)).sendUndoBlock(eq(localUser), eq(remoteUser))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue