diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt index e2d124ad..a1b896b8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/job/HideoutJob.kt @@ -15,3 +15,10 @@ object DeliverPostJob : HideoutJob("DeliverPostJob") { val actor = string("actor") val inbox = string("inbox") } + +object DeliverReactionJob : HideoutJob("DeliverReactionJob") { + val reaction = string("reaction") + val postUrl = string("postUrl") + val actor = string("actor") + val inbox = string("inbox") +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt new file mode 100644 index 00000000..106e552d --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.service.activitypub + +import dev.usbharu.hideout.domain.model.hideout.entity.Reaction +import dev.usbharu.hideout.domain.model.job.DeliverReactionJob +import kjob.core.job.JobProps + +interface ActivityPubReactionService { + suspend fun reaction(like: Reaction) + suspend fun reactionJob(props: JobProps) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/reaction/IReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/service/reaction/IReactionService.kt index 13c52f88..86a9409e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/reaction/IReactionService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/reaction/IReactionService.kt @@ -2,4 +2,5 @@ package dev.usbharu.hideout.service.reaction interface IReactionService { suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) + suspend fun sendReaction(name: String, userId: Long, postId: Long) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt index cbf24753..0c8daadf 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/reaction/ReactionServiceImpl.kt @@ -2,10 +2,14 @@ package dev.usbharu.hideout.service.reaction import dev.usbharu.hideout.domain.model.hideout.entity.Reaction import dev.usbharu.hideout.repository.ReactionRepository +import dev.usbharu.hideout.service.activitypub.ActivityPubReactionService import org.koin.core.annotation.Single @Single -class ReactionServiceImpl(private val reactionRepository: ReactionRepository) : IReactionService { +class ReactionServiceImpl( + private val reactionRepository: ReactionRepository, + private val activityPubReactionService: ActivityPubReactionService +) : IReactionService { override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) { if (reactionRepository.reactionAlreadyExist(postId, userId, 0).not()) { reactionRepository.save( @@ -13,4 +17,14 @@ class ReactionServiceImpl(private val reactionRepository: ReactionRepository) : ) } } + + override suspend fun sendReaction(name: String, userId: Long, postId: Long) { + if (reactionRepository.reactionAlreadyExist(postId, userId, 0)) { + //delete + } else { + val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId) + reactionRepository.save(reaction) + activityPubReactionService.reaction(reaction) + } + } }