style: fix lint

This commit is contained in:
usbharu 2024-08-23 23:39:27 +09:00
parent e21552df97
commit fd0d6b9625
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
42 changed files with 223 additions and 183 deletions

View File

@ -0,0 +1,3 @@
package dev.usbharu.hideout.core.application.actor
data class SuspendLocalActor(val actorId: Long)

View File

@ -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<SuspendLocalActor, Unit>(transaction, logger) {
val actor = actorRepository.findById(id)!!
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)
}
}

View File

@ -0,0 +1,3 @@
package dev.usbharu.hideout.core.application.actor
data class UnsuspendLocalActor(val actorId: Long)

View File

@ -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<UnsuspendLocalActor, Unit>(transaction, logger) {
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)
}
}

View File

@ -20,5 +20,3 @@ class RegisterLocalUserSetHomeTimelineSubscriber(
}
}
}
// todo userdetailにdomain event付けて createのイベントで反応させる タイムラインを新しく一つ作って userdetailのhometimelineに紐づけて自分自身をtimleine relationshipに入れる

View File

@ -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)
}
}

View File

@ -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<RelationshipEventBody>(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(

View File

@ -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!!
}

View File

@ -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
)
}
}

View File

@ -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<DeleteLocalPost, Unit>(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)
}

View File

@ -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) },
)
}

View File

@ -26,6 +26,7 @@ data class PostDetail(
val moveTo: PostDetail?
) {
companion object {
@Suppress("LongParameterList")
fun of(
post: Post,
actor: Actor,

View File

@ -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()

View File

@ -35,10 +35,6 @@ class UserUnmuteApplicationService(
private val actorRepository: ActorRepository,
) :
LocalUserAbstractApplicationService<Unmute, Unit>(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)
}
}

View File

@ -35,7 +35,7 @@ abstract class AbstractApplicationService<T : Any, R>(
} 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
}

View File

@ -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
)
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 {

View File

@ -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, " +

View File

@ -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
}

View File

@ -27,6 +27,8 @@ interface PostRepository {
suspend fun findAllById(ids: List<PostId>): List<Post>
suspend fun findByActorId(id: ActorId, page: Page? = null): PaginationList<Post, PostId>
suspend fun delete(post: Post)
@Suppress("FunctionMaxLength")
suspend fun findByActorIdAndVisibilityInList(
actorId: ActorId,
visibilityList: List<Visibility>,

View File

@ -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)

View File

@ -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"
}

View File

@ -32,6 +32,7 @@ data class TimelineObjectDetail(
val warnFilter: List<TimelineObjectWarnFilter>
) {
companion object {
@Suppress("LongParameterList")
fun of(
timelineObject: TimelineObject,
timelineUserDetail: UserDetail,

View File

@ -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,

View File

@ -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,

View File

@ -44,6 +44,7 @@ class UserDetail(
override fun hashCode(): Int = id.hashCode()
companion object {
@Suppress("LongParameterList")
fun create(
id: UserDetailId,
actorId: ActorId,

View File

@ -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)
}

View File

@ -152,8 +152,8 @@ class ExposedPostRepository(
this[PostsVisibleActors.actorId] = it.second
}
onComplete {
posts.forEach {
update(it)
posts.forEach { post: Post ->
update(post)
}
}
}

View File

@ -15,6 +15,9 @@ class ExposedTimelineRepository(override val domainEventPublisher: DomainEventPu
TimelineRepository,
AbstractRepository(),
DomainEventPublishableRepository<Timeline> {
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 {

View File

@ -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 {

View File

@ -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.")
}
}

View File

@ -46,9 +46,8 @@ class MongoInternalTimelineObjectRepository(
return timelineObjectList
}
override suspend fun findByPostId(postId: PostId): List<TimelineObject> {
return springDataMongoTimelineObjectRepository.findByPostId(postId.id).map { it.toTimelineObject() }.toList()
}
override suspend fun findByPostId(postId: PostId): List<TimelineObject> =
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<SpringDataMongoTimelineObject, Long> {
fun findByPostId(postId: Long): Flow<SpringDataMongoTimelineObject>
@ -217,8 +217,6 @@ interface SpringDataMongoTimelineObjectRepository : CoroutineCrudRepository<Spri
suspend fun deleteByTimelineId(timelineId: Long)
suspend fun findByTimelineId(timelineId: TimelineId): Flow<SpringDataMongoTimelineObject>
suspend fun findFirstByTimelineIdAndPostIdGreaterThanOrderByIdAsc(
timelineId: Long,
postId: Long

View File

@ -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)
}
}

View File

@ -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<TimelineRelationship>): List<Post>
@Suppress("FunctionMaxLength")
protected abstract suspend fun getPostsByTimelineRelationshipList(
timelineRelationshipList: List<TimelineRelationship>
): List<Post>
protected abstract suspend fun getPostsByPostId(postIds: List<PostId>, principal: Principal): List<Post>
@ -116,6 +121,7 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe
page: Page?
): PaginationList<TimelineObject, PostId>
@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<TimelineObject, TimelineObjectDetail> {
@ -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
)
}
)

View File

@ -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<Filter> {
return filterRepository.findByUserDetailId(userDetailId)
}
override suspend fun getFilters(userDetailId: UserDetailId): List<Filter> =
filterRepository.findByUserDetailId(userDetailId)
override suspend fun getNewerFilters(userDetailId: UserDetailId, lastUpdateAt: Instant): List<Filter> {
return filterRepository.findByUserDetailId(userDetailId)
}
override suspend fun getNewerFilters(userDetailId: UserDetailId, lastUpdateAt: Instant): List<Filter> =
filterRepository.findByUserDetailId(userDetailId)
override suspend fun applyFilters(post: Post, filters: List<Filter>): FilteredPost {
return filterDomainService.apply(post, FilterContext.HOME, filters)
}
override suspend fun applyFilters(post: Post, filters: List<Filter>): 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<TimelineObject>) {
internalTimelineObjectRepository.saveAll(timelineObjectList)
@ -87,9 +81,8 @@ open class DefaultTimelineStore(
internalTimelineObjectRepository.saveAll(timelineObjectList)
}
override suspend fun getTimelineObjectByPostId(postId: PostId): List<TimelineObject> {
return internalTimelineObjectRepository.findByPostId(postId)
}
override suspend fun getTimelineObjectByPostId(postId: PostId): List<TimelineObject> =
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<TimelineRelationship>): List<Post> {
return timelineRelationshipList.flatMap { getActorPost(it.actorId, visibilities(it)) }
}
override suspend fun getPostsByTimelineRelationshipList(timelineRelationshipList: List<TimelineRelationship>): List<Post> =
timelineRelationshipList.flatMap { getActorPost(it.actorId, visibilities(it)) }
override suspend fun getPostsByPostId(postIds: List<PostId>, principal: Principal): List<Post> {
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<ActorId>): Map<ActorId, Actor> {
return actorRepository.findAllById(actorIds).associateBy { it.id }
}
override suspend fun getActors(actorIds: List<ActorId>): Map<ActorId, Actor> =
actorRepository.findAllById(actorIds).associateBy { it.id }
override suspend fun getMedias(mediaIds: List<MediaId>): Map<MediaId, Media> {
return mediaRepository.findByIds(mediaIds).associateBy { it.id }
}
override suspend fun getMedias(mediaIds: List<MediaId>): Map<MediaId, Media> =
mediaRepository.findByIds(mediaIds).associateBy { it.id }
override suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail> {
return userDetailRepository.findAllById(userDetailIdList).associateBy { it.id }
}
override suspend fun getUserDetails(userDetailIdList: List<UserDetailId>): Map<UserDetailId, UserDetail> =
userDetailRepository.findAllById(userDetailIdList).associateBy { it.id }
}

View File

@ -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)

View File

@ -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,

View File

@ -677,7 +677,7 @@ class PostTest {
val actor = TestActorFactory.create(post.actorId.id)
assertThrows<IllegalArgumentException> {
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)