mirror of https://github.com/usbharu/Hideout.git
Merge pull request #210 from usbharu/feature/remove-reaction
feat: リアクションの削除に対応
This commit is contained in:
commit
8d1f339a5d
|
@ -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<Undo>(transaction) {
|
||||
override suspend fun internalProcess(activity: ActivityPubProcessContext<Undo>) {
|
||||
|
@ -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 -> {}
|
||||
|
|
|
@ -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<Reaction> {
|
||||
return Reactions.select { Reactions.postId eq postId and (Reactions.actorId eq actorId) }
|
||||
.map { it.toReaction() }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Reaction>
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in New Issue