mirror of https://github.com/usbharu/Hideout.git
feat: リモートのNoteのDelete Activityの受信に対応
This commit is contained in:
parent
ce7024849a
commit
5c6987f2b0
|
@ -0,0 +1,49 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.domain.model
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
|
||||||
|
|
||||||
|
open class Delete : Object {
|
||||||
|
@JsonDeserialize(using = ObjectDeserializer::class)
|
||||||
|
var `object`: Object? = null
|
||||||
|
var published: String? = null
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
type: List<String> = emptyList(),
|
||||||
|
name: String = "Delete",
|
||||||
|
actor: String,
|
||||||
|
id: String,
|
||||||
|
`object`: Object,
|
||||||
|
published: String?
|
||||||
|
) : super(add(type, "Delete"), name, actor, id) {
|
||||||
|
this.`object` = `object`
|
||||||
|
this.published = published
|
||||||
|
}
|
||||||
|
|
||||||
|
protected constructor() : super()
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is Delete) return false
|
||||||
|
if (!super.equals(other)) return false
|
||||||
|
|
||||||
|
if (`object` != other.`object`) return false
|
||||||
|
if (published != other.published) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = super.hashCode()
|
||||||
|
result = 31 * result + (`object`?.hashCode() ?: 0)
|
||||||
|
result = 31 * result + (published?.hashCode() ?: 0)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "Delete(`object`=$`object`, published=$published) ${super.toString()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.domain.model
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.objects.Object
|
||||||
|
|
||||||
|
open class Tombstone : Object {
|
||||||
|
constructor(
|
||||||
|
type: List<String> = emptyList(),
|
||||||
|
name: String = "Tombstone",
|
||||||
|
actor: String? = null,
|
||||||
|
id: String
|
||||||
|
) : super(add(type, "Tombstone"), name, actor, id)
|
||||||
|
}
|
|
@ -56,7 +56,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
ExtendedActivityVocabulary.Arrive -> TODO()
|
ExtendedActivityVocabulary.Arrive -> TODO()
|
||||||
ExtendedActivityVocabulary.Block -> TODO()
|
ExtendedActivityVocabulary.Block -> TODO()
|
||||||
ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java)
|
ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java)
|
||||||
ExtendedActivityVocabulary.Delete -> TODO()
|
ExtendedActivityVocabulary.Delete -> p.codec.treeToValue(treeNode, Delete::class.java)
|
||||||
ExtendedActivityVocabulary.Dislike -> TODO()
|
ExtendedActivityVocabulary.Dislike -> TODO()
|
||||||
ExtendedActivityVocabulary.Flag -> TODO()
|
ExtendedActivityVocabulary.Flag -> TODO()
|
||||||
ExtendedActivityVocabulary.Ignore -> TODO()
|
ExtendedActivityVocabulary.Ignore -> TODO()
|
||||||
|
@ -91,7 +91,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
ExtendedActivityVocabulary.Place -> TODO()
|
ExtendedActivityVocabulary.Place -> TODO()
|
||||||
ExtendedActivityVocabulary.Profile -> TODO()
|
ExtendedActivityVocabulary.Profile -> TODO()
|
||||||
ExtendedActivityVocabulary.Relationship -> TODO()
|
ExtendedActivityVocabulary.Relationship -> TODO()
|
||||||
ExtendedActivityVocabulary.Tombstone -> TODO()
|
ExtendedActivityVocabulary.Tombstone -> p.codec.treeToValue(treeNode, Tombstone::class.java)
|
||||||
ExtendedActivityVocabulary.Video -> TODO()
|
ExtendedActivityVocabulary.Video -> TODO()
|
||||||
ExtendedActivityVocabulary.Mention -> TODO()
|
ExtendedActivityVocabulary.Mention -> TODO()
|
||||||
ExtendedActivityVocabulary.Emoji -> p.codec.treeToValue(treeNode, Emoji::class.java)
|
ExtendedActivityVocabulary.Emoji -> p.codec.treeToValue(treeNode, Emoji::class.java)
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.service.activity.delete
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Delete
|
||||||
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
||||||
|
|
||||||
|
interface APReceiveDeleteService {
|
||||||
|
suspend fun receiveDelete(delete: Delete): ActivityPubResponse
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.service.activity.delete
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Delete
|
||||||
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
||||||
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubStringResponse
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||||
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
|
import io.ktor.http.*
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class APReceiveDeleteServiceImpl(
|
||||||
|
private val postQueryService: PostQueryService,
|
||||||
|
private val postRepository: PostRepository,
|
||||||
|
private val transaction: Transaction
|
||||||
|
) : APReceiveDeleteService {
|
||||||
|
override suspend fun receiveDelete(delete: Delete): ActivityPubResponse = transaction.transaction {
|
||||||
|
val deleteId = delete.`object`?.id ?: throw IllegalActivityPubObjectException("object.id is null")
|
||||||
|
|
||||||
|
val post = try {
|
||||||
|
postQueryService.findByApId(deleteId)
|
||||||
|
} catch (e: FailedToGetResourcesException) {
|
||||||
|
return@transaction ActivityPubStringResponse(HttpStatusCode.OK, "Resource not found or already deleted")
|
||||||
|
}
|
||||||
|
postRepository.delete(post.id)
|
||||||
|
return@transaction ActivityPubStringResponse(HttpStatusCode.OK, "Resource was deleted.")
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||||
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
import dev.usbharu.hideout.activitypub.interfaces.api.common.ActivityPubResponse
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.accept.APAcceptService
|
import dev.usbharu.hideout.activitypub.service.activity.accept.APAcceptService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.create.APCreateService
|
import dev.usbharu.hideout.activitypub.service.activity.create.APCreateService
|
||||||
|
import dev.usbharu.hideout.activitypub.service.activity.delete.APReceiveDeleteService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowService
|
import dev.usbharu.hideout.activitypub.service.activity.follow.APReceiveFollowService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.like.APLikeService
|
import dev.usbharu.hideout.activitypub.service.activity.like.APLikeService
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.undo.APUndoService
|
import dev.usbharu.hideout.activitypub.service.activity.undo.APUndoService
|
||||||
|
@ -180,7 +181,8 @@ class APServiceImpl(
|
||||||
private val apAcceptService: APAcceptService,
|
private val apAcceptService: APAcceptService,
|
||||||
private val apCreateService: APCreateService,
|
private val apCreateService: APCreateService,
|
||||||
private val apLikeService: APLikeService,
|
private val apLikeService: APLikeService,
|
||||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
||||||
|
private val apReceiveDeleteService: APReceiveDeleteService
|
||||||
) : APService {
|
) : APService {
|
||||||
|
|
||||||
val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java)
|
val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java)
|
||||||
|
@ -234,6 +236,7 @@ class APServiceImpl(
|
||||||
ActivityType.Create -> apCreateService.receiveCreate(objectMapper.readValue(json))
|
ActivityType.Create -> apCreateService.receiveCreate(objectMapper.readValue(json))
|
||||||
ActivityType.Like -> apLikeService.receiveLike(objectMapper.readValue(json))
|
ActivityType.Like -> apLikeService.receiveLike(objectMapper.readValue(json))
|
||||||
ActivityType.Undo -> apUndoService.receiveUndo(objectMapper.readValue(json))
|
ActivityType.Undo -> apUndoService.receiveUndo(objectMapper.readValue(json))
|
||||||
|
ActivityType.Delete -> apReceiveDeleteService.receiveDelete(objectMapper.readValue(json))
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
throw IllegalArgumentException("$type is not supported.")
|
throw IllegalArgumentException("$type is not supported.")
|
||||||
|
|
Loading…
Reference in New Issue