From fd0d6b9625a5807f7a55a08075045ff8d558548f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:39:27 +0900 Subject: [PATCH] style: fix lint --- .../application/actor/SuspendLocalActor.kt | 3 + .../SuspendLocalActorApplicationService.kt | 23 ++++-- .../application/actor/UnsuspendLocalActor.kt | 3 + .../UnsuspendLocalActorApplicationService.kt | 22 +++-- ...isterLocalUserSetHomeTimelineSubscriber.kt | 2 - .../TimelinePostCreateSubscriber.kt | 5 -- .../TimelineRelationshipFollowSubscriber.kt | 6 +- .../GetLocalInstanceApplicationService.kt | 2 + .../core/application/post/ActorDetail.kt | 16 ++-- .../post/DeleteLocalPostApplicationService.kt | 7 +- .../post/GetPostDetailApplicationService.kt | 14 ++-- .../core/application/post/PostDetail.kt | 1 + ...erRejectFollowRequestApplicationService.kt | 2 +- .../unmute/UserUnmuteApplicationService.kt | 8 +- .../shared/AbstractApplicationService.kt | 2 +- .../ReadTimelineApplicationService.kt | 14 ++-- .../core/domain/event/post/PostEvent.kt | 2 +- .../event/relationship/RelationshipEvent.kt | 4 +- .../domain/event/timeline/TimelineEvent.kt | 4 +- .../event/userdetail/UserDetailEvent.kt | 4 +- .../core/domain/model/filter/Filter.kt | 4 +- .../hideout/core/domain/model/media/Media.kt | 13 +++ .../hideout/core/domain/model/post/Post.kt | 2 +- .../core/domain/model/post/PostRepository.kt | 2 + .../relationship/RelationshipRepository.kt | 1 + .../core/domain/model/support/acct/Acct.kt | 4 +- .../TimelineObjectDetail.kt | 1 + .../core/domain/model/timeline/Timeline.kt | 6 +- .../model/timelineobject/TimelineObject.kt | 7 +- .../domain/model/userdetails/UserDetail.kt | 1 + .../ExposedPrincipalQueryService.kt | 6 +- .../ExposedPostRepository.kt | 4 +- .../ExposedTimelineRepository.kt | 6 +- .../UserDetailRepositoryImpl.kt | 12 +-- .../media/image/ImageIOImageProcessor.kt | 3 +- .../MongoInternalTimelineObjectRepository.kt | 80 +++++++++---------- .../SpringFrameworkDomainEventSubscriber.kt | 2 +- .../timeline/AbstractTimelineStore.kt | 49 +++++++----- .../timeline/DefaultTimelineStore.kt | 50 +++++------- .../interfaces/web/posts/PublishController.kt | 2 + .../web/timeline/TimelineController.kt | 3 +- .../core/domain/model/post/PostTest.kt | 4 +- 42 files changed, 223 insertions(+), 183 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActor.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActor.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActor.kt new file mode 100644 index 00000000..a566ce97 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActor.kt @@ -0,0 +1,3 @@ +package dev.usbharu.hideout.core.application.actor + +data class SuspendLocalActor(val actorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt index 809b3a36..eaeba5e7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/SuspendLocalActorApplicationService.kt @@ -16,22 +16,29 @@ package dev.usbharu.hideout.core.application.actor +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @Service class SuspendLocalActorApplicationService( - private val transaction: Transaction, + transaction: Transaction, private val actorRepository: ActorRepository, -) { - suspend fun suspend(actorId: Long, executor: ActorId) { - transaction.transaction { - val id = ActorId(actorId) +) : LocalUserAbstractApplicationService(transaction, logger) { - val actor = actorRepository.findById(id)!! - actor.suspend = true - } + override suspend fun internalExecute(command: SuspendLocalActor, principal: LocalUser) { + val id = ActorId(command.actorId) + val actor = + actorRepository.findById(id) ?: throw IllegalArgumentException("Actor ${command.actorId} not found.") + actor.suspend = true + actorRepository.save(actor) + } + + companion object { + private val logger = LoggerFactory.getLogger(SuspendLocalActorApplicationService::class.java) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActor.kt new file mode 100644 index 00000000..a8107458 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActor.kt @@ -0,0 +1,3 @@ +package dev.usbharu.hideout.core.application.actor + +data class UnsuspendLocalActor(val actorId: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt index baf0ab4b..019753e8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/UnsuspendLocalActorApplicationService.kt @@ -16,21 +16,29 @@ package dev.usbharu.hideout.core.application.actor +import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorRepository +import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @Service class UnsuspendLocalActorApplicationService( - private val transaction: Transaction, + transaction: Transaction, private val actorRepository: ActorRepository, -) { - suspend fun unsuspend(actorId: Long, executor: Long) { - transaction.transaction { - val findById = actorRepository.findById(ActorId(actorId))!! +) : LocalUserAbstractApplicationService(transaction, logger) { - findById.suspend = false - } + override suspend fun internalExecute(command: UnsuspendLocalActor, principal: LocalUser) { + val findById = actorRepository.findById(ActorId(command.actorId)) + ?: throw IllegalArgumentException("Actor ${command.actorId} not found.") + + findById.suspend = false + actorRepository.save(findById) + } + + companion object { + private val logger = LoggerFactory.getLogger(UnsuspendLocalActorApplicationService::class.java) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/RegisterLocalUserSetHomeTimelineSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/RegisterLocalUserSetHomeTimelineSubscriber.kt index 868ec419..48620f34 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/RegisterLocalUserSetHomeTimelineSubscriber.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/RegisterLocalUserSetHomeTimelineSubscriber.kt @@ -20,5 +20,3 @@ class RegisterLocalUserSetHomeTimelineSubscriber( } } } - -// todo userdetailにdomain event付けて createのイベントで反応させる タイムラインを新しく一つ作って userdetailのhometimelineに紐づけて自分自身をtimleine relationshipに入れる diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt index dfcc87ad..4f407e99 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelinePostCreateSubscriber.kt @@ -5,7 +5,6 @@ import dev.usbharu.hideout.core.application.timeline.TimelineAddPostApplicationS import dev.usbharu.hideout.core.domain.event.post.PostEvent import dev.usbharu.hideout.core.domain.event.post.PostEventBody import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous -import org.slf4j.LoggerFactory import org.springframework.stereotype.Component @Component @@ -18,8 +17,4 @@ class TimelinePostCreateSubscriber( timelineAddPostApplicationService.execute(AddPost(it.body.getPostId()), Anonymous) } } - - companion object { - private val logger = LoggerFactory.getLogger(TimelinePostCreateSubscriber::class.java) - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelineRelationshipFollowSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelineRelationshipFollowSubscriber.kt index bc13d823..4a3e03e8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelineRelationshipFollowSubscriber.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/domainevent/subscribers/TimelineRelationshipFollowSubscriber.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.application.domainevent.subscribers +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.timeline.AddTimelineRelationship import dev.usbharu.hideout.core.application.timeline.UserAddTimelineRelationshipApplicationService import dev.usbharu.hideout.core.domain.event.relationship.RelationshipEvent @@ -23,11 +24,14 @@ class TimelineRelationshipFollowSubscriber( init { domainEventSubscriber.subscribe(RelationshipEvent.FOLLOW.eventName) { val relationship = it.body.getRelationship() - val userDetail = userDetailRepository.findByActorId(relationship.actorId.id) ?: throw Exception() + val userDetail = userDetailRepository.findByActorId(relationship.actorId.id) + ?: throw InternalServerException("Userdetail ${relationship.actorId} not found by actorid.") if (userDetail.homeTimelineId == null) { logger.warn("Home timeline for ${relationship.actorId} is not found") return@subscribe } + + @Suppress("UnsafeCallOnNullableType") userAddTimelineRelationshipApplicationService.execute( AddTimelineRelationship( TimelineRelationship( diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt index 72c3d5bf..b96b7e06 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/instance/GetLocalInstanceApplicationService.kt @@ -23,6 +23,7 @@ class GetLocalInstanceApplicationService( override suspend fun internalExecute(command: Unit, principal: Principal): Instance { if (cachedInstance != null) { + @Suppress("UnsafeCallOnNullableType") return cachedInstance!! } @@ -32,6 +33,7 @@ class GetLocalInstanceApplicationService( ) cachedInstance = Instance.of(instance) + @Suppress("UnsafeCallOnNullableType") return cachedInstance!! } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt index dab9ccce..7ef57687 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/ActorDetail.kt @@ -17,14 +17,14 @@ data class ActorDetail( companion object { fun of(actor: Actor, iconMedia: Media?): ActorDetail { return ActorDetail( - actor.id.id, - actor.instance.instanceId, - actor.name.name, - actor.domain.domain, - actor.screenName.screenName, - actor.url, - actor.locked, - iconMedia?.url + actorId = actor.id.id, + instanceId = actor.instance.instanceId, + name = actor.name.name, + domain = actor.domain.domain, + screenName = actor.screenName.screenName, + url = actor.url, + locked = actor.locked, + icon = iconMedia?.url ) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt index 1de7fe31..48441863 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/DeleteLocalPostApplicationService.kt @@ -16,6 +16,7 @@ package dev.usbharu.hideout.core.application.post +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.application.exception.PermissionDeniedException import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService import dev.usbharu.hideout.core.application.shared.Transaction @@ -34,11 +35,13 @@ class DeleteLocalPostApplicationService( ) : LocalUserAbstractApplicationService(transaction, logger) { override suspend fun internalExecute(command: DeleteLocalPost, principal: LocalUser) { - val findById = postRepository.findById(PostId(command.postId))!! + val findById = postRepository.findById(PostId(command.postId)) + ?: throw IllegalArgumentException("Post ${command.postId} not found.") if (findById.actorId != principal.actorId) { throw PermissionDeniedException() } - val actor = actorRepository.findById(principal.actorId)!! + val actor = actorRepository.findById(principal.actorId) + ?: throw InternalServerException("Actor ${principal.actorId} not found.") findById.delete(actor) postRepository.save(findById) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt index 792e5d36..7eb38ed3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/GetPostDetailApplicationService.kt @@ -39,13 +39,13 @@ class GetPostDetailApplicationService( val mediaList = mediaRepository.findByIds(post.mediaIds) return PostDetail.of( - post, - actor, - iconMedia, - mediaList, - post.replyId?.let { fetchChild(it, actor, iconMedia, principal) }, - post.repostId?.let { fetchChild(it, actor, iconMedia, principal) }, - post.moveTo?.let { fetchChild(it, actor, iconMedia, principal) }, + post = post, + actor = actor, + iconMedia = iconMedia, + mediaList = mediaList, + reply = post.replyId?.let { fetchChild(it, actor, iconMedia, principal) }, + repost = post.repostId?.let { fetchChild(it, actor, iconMedia, principal) }, + moveTo = post.moveTo?.let { fetchChild(it, actor, iconMedia, principal) }, ) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt index 6c0630a8..567848df 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/post/PostDetail.kt @@ -26,6 +26,7 @@ data class PostDetail( val moveTo: PostDetail? ) { companion object { + @Suppress("LongParameterList") fun of( post: Post, actor: Actor, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt index 2301fd2f..acc01ebe 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/rejectfollowrequest/UserRejectFollowRequestApplicationService.kt @@ -41,7 +41,7 @@ class UserRejectFollowRequestApplicationService( val targetId = ActorId(command.sourceActorId) val relationship = relationshipRepository.findByActorIdAndTargetId(targetId, actor.id) - ?: throw Exception("Follow request not found") + ?: throw IllegalArgumentException("Follow request not found") relationship.rejectFollowRequest() diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt index 7c41fcc6..39b20e19 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/relationship/unmute/UserUnmuteApplicationService.kt @@ -35,10 +35,6 @@ class UserUnmuteApplicationService( private val actorRepository: ActorRepository, ) : LocalUserAbstractApplicationService(transaction, logger) { - companion object { - private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) - } - override suspend fun internalExecute(command: Unmute, principal: LocalUser) { val actor = actorRepository.findById(principal.actorId) ?: throw InternalServerException("Actor ${principal.actorId} not found.") @@ -53,4 +49,8 @@ class UserUnmuteApplicationService( relationshipRepository.save(relationship) } + + companion object { + private val logger = LoggerFactory.getLogger(UserBlockApplicationService::class.java) + } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/AbstractApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/AbstractApplicationService.kt index 88f5de32..40bfa6fc 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/AbstractApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/shared/AbstractApplicationService.kt @@ -35,7 +35,7 @@ abstract class AbstractApplicationService( } catch (e: CancellationException) { logger.debug("Coroutine canceled", e) throw e - } catch (e: Exception) { + } catch (@Suppress("TooGenericExceptionCaught") e: Exception) { logger.warn("Command execution error", e) throw e } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/ReadTimelineApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/ReadTimelineApplicationService.kt index 88fabe9f..9facf26c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/ReadTimelineApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/timeline/ReadTimelineApplicationService.kt @@ -42,6 +42,7 @@ class ReadTimelineApplicationService( val postDetailList = timeline.map { val reply = if (it.replyPost != null) { + @Suppress("UnsafeCallOnNullableType") PostDetail.of( it.replyPost, it.replyPostActor!!, @@ -53,6 +54,7 @@ class ReadTimelineApplicationService( } val repost = if (it.repostPost != null) { + @Suppress("UnsafeCallOnNullableType") PostDetail.of( it.repostPost, it.repostPostActor!!, @@ -64,12 +66,12 @@ class ReadTimelineApplicationService( } PostDetail.of( - it.post, - it.postActor, - it.postActorIconMedia, - it.postMedias, - reply, - repost + post = it.post, + actor = it.postActor, + iconMedia = it.postActorIconMedia, + mediaList = it.postMedias, + reply = reply, + repost = repost ) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt index dd64669b..08118b85 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/post/PostEvent.kt @@ -34,7 +34,7 @@ class PostDomainEventFactory(private val post: Post, private val actor: Actor? = class PostEventBody(post: PostId, actor: ActorId?) : DomainEventBody(mapOf("post" to post, "actor" to actor)) { fun getPostId(): PostId = toMap()["post"] as PostId - fun getActorId(): ActorId? = toMap()["actor"] as ActorId? + fun getActorId(): ActorId? = toMap()["actor"] as? ActorId } enum class PostEvent(val eventName: String) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt index 0681d9b7..5e26b130 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/relationship/RelationshipEvent.kt @@ -31,9 +31,7 @@ class RelationshipEventBody( relationship: Relationship, override val principal: Principal ) : DomainEventBody(mapOf("relationship" to relationship), principal) { - fun getRelationship(): Relationship { - return toMap()["relationship"] as Relationship - } + fun getRelationship(): Relationship = toMap()["relationship"] as Relationship } enum class RelationshipEvent(val eventName: String) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/timeline/TimelineEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/timeline/TimelineEvent.kt index af552cfc..76cc4554 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/timeline/TimelineEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/timeline/TimelineEvent.kt @@ -11,9 +11,7 @@ class TimelineEventFactory(private val timeline: Timeline) { } class TimelineEventBody(timelineId: TimelineId) : DomainEventBody(mapOf("timeline" to timelineId)) { - fun getTimelineId(): TimelineId { - return toMap()["timeline"] as TimelineId - } + fun getTimelineId(): TimelineId = toMap()["timeline"] as TimelineId } enum class TimelineEvent(val eventName: String) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/userdetail/UserDetailEvent.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/userdetail/UserDetailEvent.kt index 792b475c..dc9f4481 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/userdetail/UserDetailEvent.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/event/userdetail/UserDetailEvent.kt @@ -19,9 +19,7 @@ class UserDetailEventBody(userDetail: UserDetailId) : DomainEventBody( "userDetail" to userDetail ) ) { - fun getUserDetail(): UserDetailId { - return toMap()["userDetail"] as UserDetailId - } + fun getUserDetail(): UserDetailId = toMap()["userDetail"] as UserDetailId } enum class UserDetailEvent(val eventName: String) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt index e80eece0..4267ddbe 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/filter/Filter.kt @@ -65,9 +65,7 @@ class Filter( return id == other.id } - override fun hashCode(): Int { - return id.hashCode() - } + override fun hashCode(): Int = id.hashCode() companion object { fun isAllow(user: UserDetail, action: Action, resource: Filter): Boolean { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt index 44c75088..c3705518 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/media/Media.kt @@ -18,6 +18,7 @@ package dev.usbharu.hideout.core.domain.model.media import java.net.URI +@Suppress("LongParameterList") class Media( val id: MediaId, val name: MediaName, @@ -35,6 +36,18 @@ class Media( fun setUrl(url: URI) { this.url = url } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Media + + return id == other.id + } + + override fun hashCode(): Int = id.hashCode() + override fun toString(): String { return "Media(" + "id=$id, " + diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index 247067a1..b953bd8e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -201,7 +201,7 @@ class Post( var moveTo = moveTo private set - fun moveTo(moveTo: PostId, actor: Actor) { + fun moveTo(moveTo: PostId) { require(this.moveTo == null) this.moveTo = moveTo } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt index 674bf8bc..c6c0a81e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt @@ -27,6 +27,8 @@ interface PostRepository { suspend fun findAllById(ids: List): List suspend fun findByActorId(id: ActorId, page: Page? = null): PaginationList suspend fun delete(post: Post) + + @Suppress("FunctionMaxLength") suspend fun findByActorIdAndVisibilityInList( actorId: ActorId, visibilityList: List, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt index 59587c87..ca6cebcd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt @@ -18,6 +18,7 @@ package dev.usbharu.hideout.core.domain.model.relationship import dev.usbharu.hideout.core.domain.model.actor.ActorId +@Suppress("FunctionMaxLength") interface RelationshipRepository { suspend fun save(relationship: Relationship): Relationship suspend fun delete(relationship: Relationship) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/acct/Acct.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/acct/Acct.kt index 52394510..8be92e3a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/acct/Acct.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/acct/Acct.kt @@ -4,7 +4,5 @@ data class Acct( val userpart: String, val host: String ) { - override fun toString(): String { - return "acct:$userpart@$host" - } + override fun toString(): String = "acct:$userpart@$host" } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/timelineobjectdetail/TimelineObjectDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/timelineobjectdetail/TimelineObjectDetail.kt index e0381014..830612dc 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/timelineobjectdetail/TimelineObjectDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/timelineobjectdetail/TimelineObjectDetail.kt @@ -32,6 +32,7 @@ data class TimelineObjectDetail( val warnFilter: List ) { companion object { + @Suppress("LongParameterList") fun of( timelineObject: TimelineObject, timelineUserDetail: UserDetail, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt index 7f09a103..9b713d8f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt @@ -16,6 +16,9 @@ class Timeline( var visibility = visibility private set + var name = name + private set + fun setVisibility(visibility: TimelineVisibility, userDetail: UserDetail) { check(isSystem.not()) require(userDetailId == userDetail.id) @@ -23,9 +26,6 @@ class Timeline( addDomainEvent(TimelineEventFactory(this).createEvent(TimelineEvent.CHANGE_VISIBILITY)) } - var name = name - private set - companion object { fun create( id: TimelineId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt index 636d8bcb..c88ed75f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt @@ -13,6 +13,7 @@ import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import java.time.Instant +@Suppress("LongParameterList") class TimelineObject( val id: TimelineObjectId, val userDetailId: UserDetailId, @@ -59,7 +60,10 @@ class TimelineObject( emojiIds = post.emojiIds.toList() lastUpdatedAt = Instant.now() isPureRepost = - post.repostId != null && post.replyId == null && post.text.isEmpty() && post.overview?.overview.isNullOrEmpty() + post.repostId != null && + post.replyId == null && + post.text.isEmpty() && + post.overview?.overview.isNullOrEmpty() warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) } } @@ -102,6 +106,7 @@ class TimelineObject( ) } + @Suppress("LongParameterList") fun create( timelineObjectId: TimelineObjectId, timeline: Timeline, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt index 4cd447a7..7cd33a5f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/userdetails/UserDetail.kt @@ -44,6 +44,7 @@ class UserDetail( override fun hashCode(): Int = id.hashCode() companion object { + @Suppress("LongParameterList") fun create( id: UserDetailId, actorId: ActorId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt index 742956ac..2c48e636 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedquery/ExposedPrincipalQueryService.kt @@ -14,6 +14,9 @@ import org.springframework.stereotype.Repository @Repository class ExposedPrincipalQueryService : PrincipalQueryService, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun findByUserDetailId(userDetailId: UserDetailId): PrincipalDTO { return query { UserDetails.leftJoin(Actors).selectAll().where { UserDetails.id eq userDetailId.id }.single() @@ -28,9 +31,6 @@ class ExposedPrincipalQueryService : PrincipalQueryService, AbstractRepository() } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger: Logger = LoggerFactory.getLogger(ExposedPrincipalQueryService::class.java) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index 78dcbbff..8dc2184a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -152,8 +152,8 @@ class ExposedPostRepository( this[PostsVisibleActors.actorId] = it.second } onComplete { - posts.forEach { - update(it) + posts.forEach { post: Post -> + update(post) } } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt index 3bd964f7..227e4667 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt @@ -15,6 +15,9 @@ class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPu TimelineRepository, AbstractRepository(), DomainEventPublishableRepository { + override val logger: Logger + get() = Companion.logger + override suspend fun save(timeline: Timeline): Timeline { query { Timelines.insert { @@ -58,9 +61,6 @@ class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPu companion object { private val logger = LoggerFactory.getLogger(ExposedTimelineRepository::class.java.name) } - - override val logger: Logger - get() = Companion.logger } fun ResultRow.toTimeline(): Timeline { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt index 1169e109..9033e5e4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt @@ -109,12 +109,12 @@ class UserDetailRepositoryImpl(override val domainEventPublisher: DomainEventPub } private fun userDetail(it: ResultRow) = UserDetail( - UserDetailId(it[UserDetails.id]), - ActorId(it[UserDetails.actorId]), - UserDetailHashedPassword(it[UserDetails.password]), - it[UserDetails.autoAcceptFolloweeFollowRequest], - it[UserDetails.lastMigration], - it[UserDetails.homeTimelineId]?.let { it1 -> TimelineId(it1) } + id = UserDetailId(it[UserDetails.id]), + actorId = ActorId(it[UserDetails.actorId]), + password = UserDetailHashedPassword(it[UserDetails.password]), + autoAcceptFolloweeFollowRequest = it[UserDetails.autoAcceptFolloweeFollowRequest], + lastMigration = it[UserDetails.lastMigration], + homeTimelineId = it[UserDetails.homeTimelineId]?.let { it1 -> TimelineId(it1) } ) companion object { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/image/ImageIOImageProcessor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/image/ImageIOImageProcessor.kt index b297ff51..89b0ae1e 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/image/ImageIOImageProcessor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/media/image/ImageIOImageProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.infrastructure.media.image +import dev.usbharu.hideout.core.application.exception.InternalServerException import dev.usbharu.hideout.core.config.ImageIOImageConfig import dev.usbharu.hideout.core.domain.model.media.FileType import dev.usbharu.hideout.core.domain.model.media.MimeType @@ -59,7 +60,7 @@ class ImageIOImageProcessor( tempFile.outputStream().use { if (ImageIO.write(bufferedImage, imageIOImageConfig.format, it).not()) { logger.warn("Failed to save a temporary file. type: {} ,path: {}", imageIOImageConfig.format, tempFile) - throw Exception("Failed to save a temporary file.") + throw InternalServerException("Failed to save a temporary file.") } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoInternalTimelineObjectRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoInternalTimelineObjectRepository.kt index f289ec5c..1e476d0c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoInternalTimelineObjectRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/mongorepository/MongoInternalTimelineObjectRepository.kt @@ -46,9 +46,8 @@ class MongoInternalTimelineObjectRepository( return timelineObjectList } - override suspend fun findByPostId(postId: PostId): List { - return springDataMongoTimelineObjectRepository.findByPostId(postId.id).map { it.toTimelineObject() }.toList() - } + override suspend fun findByPostId(postId: PostId): List = + springDataMongoTimelineObjectRepository.findByPostId(postId.id).map { it.toTimelineObject() }.toList() override suspend fun deleteByPostId(postId: PostId) { springDataMongoTimelineObjectRepository.deleteByPostId(postId.id) @@ -139,48 +138,48 @@ data class SpringDataMongoTimelineObject( fun toTimelineObject(): TimelineObject { return TimelineObject( - TimelineObjectId(id), - UserDetailId(userDetailId), - TimelineId(timelineId), - PostId(postId), - ActorId(postActorId), - Instant.ofEpochSecond(postCreatedAt), - replyId?.let { PostId(it) }, - replyActorId?.let { ActorId(it) }, - repostId?.let { PostId(it) }, - repostActorId?.let { ActorId(it) }, - visibility, - isPureRepost, - mediaIds.map { MediaId(it) }, - emojiIds.map { EmojiId(it) }, - visibleActors.map { ActorId(it) }, - hasMediaInRepost, - Instant.ofEpochSecond(lastUpdatedAt), - warnFilters.map { it.toTimelineObjectWarnFilter() } + id = TimelineObjectId(id), + userDetailId = UserDetailId(userDetailId), + timelineId = TimelineId(timelineId), + postId = PostId(postId), + postActorId = ActorId(postActorId), + postCreatedAt = Instant.ofEpochSecond(postCreatedAt), + replyId = replyId?.let { PostId(it) }, + replyActorId = replyActorId?.let { ActorId(it) }, + repostId = repostId?.let { PostId(it) }, + repostActorId = repostActorId?.let { ActorId(it) }, + visibility = visibility, + isPureRepost = isPureRepost, + mediaIds = mediaIds.map { MediaId(it) }, + emojiIds = emojiIds.map { EmojiId(it) }, + visibleActors = visibleActors.map { ActorId(it) }, + hasMediaInRepost = hasMediaInRepost, + lastUpdatedAt = Instant.ofEpochSecond(lastUpdatedAt), + warnFilters = warnFilters.map { it.toTimelineObjectWarnFilter() } ) } companion object { fun of(timelineObject: TimelineObject): SpringDataMongoTimelineObject { return SpringDataMongoTimelineObject( - timelineObject.id.value, - timelineObject.userDetailId.id, - timelineObject.timelineId.value, - timelineObject.postId.id, - timelineObject.postActorId.id, - timelineObject.postCreatedAt.epochSecond, - timelineObject.replyId?.id, - timelineObject.replyActorId?.id, - timelineObject.repostId?.id, - timelineObject.repostActorId?.id, - timelineObject.visibility, - timelineObject.isPureRepost, - timelineObject.mediaIds.map { it.id }, - timelineObject.emojiIds.map { it.emojiId }, - timelineObject.visibleActors.map { it.id }, - timelineObject.hasMediaInRepost, - timelineObject.lastUpdatedAt.epochSecond, - timelineObject.warnFilters.map { SpringDataMongoTimelineObjectWarnFilter.of(it) } + id = timelineObject.id.value, + userDetailId = timelineObject.userDetailId.id, + timelineId = timelineObject.timelineId.value, + postId = timelineObject.postId.id, + postActorId = timelineObject.postActorId.id, + postCreatedAt = timelineObject.postCreatedAt.epochSecond, + replyId = timelineObject.replyId?.id, + replyActorId = timelineObject.replyActorId?.id, + repostId = timelineObject.repostId?.id, + repostActorId = timelineObject.repostActorId?.id, + visibility = timelineObject.visibility, + isPureRepost = timelineObject.isPureRepost, + mediaIds = timelineObject.mediaIds.map { it.id }, + emojiIds = timelineObject.emojiIds.map { it.emojiId }, + visibleActors = timelineObject.visibleActors.map { it.id }, + hasMediaInRepost = timelineObject.hasMediaInRepost, + lastUpdatedAt = timelineObject.lastUpdatedAt.epochSecond, + warnFilters = timelineObject.warnFilters.map { SpringDataMongoTimelineObjectWarnFilter.of(it) } ) } } @@ -208,6 +207,7 @@ data class SpringDataMongoTimelineObjectWarnFilter( } } +@Suppress("FunctionMaxLength") interface SpringDataMongoTimelineObjectRepository : CoroutineCrudRepository { fun findByPostId(postId: Long): Flow @@ -217,8 +217,6 @@ interface SpringDataMongoTimelineObjectRepository : CoroutineCrudRepository - suspend fun findFirstByTimelineIdAndPostIdGreaterThanOrderByIdAsc( timelineId: Long, postId: Long diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt index 64d7c6a0..184cab62 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/domainevent/SpringFrameworkDomainEventSubscriber.kt @@ -23,7 +23,7 @@ class SpringFrameworkDomainEventSubscriber : DomainEventSubscriber { map[domainEvent.name]?.forEach { try { it.invoke(domainEvent) - } catch (e: Exception) { + } catch (@Suppress("TooGenericExceptionCaught") e: Exception) { logger.error("", e) } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt index f0be54f8..829a1fb7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt @@ -58,7 +58,9 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe if (timeline.visibility == TimelineVisibility.PUBLIC && post.visibility != Visibility.PUBLIC) { return null } - if (timeline.visibility == TimelineVisibility.UNLISTED && (post.visibility != Visibility.PUBLIC || post.visibility != Visibility.UNLISTED)) { + if (timeline.visibility == TimelineVisibility.UNLISTED && + (post.visibility != Visibility.PUBLIC || post.visibility != Visibility.UNLISTED) + ) { return null } @@ -68,21 +70,21 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe if (repost != null) { return TimelineObject.create( - TimelineObjectId(idGenerateService.generateId()), - timeline, - post, - replyActorId, - repost, - applyFilters.filterResults + timelineObjectId = TimelineObjectId(idGenerateService.generateId()), + timeline = timeline, + post = post, + replyActorId = replyActorId, + repost = repost, + filterResults = applyFilters.filterResults ) } return TimelineObject.create( - TimelineObjectId(idGenerateService.generateId()), - timeline, - post, - replyActorId, - applyFilters.filterResults + timelineObjectId = TimelineObjectId(idGenerateService.generateId()), + timeline = timeline, + post = post, + replyActorId = replyActorId, + filterResults = applyFilters.filterResults ) } @@ -106,7 +108,10 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe protected abstract suspend fun removeTimelineObject(timelineId: TimelineId) - protected abstract suspend fun getPostsByTimelineRelationshipList(timelineRelationshipList: List): List + @Suppress("FunctionMaxLength") + protected abstract suspend fun getPostsByTimelineRelationshipList( + timelineRelationshipList: List + ): List protected abstract suspend fun getPostsByPostId(postIds: List, principal: Principal): List @@ -116,6 +121,7 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe page: Page? ): PaginationList + @Suppress("RedundantHigherOrderMapUsage") // if式に対応していないため override suspend fun updatePost(post: Post) { val timelineObjectByPostId = getTimelineObjectByPostId(post.id) @@ -236,16 +242,19 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe val actors = getActors( - timelineObjectList.map { - it.postActorId - } + timelineObjectList.mapNotNull { it.repostActorId } + timelineObjectList.mapNotNull { it.replyActorId } + timelineObjectList.map { it.postActorId } + + timelineObjectList.mapNotNull { it.repostActorId } + + timelineObjectList.mapNotNull { it.replyActorId } ) val postMap = posts.associate { post -> post.id to applyFilters(post, newerFilters) } - val mediaMap = getMedias(posts.flatMap { it.mediaIds } + actors.mapNotNull { it.value.icon }) + val mediaMap = getMedias( + posts.flatMap { it.mediaIds } + + actors.mapNotNull { it.value.icon } + ) return PaginationList( timelineObjectList.mapNotNull { @@ -274,10 +283,10 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe repostPostMedias = repostMedias, repostPostActor = repostActor, repostPostActorIconMedia = mediaMap[repostActor?.icon], - warnFilter = it.warnFilters + post.filterResults.map { + warnFilter = it.warnFilters + post.filterResults.map { filterResult -> TimelineObjectWarnFilter( - it.filter.id, - it.matchedKeyword + filterResult.filter.id, + filterResult.matchedKeyword ) } ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt index 2a704496..36faa561 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt @@ -36,6 +36,7 @@ import org.springframework.stereotype.Component import java.time.Instant @Component +@Suppress("LongParameterList") open class DefaultTimelineStore( private val timelineRepository: TimelineRepository, private val timelineRelationshipRepository: TimelineRelationshipRepository, @@ -59,25 +60,18 @@ open class DefaultTimelineStore( ) } - override suspend fun getTimeline(timelineId: TimelineId): Timeline? { - return timelineRepository.findById(timelineId) - } + override suspend fun getTimeline(timelineId: TimelineId): Timeline? = timelineRepository.findById(timelineId) - override suspend fun getFilters(userDetailId: UserDetailId): List { - return filterRepository.findByUserDetailId(userDetailId) - } + override suspend fun getFilters(userDetailId: UserDetailId): List = + filterRepository.findByUserDetailId(userDetailId) - override suspend fun getNewerFilters(userDetailId: UserDetailId, lastUpdateAt: Instant): List { - return filterRepository.findByUserDetailId(userDetailId) - } + override suspend fun getNewerFilters(userDetailId: UserDetailId, lastUpdateAt: Instant): List = + filterRepository.findByUserDetailId(userDetailId) - override suspend fun applyFilters(post: Post, filters: List): FilteredPost { - return filterDomainService.apply(post, FilterContext.HOME, filters) - } + override suspend fun applyFilters(post: Post, filters: List): FilteredPost = + filterDomainService.apply(post, FilterContext.HOME, filters) - override suspend fun getPost(postId: PostId): Post? { - return postRepository.findById(postId) - } + override suspend fun getPost(postId: PostId): Post? = postRepository.findById(postId) override suspend fun insertTimelineObject(timelineObjectList: List) { internalTimelineObjectRepository.saveAll(timelineObjectList) @@ -87,9 +81,8 @@ open class DefaultTimelineStore( internalTimelineObjectRepository.saveAll(timelineObjectList) } - override suspend fun getTimelineObjectByPostId(postId: PostId): List { - return internalTimelineObjectRepository.findByPostId(postId) - } + override suspend fun getTimelineObjectByPostId(postId: PostId): List = + internalTimelineObjectRepository.findByPostId(postId) override suspend fun removeTimelineObject(postId: PostId) { internalTimelineObjectRepository.deleteByPostId(postId) @@ -103,9 +96,8 @@ open class DefaultTimelineStore( internalTimelineObjectRepository.deleteByTimelineId(timelineId) } - override suspend fun getPostsByTimelineRelationshipList(timelineRelationshipList: List): List { - return timelineRelationshipList.flatMap { getActorPost(it.actorId, visibilities(it)) } - } + override suspend fun getPostsByTimelineRelationshipList(timelineRelationshipList: List): List = + timelineRelationshipList.flatMap { getActorPost(it.actorId, visibilities(it)) } override suspend fun getPostsByPostId(postIds: List, principal: Principal): List { val findAllById = postRepository.findAllById(postIds) @@ -136,6 +128,7 @@ open class DefaultTimelineStore( ) } + @Suppress("UnsafeCallOnNullableType") override suspend fun getNextPaging( timelineId: TimelineId, page: Page? @@ -158,15 +151,12 @@ open class DefaultTimelineStore( return PaginationList(emptyList(), page?.maxId?.let { PostId(it) }, page?.minId?.let { PostId(it) }) } - override suspend fun getActors(actorIds: List): Map { - return actorRepository.findAllById(actorIds).associateBy { it.id } - } + override suspend fun getActors(actorIds: List): Map = + actorRepository.findAllById(actorIds).associateBy { it.id } - override suspend fun getMedias(mediaIds: List): Map { - return mediaRepository.findByIds(mediaIds).associateBy { it.id } - } + override suspend fun getMedias(mediaIds: List): Map = + mediaRepository.findByIds(mediaIds).associateBy { it.id } - override suspend fun getUserDetails(userDetailIdList: List): Map { - return userDetailRepository.findAllById(userDetailIdList).associateBy { it.id } - } + override suspend fun getUserDetails(userDetailIdList: List): Map = + userDetailRepository.findAllById(userDetailIdList).associateBy { it.id } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt index 76f4ad00..86eb8db7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/posts/PublishController.kt @@ -30,6 +30,8 @@ class PublishController( } val instance = getLocalInstanceApplicationService.execute(Unit, principal) + + @Suppress("UnsafeCallOnNullableType") val userDetail = getUserDetailApplicationService.execute(GetUserDetail(principal.userDetailId!!.id), principal) model.addAttribute("instance", instance) model.addAttribute("user", userDetail) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/timeline/TimelineController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/timeline/TimelineController.kt index fe88f560..52e83f5d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/timeline/TimelineController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/timeline/TimelineController.kt @@ -32,7 +32,8 @@ class TimelineController( ?: throw InternalServerException("UserDetail not found.") } - val homeTimelineId = userDetail.homeTimelineId!! + val homeTimelineId = + userDetail.homeTimelineId ?: throw InternalServerException("HomeTimeline ${userDetail.id} is null.") val execute = readTimelineApplicationService.execute( ReadTimeline( timelineId = homeTimelineId.value, diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt index 69fb7cca..ae8cc674 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/post/PostTest.kt @@ -677,7 +677,7 @@ class PostTest { val actor = TestActorFactory.create(post.actorId.id) assertThrows { - post.moveTo(PostId(2), actor) + post.moveTo(PostId(2)) } } @@ -687,7 +687,7 @@ class PostTest { val actor = TestActorFactory.create(post.actorId.id) assertDoesNotThrow { - post.moveTo(PostId(2), actor) + post.moveTo(PostId(2)) } assertEquals(PostId(2), post.moveTo)