feat: リアクション情報を配送するinterfaceを定義

This commit is contained in:
usbharu 2023-07-31 00:32:15 +09:00
parent 20fbcbf72e
commit 88f8b405e3
4 changed files with 33 additions and 1 deletions

View File

@ -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")
}

View File

@ -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<DeliverReactionJob>)
}

View File

@ -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)
}

View File

@ -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)
}
}
}