From 3b4a6a04e005282d93cdb1013ce2b0e2e06f301e Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 13 Dec 2023 10:54:45 +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=E3=81=AE=E5=89=8A=E9=99=A4=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/activity/undo/APUndoProcessor.kt | 23 +++++++++++++++---- .../exposedquery/ReactionQueryServiceImpl.kt | 8 +++---- .../ReactionRepositoryImpl.kt | 2 +- .../core/query/ReactionQueryService.kt | 2 +- .../core/service/reaction/ReactionService.kt | 1 + .../service/reaction/ReactionServiceImpl.kt | 5 ++++ 6 files changed, 30 insertions(+), 11 deletions(-) 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..86f695cb 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,9 @@ 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 =