diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APAcceptService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APAcceptService.kt deleted file mode 100644 index b702a791..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/accept/APAcceptService.kt +++ /dev/null @@ -1,55 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.accept - -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException -import dev.usbharu.hideout.activitypub.domain.model.Accept -import dev.usbharu.hideout.activitypub.domain.model.Follow -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.query.FollowerQueryService -import dev.usbharu.hideout.core.query.UserQueryService -import dev.usbharu.hideout.core.service.user.UserService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -@Deprecated("use activitypub processor") -interface APAcceptService { - suspend fun receiveAccept(accept: Accept) -} - -@Service -class APAcceptServiceImpl( - private val userService: UserService, - private val userQueryService: UserQueryService, - private val followerQueryService: FollowerQueryService, - private val transaction: Transaction -) : APAcceptService { - override suspend fun receiveAccept(accept: Accept) { - return transaction.transaction { - LOGGER.debug("START Follow") - LOGGER.trace("{}", accept) - val value = accept.`object` ?: throw IllegalActivityPubObjectException("object is null") - if (value.type.contains("Follow").not()) { - LOGGER.warn("FAILED Activity type is not 'Follow'") - throw IllegalActivityPubObjectException("Invalid type ${value.type}") - } - - val follow = value as Follow - val userUrl = follow.`object` ?: throw IllegalActivityPubObjectException("object is null") - val followerUrl = follow.actor ?: throw IllegalActivityPubObjectException("actor is null") - - val user = userQueryService.findByUrl(userUrl) - val follower = userQueryService.findByUrl(followerUrl) - - if (followerQueryService.alreadyFollow(user.id, follower.id)) { - LOGGER.debug("END User already follow from ${follower.url} to ${user.url}") - return@transaction - } - userService.follow(user.id, follower.id) - LOGGER.debug("SUCCESS Follow from ${follower.url} to ${user.url}.") - - } - } - - companion object { - private val LOGGER = LoggerFactory.getLogger(APAcceptServiceImpl::class.java) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/APCreateService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/APCreateService.kt deleted file mode 100644 index afcf4881..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/create/APCreateService.kt +++ /dev/null @@ -1,40 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.create - -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException -import dev.usbharu.hideout.activitypub.domain.model.Create -import dev.usbharu.hideout.activitypub.domain.model.Note -import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService -import dev.usbharu.hideout.application.external.Transaction -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -interface APCreateService { - suspend fun receiveCreate(create: Create) -} - -@Service -class APCreateServiceImpl( - private val apNoteService: APNoteService, - private val transaction: Transaction -) : APCreateService { - override suspend fun receiveCreate(create: Create) { - LOGGER.debug("START Create new remote note.") - LOGGER.trace("{}", create) - - val value = create.`object` ?: throw IllegalActivityPubObjectException("object is null") - if (value.type.contains("Note").not()) { - LOGGER.warn("FAILED Object type is not 'Note'") - throw IllegalActivityPubObjectException("object is not Note") - } - - return transaction.transaction { - val note = value as Note - apNoteService.fetchNote(note) - LOGGER.debug("SUCCESS Create new remote note. ${note.id} by ${note.attributedTo}") - } - } - - companion object { - private val LOGGER = LoggerFactory.getLogger(APCreateServiceImpl::class.java) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteService.kt deleted file mode 100644 index 68505f22..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteService.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.delete - -import dev.usbharu.hideout.activitypub.domain.model.Delete - -interface APReceiveDeleteService { - suspend fun receiveDelete(delete: Delete) -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteServiceImpl.kt deleted file mode 100644 index e75fa90c..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APReceiveDeleteServiceImpl.kt +++ /dev/null @@ -1,28 +0,0 @@ -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.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 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) = transaction.transaction { - val deleteId = delete.`object`?.id ?: throw IllegalActivityPubObjectException("object.id is null") - - val post = try { - postQueryService.findByApId(deleteId) - } catch (_: FailedToGetResourcesException) { - return@transaction - } - postRepository.delete(post.id) - return@transaction - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeService.kt deleted file mode 100644 index 5b59550e..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeService.kt +++ /dev/null @@ -1,63 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.like - -import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException -import dev.usbharu.hideout.activitypub.domain.exception.IllegalActivityPubObjectException -import dev.usbharu.hideout.activitypub.domain.model.Like -import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService -import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.query.PostQueryService -import dev.usbharu.hideout.core.service.reaction.ReactionService -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Service - -interface APLikeService { - suspend fun receiveLike(like: Like) -} - -@Service -class APLikeServiceImpl( - private val reactionService: ReactionService, - private val apUserService: APUserService, - private val apNoteService: APNoteService, - private val postQueryService: PostQueryService, - private val transaction: Transaction -) : APLikeService { - override suspend fun receiveLike(like: Like) { - LOGGER.debug("START Add Like") - LOGGER.trace("{}", like) - - val actor = like.actor ?: throw IllegalActivityPubObjectException("actor is null") - val content = like.content ?: throw IllegalActivityPubObjectException("content is null") - like.`object` ?: throw IllegalActivityPubObjectException("object is null") - transaction.transaction { - LOGGER.trace("FETCH Liked Person $actor") - val person = apUserService.fetchPersonWithEntity(actor) - LOGGER.trace("{}", person.second) - - LOGGER.trace("FETCH Liked Note ${like.`object`}") - try { - apNoteService.fetchNoteAsync(like.`object` ?: return@transaction).await() - } catch (e: FailedToGetActivityPubResourceException) { - LOGGER.debug("FAILED Failed to Get ${like.`object`}") - LOGGER.trace("", e) - return@transaction - } - val post = postQueryService.findByUrl(like.`object` ?: return@transaction) - LOGGER.trace("{}", post) - - reactionService.receiveReaction( - content, - actor.substringAfter("://").substringBefore("/"), - person.second.id, - post.id - ) - LOGGER.debug("SUCCESS Add Like($content) from ${person.second.url} to ${post.url}") - } - return - } - - companion object { - private val LOGGER = LoggerFactory.getLogger(APLikeServiceImpl::class.java) - } -} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoService.kt deleted file mode 100644 index e0348b6c..00000000 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoService.kt +++ /dev/null @@ -1,53 +0,0 @@ -package dev.usbharu.hideout.activitypub.service.activity.undo - -import dev.usbharu.hideout.activitypub.domain.model.Follow -import dev.usbharu.hideout.activitypub.domain.model.Undo -import dev.usbharu.hideout.activitypub.service.objects.user.APUserService -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.query.UserQueryService -import dev.usbharu.hideout.core.service.user.UserService -import org.springframework.stereotype.Service - -interface APUndoService { - suspend fun receiveUndo(undo: Undo) -} - -@Service -@Suppress("UnsafeCallOnNullableType") -class APUndoServiceImpl( - private val userService: UserService, - private val apUserService: APUserService, - private val userQueryService: UserQueryService, - private val transaction: Transaction -) : APUndoService { - override suspend fun receiveUndo(undo: Undo) { - if (undo.actor == null) { - return - } - - val type = - undo.`object`?.type.orEmpty() - .firstOrNull { it == "Block" || it == "Follow" || it == "Like" || it == "Announce" || it == "Accept" } - ?: return - - when (type) { - "Follow" -> { - val follow = undo.`object` as Follow - - if (follow.`object` == null) { - return - } - transaction.transaction { - apUserService.fetchPerson(undo.actor!!, follow.`object`) - val follower = userQueryService.findByUrl(undo.actor!!) - val target = userQueryService.findByUrl(follow.`object`!!) - userService.unfollow(target.id, follower.id) - } - return - } - - else -> {} - } - TODO() - } -}