From 0a33f19e2f324d9c2d3a510ca36ee1e489dc93d0 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 31 Jul 2023 00:32:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AA=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E6=83=85=E5=A0=B1=E3=82=92=E9=85=8D=E9=80=81?= =?UTF-8?q?=E3=81=99=E3=82=8Binterface=E3=82=92=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/domain/model/job/HideoutJob.kt | 7 +++++++ .../activitypub/ActivityPubReactionService.kt | 10 ++++++++++ .../hideout/service/reaction/IReactionService.kt | 1 + .../service/reaction/ReactionServiceImpl.kt | 16 +++++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReactionService.kt 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) + } + } }