Merge pull request #210 from usbharu/feature/remove-reaction

feat: リアクションの削除に対応
This commit is contained in:
usbharu 2023-12-13 11:07:11 +09:00 committed by GitHub
commit 8d1f339a5d
6 changed files with 29 additions and 11 deletions

View File

@ -1,9 +1,6 @@
package dev.usbharu.hideout.activitypub.service.activity.undo package dev.usbharu.hideout.activitypub.service.activity.undo
import dev.usbharu.hideout.activitypub.domain.model.Accept import dev.usbharu.hideout.activitypub.domain.model.*
import dev.usbharu.hideout.activitypub.domain.model.Block
import dev.usbharu.hideout.activitypub.domain.model.Follow
import dev.usbharu.hideout.activitypub.domain.model.Undo
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectValue 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
@ -11,6 +8,8 @@ import dev.usbharu.hideout.activitypub.service.common.ActivityType
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.application.external.Transaction
import dev.usbharu.hideout.core.query.ActorQueryService import dev.usbharu.hideout.core.query.ActorQueryService
import dev.usbharu.hideout.core.query.PostQueryService
import dev.usbharu.hideout.core.service.reaction.ReactionService
import dev.usbharu.hideout.core.service.relationship.RelationshipService import dev.usbharu.hideout.core.service.relationship.RelationshipService
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -19,7 +18,9 @@ class APUndoProcessor(
transaction: Transaction, transaction: Transaction,
private val apUserService: APUserService, private val apUserService: APUserService,
private val actorQueryService: ActorQueryService, private val actorQueryService: ActorQueryService,
private val relationshipService: RelationshipService private val relationshipService: RelationshipService,
private val postQueryService: PostQueryService,
private val reactionService: ReactionService
) : ) :
AbstractActivityPubProcessor<Undo>(transaction) { AbstractActivityPubProcessor<Undo>(transaction) {
override suspend fun internalProcess(activity: ActivityPubProcessContext<Undo>) { override suspend fun internalProcess(activity: ActivityPubProcessContext<Undo>) {
@ -68,6 +69,18 @@ class APUndoProcessor(
val target = actorQueryService.findByUrl(acceptObject) val target = actorQueryService.findByUrl(acceptObject)
relationshipService.rejectFollowRequest(accepter.id, target.id) relationshipService.rejectFollowRequest(accepter.id, target.id)
return
}
"Like" -> {
val like = undo.apObject as Like
val post = postQueryService.findByUrl(like.apObject)
val actor = actorQueryService.findByUrl(like.actor)
reactionService.receiveRemoveReaction(actor.id, post.id)
return
} }
else -> {} else -> {}

View File

@ -6,9 +6,7 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Reactions
import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction import dev.usbharu.hideout.core.infrastructure.exposedrepository.toReaction
import dev.usbharu.hideout.core.query.ReactionQueryService import dev.usbharu.hideout.core.query.ReactionQueryService
import dev.usbharu.hideout.util.singleOr import dev.usbharu.hideout.util.singleOr
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
@ -45,7 +43,8 @@ class ReactionQueryServiceImpl : ReactionQueryService {
}.empty().not() }.empty().not()
} }
override suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long) { override suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List<Reaction> {
Reactions.deleteWhere { Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)) } return Reactions.select { Reactions.postId eq postId and (Reactions.actorId eq actorId) }
.map { it.toReaction() }
} }
} }

View File

@ -37,7 +37,7 @@ class ReactionRepositoryImpl(
Reactions.deleteWhere { Reactions.deleteWhere {
id.eq(reaction.id) id.eq(reaction.id)
.and(postId.eq(reaction.postId)) .and(postId.eq(reaction.postId))
.and(actorId.eq(reaction.postId)) .and(actorId.eq(reaction.actorId))
.and(emojiId.eq(reaction.emojiId)) .and(emojiId.eq(reaction.emojiId))
} }
return reaction return reaction

View File

@ -12,5 +12,5 @@ interface ReactionQueryService {
suspend fun reactionAlreadyExist(postId: Long, actorId: Long, emojiId: Long): Boolean suspend fun reactionAlreadyExist(postId: Long, actorId: Long, emojiId: Long): Boolean
suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long) suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List<Reaction>
} }

View File

@ -5,6 +5,7 @@ import org.springframework.stereotype.Service
@Service @Service
interface ReactionService { interface ReactionService {
suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long) suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long)
suspend fun receiveRemoveReaction(actorId: Long, postId: Long)
suspend fun sendReaction(name: String, actorId: Long, postId: Long) suspend fun sendReaction(name: String, actorId: Long, postId: Long)
suspend fun removeReaction(actorId: Long, postId: Long) suspend fun removeReaction(actorId: Long, postId: Long)
} }

View File

@ -27,6 +27,11 @@ class ReactionServiceImpl(
} }
} }
override suspend fun receiveRemoveReaction(actorId: Long, postId: Long) {
val reaction = reactionQueryService.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
reactionRepository.delete(reaction)
}
override suspend fun sendReaction(name: String, actorId: Long, postId: Long) { override suspend fun sendReaction(name: String, actorId: Long, postId: Long) {
try { try {
val findByPostIdAndUserIdAndEmojiId = val findByPostIdAndUserIdAndEmojiId =