From 9d0ed309d0f329fa6fc3e04e199d7d52b9e9b290 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:32:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=A8=E3=81=AE=E4=B8=8D=E6=95=B4=E5=90=88=E3=81=AE=E8=A7=A3?= =?UTF-8?q?=E6=B1=BA=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../relationship/RelationshipService.kt | 2 +- .../relationship/RelationshipServiceImpl.kt | 30 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c8d31ca7..9c892615 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -287,7 +287,7 @@ project.gradle.taskGraph.whenReady { kover { excludeSourceSets { - names("aot") + names("aot", "e2eTest", "intTest") } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipService.kt index 4f0a164a..663ec70a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipService.kt @@ -3,7 +3,7 @@ package dev.usbharu.hideout.core.service.relationship interface RelationshipService { suspend fun followRequest(userId: Long, targetId: Long) suspend fun block(userId: Long, targetId: Long) - suspend fun acceptFollowRequest(userId: Long, targetId: Long) + suspend fun acceptFollowRequest(userId: Long, targetId: Long, force: Boolean = false) suspend fun rejectFollowRequest(userId: Long, targetId: Long) suspend fun ignoreFollowRequest(userId: Long, targetId: Long) suspend fun unfollow(userId: Long, targetId: Long) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt index 1ee53312..9e3b98ce 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt @@ -63,6 +63,11 @@ class RelationshipServiceImpl( return } + if (relationship.following) { + logger.debug("SUCCESS User already follow. userId: {} targetId: {}", userId, targetId) + acceptFollowRequest(userId, targetId, true) + return + } relationshipRepository.save(relationship) @@ -100,15 +105,25 @@ class RelationshipServiceImpl( } } - override suspend fun acceptFollowRequest(userId: Long, targetId: Long) { + override suspend fun acceptFollowRequest(userId: Long, targetId: Long, force: Boolean) { val relationship = relationshipRepository.findByUserIdAndTargetUserId(userId, targetId) + val inverseRelationship = relationshipRepository.findByUserIdAndTargetUserId(targetId, userId) ?: Relationship( + userId = targetId, + targetUserId = userId, + following = false, + blocking = false, + muting = false, + followRequest = false, + ignoreFollowRequestFromTarget = false + ) + if (relationship == null) { logger.warn("FAILED Follow Request Not Found. (Relationship) userId: {} targetId: {}", userId, targetId) return } - if (relationship.followRequest.not()) { + if (relationship.followRequest.not() && force.not()) { logger.warn("FAILED Follow Request Not Found. (Follow Request) userId: {} targetId: {}", userId, targetId) return } @@ -118,6 +133,11 @@ class RelationshipServiceImpl( throw IllegalStateException("Cannot accept a follow request from a blocked user. userId: $userId targetId: $targetId") } + if (inverseRelationship.blocking) { + logger.warn("FAILED BLocked by user userId: {} targetId: {}", userId, targetId) + throw IllegalStateException("Cannot accept a follow request from a blocking user. userId: $userId targetId: $targetId") + } + val copy = relationship.copy(followRequest = false, following = true, blocking = false) relationshipRepository.save(copy) @@ -143,7 +163,7 @@ class RelationshipServiceImpl( return } - val copy = relationship.copy(followRequest = false, following = false, blocking = false) + val copy = relationship.copy(followRequest = false, following = false) relationshipRepository.save(copy) @@ -214,9 +234,9 @@ class RelationshipServiceImpl( val remoteUser = isRemoteUser(targetId) - if (remoteUser == null) { + if (remoteUser != null) { val user = userQueryService.findById(userId) - apSendUndoService.sendUndoBlock(user, targetId) + apSendUndoService.sendUndoBlock(user, remoteUser) } }