diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 888c31f7..77388337 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -1,9 +1,6 @@ package dev.usbharu.hideout.activitypub.service.activity.undo -import dev.usbharu.hideout.activitypub.domain.model.Accept -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.* import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectValue import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor 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.application.external.Transaction 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 org.springframework.stereotype.Service @@ -19,7 +18,9 @@ class APUndoProcessor( transaction: Transaction, private val apUserService: APUserService, private val actorQueryService: ActorQueryService, - private val relationshipService: RelationshipService + private val relationshipService: RelationshipService, + private val postQueryService: PostQueryService, + private val reactionService: ReactionService ) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { @@ -68,6 +69,18 @@ class APUndoProcessor( val target = actorQueryService.findByUrl(acceptObject) 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 -> {} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ReactionQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ReactionQueryServiceImpl.kt index b7bd1642..8e51e2e6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ReactionQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ReactionQueryServiceImpl.kt @@ -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.query.ReactionQueryService import dev.usbharu.hideout.util.singleOr -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.select import org.springframework.stereotype.Repository @@ -45,7 +43,8 @@ class ReactionQueryServiceImpl : ReactionQueryService { }.empty().not() } - override suspend fun deleteByPostIdAndActorId(postId: Long, actorId: Long) { - Reactions.deleteWhere { Reactions.postId.eq(postId).and(Reactions.actorId.eq(actorId)) } + override suspend fun findByPostIdAndActorId(postId: Long, actorId: Long): List { + return Reactions.select { Reactions.postId eq postId and (Reactions.actorId eq actorId) } + .map { it.toReaction() } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt index a94abda4..e2b8cef7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt @@ -37,7 +37,7 @@ class ReactionRepositoryImpl( Reactions.deleteWhere { id.eq(reaction.id) .and(postId.eq(reaction.postId)) - .and(actorId.eq(reaction.postId)) + .and(actorId.eq(reaction.actorId)) .and(emojiId.eq(reaction.emojiId)) } return reaction diff --git a/src/main/kotlin/dev/usbharu/hideout/core/query/ReactionQueryService.kt b/src/main/kotlin/dev/usbharu/hideout/core/query/ReactionQueryService.kt index 602e0a76..ece7b040 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/query/ReactionQueryService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/query/ReactionQueryService.kt @@ -12,5 +12,5 @@ interface ReactionQueryService { 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 } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt index 333deb1d..38121bb6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionService.kt @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service @Service interface ReactionService { 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 removeReaction(actorId: Long, postId: Long) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index 1e9be539..0323dc97 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -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) { try { val findByPostIdAndUserIdAndEmojiId =