From 5f79f06831399f103b5727dfba590f63d9e9085a Mon Sep 17 00:00:00 2001 From: usbharu Date: Thu, 7 Dec 2023 14:30:35 +0900 Subject: [PATCH] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../hideout/activitypub/domain/model/Image.kt | 10 ++-- .../service/inbox/InboxJobProcessor.kt | 2 - .../HttpSignatureUserDetailsService.kt | 1 - .../service/account/AccountApiService.kt | 50 +++++++++---------- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt index c3e4649a..8f77d4ae 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Image.kt @@ -31,11 +31,9 @@ open class Image( override fun toString(): String { return "Image(" + - "mediaType=$mediaType, " + - "url='$url'" + - ")" + - " ${super.toString()}" + "mediaType=$mediaType, " + + "url='$url'" + + ")" + + " ${super.toString()}" } - - } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt index 9ca3e982..301ac7ce 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt @@ -99,7 +99,6 @@ class InboxJobProcessor( val verify = signature?.let { verifyHttpSignature(httpRequest, it, transaction) } ?: false - logger.debug("Is verifying success? {}", verify) val activityPubProcessor = @@ -114,7 +113,6 @@ class InboxJobProcessor( activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify)) logger.info("SUCCESS Process inbox. type: {}", param.type) - } override fun job(): InboxJob = InboxJob diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt index 9ef79982..a75fe934 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/httpsignature/HttpSignatureUserDetailsService.kt @@ -37,7 +37,6 @@ class HttpSignatureUserDetailsService( try { userQueryService.findByKeyId(keyId) } catch (e: FailedToGetResourcesException) { - throw UsernameNotFoundException("User not found", e) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt index 946a6710..a3315107 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt @@ -92,10 +92,8 @@ class AccountApiServiceImpl( } override suspend fun follow(userid: Long, followeeId: Long): Relationship = transaction.transaction { - val alreadyFollow = followerQueryService.alreadyFollow(followeeId, userid) - val followRequest = if (alreadyFollow) { true } else { @@ -129,40 +127,38 @@ class AccountApiServiceImpl( override suspend fun relationships(userid: Long, id: List, withSuspended: Boolean): List = transaction.transaction { - if (id.isEmpty()) { - return@transaction emptyList() - } + if (id.isEmpty()) { + return@transaction emptyList() + } - - logger.warn("id is too long! ({}) truncate to 20", id.size) + logger.warn("id is too long! ({}) truncate to 20", id.size) val subList = id.subList(0, min(id.size, 20)) return@transaction subList.map { + val alreadyFollow = followerQueryService.alreadyFollow(userid, it) - val alreadyFollow = followerQueryService.alreadyFollow(userid, it) + val followed = followerQueryService.alreadyFollow(it, userid) - val followed = followerQueryService.alreadyFollow(it, userid) + val requested = userRepository.findFollowRequestsById(it, userid) - val requested = userRepository.findFollowRequestsById(it, userid) - - Relationship( - id = it.toString(), - following = alreadyFollow, - showingReblogs = true, - notifying = false, - followedBy = followed, - blocking = false, - blockedBy = false, - muting = false, - mutingNotifications = false, - requested = requested, - domainBlocking = false, - endorsed = false, - note = "" - ) + Relationship( + id = it.toString(), + following = alreadyFollow, + showingReblogs = true, + notifying = false, + followedBy = followed, + blocking = false, + blockedBy = false, + muting = false, + mutingNotifications = false, + requested = requested, + domainBlocking = false, + endorsed = false, + note = "" + ) + } } - } private fun from(account: Account): CredentialAccount { return CredentialAccount(