mirror of https://github.com/usbharu/Hideout.git
feat: アカウント削除アクティビティに対応
This commit is contained in:
parent
511288f4bb
commit
c98a90e2fc
|
@ -3,37 +3,54 @@ package dev.usbharu.hideout.activitypub.service.activity.delete
|
||||||
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
|
import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Delete
|
import dev.usbharu.hideout.activitypub.domain.model.Delete
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.HasId
|
import dev.usbharu.hideout.activitypub.domain.model.HasId
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectValue
|
||||||
import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor
|
import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||||
|
import dev.usbharu.hideout.core.query.ActorQueryService
|
||||||
import dev.usbharu.hideout.core.query.PostQueryService
|
import dev.usbharu.hideout.core.query.PostQueryService
|
||||||
import dev.usbharu.hideout.core.service.post.PostService
|
import dev.usbharu.hideout.core.service.post.PostService
|
||||||
|
import dev.usbharu.hideout.core.service.user.UserService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class APDeleteProcessor(
|
class APDeleteProcessor(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
private val postQueryService: PostQueryService,
|
private val postQueryService: PostQueryService,
|
||||||
|
private val actorQueryService: ActorQueryService,
|
||||||
|
private val userService: UserService,
|
||||||
private val postService: PostService
|
private val postService: PostService
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Delete>(transaction) {
|
AbstractActivityPubProcessor<Delete>(transaction) {
|
||||||
override suspend fun internalProcess(activity: ActivityPubProcessContext<Delete>) {
|
override suspend fun internalProcess(activity: ActivityPubProcessContext<Delete>) {
|
||||||
val value = activity.activity.apObject
|
val value = activity.activity.apObject
|
||||||
if (value !is HasId) {
|
val deleteId = if (value is HasId) {
|
||||||
throw IllegalActivityPubObjectException("object hasn't id")
|
value.id
|
||||||
|
} else if (value is ObjectValue) {
|
||||||
|
value.`object`
|
||||||
|
} else {
|
||||||
|
throw IllegalActivityPubObjectException("object hasn't id or object")
|
||||||
}
|
}
|
||||||
val deleteId = value.id
|
|
||||||
|
|
||||||
val post = try {
|
|
||||||
postQueryService.findByApId(deleteId)
|
try {
|
||||||
|
val actor = actorQueryService.findByUrl(deleteId)
|
||||||
|
userService.deleteRemoteActor(actor.id)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("FAILED delete id: {} is not found.", deleteId, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val post = postQueryService.findByApId(deleteId)
|
||||||
|
postService.deleteRemote(post)
|
||||||
} catch (e: FailedToGetResourcesException) {
|
} catch (e: FailedToGetResourcesException) {
|
||||||
logger.warn("FAILED delete id: {} is not found.", deleteId, e)
|
logger.warn("FAILED delete id: {} is not found.", deleteId, e)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
postService.deleteRemote(post)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Delete
|
override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Delete
|
||||||
|
|
Loading…
Reference in New Issue