diff --git a/src/main/kotlin/dev/usbharu/hideout/application/config/HttpClientConfig.kt b/src/main/kotlin/dev/usbharu/hideout/application/config/HttpClientConfig.kt index f3b036a1..01209557 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/config/HttpClientConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/config/HttpClientConfig.kt @@ -14,13 +14,13 @@ class HttpClientConfig { @Bean fun httpClient(buildProperties: BuildProperties, applicationConfig: ApplicationConfig): HttpClient = HttpClient(CIO).config { - install(Logging) { - logger = Logger.DEFAULT - level = LogLevel.ALL - } - install(HttpCache) { - } - expectSuccess = true + install(Logging) { + logger = Logger.DEFAULT + level = LogLevel.ALL + } + install(HttpCache) { + } + expectSuccess = true install(UserAgent) { agent = "Hideout/${buildProperties.version} (${applicationConfig.url})" } diff --git a/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt b/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt index b79bd78f..075fc1bb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt @@ -272,7 +272,9 @@ class SecurityConfig { fun jwtTokenCustomizer(): OAuth2TokenCustomizer { return OAuth2TokenCustomizer { context: JwtEncodingContext -> - if (OAuth2TokenType.ACCESS_TOKEN == context.tokenType && context.authorization?.authorizationGrantType == AuthorizationGrantType.AUTHORIZATION_CODE) { + if (OAuth2TokenType.ACCESS_TOKEN == context.tokenType && + context.authorization?.authorizationGrantType == AuthorizationGrantType.AUTHORIZATION_CODE + ) { val userDetailsImpl = context.getPrincipal().principal as UserDetailsImpl context.claims.claim("uid", userDetailsImpl.id.toString()) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt index 221c92e5..f5e368db 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/media/MediaException.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.domain.exception.media import java.io.Serial +@Suppress("UnnecessaryAbstractClass") abstract class MediaException : RuntimeException { constructor() : super() constructor(message: String?) : super(message) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/ExposedNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/ExposedNotificationRepository.kt index 9c82f69e..03e28d0a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/ExposedNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/notification/ExposedNotificationRepository.kt @@ -63,14 +63,14 @@ class ExposedNotificationRepository(private val idGenerateService: IdGenerateSer } fun ResultRow.toNotifications() = Notification( - this[Notifications.id], - this[Notifications.type], - this[Notifications.userId], - this[Notifications.sourceActorId], - this[Notifications.postId], - this[Notifications.text], - this[Notifications.reactionId], - this[Notifications.createdAt], + id = this[Notifications.id], + type = this[Notifications.type], + userId = this[Notifications.userId], + sourceActorId = this[Notifications.sourceActorId], + postId = this[Notifications.postId], + text = this[Notifications.text], + reactionId = this[Notifications.reactionId], + createdAt = this[Notifications.createdAt], ) object Notifications : Table("notifications") { diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt index b76f5f0a..64901759 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/reaction/ReactionRepository.kt @@ -4,7 +4,7 @@ import dev.usbharu.hideout.core.domain.model.emoji.Emoji import org.springframework.stereotype.Repository @Repository -@Suppress("FunctionMaxLength", "TooManyFunction") +@Suppress("FunctionMaxLength", "TooManyFunctions") interface ReactionRepository { suspend fun generateId(): Long suspend fun save(reaction: Reaction): Reaction diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt index 7dca9785..843e9eac 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt @@ -43,6 +43,7 @@ interface RelationshipRepository { ignoreFollowRequest: Boolean ): List + @Suppress("FunctionMaxLength") suspend fun findByActorIdAntMutingAndMaxIdAndSinceId( actorId: Long, muting: Boolean, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt index 3e2b8b5c..0ea02754 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationRequest.kt @@ -22,14 +22,14 @@ data class MentionNotificationRequest( ), PostId { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - postId, - null, - null, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = postId, + text = null, + reactionId = null, + createdAt = createdAt ) } @@ -40,14 +40,14 @@ data class PostNotificationRequest( ) : NotificationRequest(userId, sourceActorId, "post"), PostId { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - postId, - null, - null, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = postId, + text = null, + reactionId = null, + createdAt = createdAt ) } @@ -57,14 +57,14 @@ data class RepostNotificationRequest( override val postId: Long ) : NotificationRequest(userId, sourceActorId, "repost"), PostId { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - postId, - null, - null, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = postId, + text = null, + reactionId = null, + createdAt = createdAt ) } @@ -73,14 +73,14 @@ data class FollowNotificationRequest( override val sourceActorId: Long ) : NotificationRequest(userId, sourceActorId, "follow") { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - null, - null, - null, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = null, + text = null, + reactionId = null, + createdAt = createdAt ) } @@ -89,14 +89,14 @@ data class FollowRequestNotificationRequest( override val sourceActorId: Long ) : NotificationRequest(userId, sourceActorId, "follow-request") { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - null, - null, - null, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = null, + text = null, + reactionId = null, + createdAt = createdAt ) } @@ -108,13 +108,13 @@ data class ReactionNotificationRequest( ) : NotificationRequest(userId, sourceActorId, "reaction"), PostId { override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( - id, - type, - userId, - sourceActorId, - postId, - null, - reactionId, - createdAt + id = id, + type = type, + userId = userId, + sourceActorId = sourceActorId, + postId = postId, + text = null, + reactionId = reactionId, + createdAt = createdAt ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt index f208587e..f2c049a7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/notification/NotificationServiceImpl.kt @@ -59,6 +59,7 @@ class NotificationServiceImpl( logger.debug("push to {} notification store.", notificationStoreList.size) for (it in notificationStoreList) { + @Suppress("TooGenericExceptionCaught") try { it.publishNotification(savedNotification, user, sourceActor, post, reaction) } catch (e: Exception) { diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt index 21252a28..3f063845 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/post/DefaultPostContentFormatter.kt @@ -67,13 +67,13 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po private fun printHtml(element: Elements): String { return element.joinToString("\n\n") { - it.childNodes().joinToString("") { - if (it is Element && it.tagName() == "br") { + it.childNodes().joinToString("") { node -> + if (node is Element && node.tagName() == "br") { "\n" - } else if (it is Element) { - it.text() - } else if (it is TextNode) { - it.text() + } else if (node is Element) { + node.text() + } else if (node is TextNode) { + node.text() } else { "" } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt index 6e58fe8d..a6878729 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt @@ -5,7 +5,6 @@ import dev.usbharu.hideout.activitypub.service.activity.delete.APSendDeleteServi import dev.usbharu.hideout.core.domain.exception.UserNotFoundException import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException import dev.usbharu.hideout.core.domain.exception.resource.PostNotFoundException -import dev.usbharu.hideout.core.domain.model.actor.Actor import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.PostRepository @@ -38,7 +37,7 @@ class PostServiceImpl( logger.info("START Create Remote Post user: {}, remote url: {}", post.actorId, post.apId) val actor = actorRepository.findById(post.actorId) ?: throw UserNotFoundException("${post.actorId} was not found.") - val createdPost = internalCreate(post, false, actor) + val createdPost = internalCreate(post, false) logger.info("SUCCESS Create Remote Post url: {}", createdPost.url) return createdPost } @@ -79,11 +78,10 @@ class PostServiceImpl( actorRepository.save(actor.copy(postsCount = 0, lastPostDate = null)) } - private suspend fun internalCreate(post: Post, isLocal: Boolean, actor: Actor): Post { + private suspend fun internalCreate(post: Post, isLocal: Boolean): Post { return try { val save = postRepository.save(post) timelineService.publishTimeline(post, isLocal) -// actorRepository.save(actor.incrementPostsCount()) save } catch (_: DuplicateException) { postRepository.findByApId(post.apId) ?: throw PostNotFoundException.withApId(post.apId) @@ -105,7 +103,7 @@ class PostServiceImpl( replyId = post.repolyId, repostId = post.repostId, ) - return internalCreate(createPost, isLocal, user) + return internalCreate(createPost, isLocal) } companion object { diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt index 42d769da..8d903a56 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt @@ -4,6 +4,8 @@ interface MastodonNotificationRepository { suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification suspend fun deleteById(id: Long) suspend fun findById(id: Long): MastodonNotification? + + @Suppress("LongParameterList", "FunctionMaxLength") suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( loginUser: Long, maxId: Long?, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/NotificationType.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/NotificationType.kt index b4eb3a45..ff762881 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/NotificationType.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/NotificationType.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.mastodon.domain.model +@Suppress("EnumEntryName", "EnumNaming", "EnumEntryNameCase") enum class NotificationType { mention, status, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt index 520d913a..14279e69 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt @@ -105,18 +105,16 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab } } -fun ResultRow.toMastodonNotification(): MastodonNotification { - return MastodonNotification( - this[MastodonNotifications.id], - this[MastodonNotifications.userId], - NotificationType.valueOf(this[MastodonNotifications.type]), - this[MastodonNotifications.createdAt], - this[MastodonNotifications.accountId], - this[MastodonNotifications.statusId], - this[MastodonNotifications.reportId], - this[MastodonNotifications.relationshipServeranceEventId], - ) -} +fun ResultRow.toMastodonNotification(): MastodonNotification = MastodonNotification( + id = this[MastodonNotifications.id], + userId = this[MastodonNotifications.userId], + type = NotificationType.valueOf(this[MastodonNotifications.type]), + createdAt = this[MastodonNotifications.createdAt], + accountId = this[MastodonNotifications.accountId], + statusId = this[MastodonNotifications.statusId], + reportId = this[MastodonNotifications.reportId], + relationshipServeranceEvent = this[MastodonNotifications.relationshipServeranceEventId], +) object MastodonNotifications : Table("mastodon_notifications") { val id = long("id") diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt index 1016279f..96c7a278 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt @@ -18,17 +18,13 @@ class MongoMastodonNotificationRepositoryWrapper( private val mongoTemplate: MongoTemplate ) : MastodonNotificationRepository { - override suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification { - return mongoMastodonNotificationRepository.save(mastodonNotification) - } + override suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification = + mongoMastodonNotificationRepository.save(mastodonNotification) - override suspend fun deleteById(id: Long) { - mongoMastodonNotificationRepository.deleteById(id) - } + override suspend fun deleteById(id: Long) = mongoMastodonNotificationRepository.deleteById(id) - override suspend fun findById(id: Long): MastodonNotification? { - return mongoMastodonNotificationRepository.findById(id).getOrNull() - } + override suspend fun findById(id: Long): MastodonNotification? = + mongoMastodonNotificationRepository.findById(id).getOrNull() override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( loginUser: Long, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/notification/MastodonNotificationApiController.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/notification/MastodonNotificationApiController.kt index c8ea7e78..ba83cb37 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/notification/MastodonNotificationApiController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/notification/MastodonNotificationApiController.kt @@ -31,12 +31,12 @@ class MastodonNotificationApiController( accountId: List? ): ResponseEntity> = runBlocking { val notificationFlow = notificationApiService.notifications( - loginUserContextHolder.getLoginUserId(), - maxId?.toLong(), - minId?.toLong(), - sinceId?.toLong(), - limit ?: 20, - types.orEmpty().mapNotNull { NotificationType.parse(it) }, + loginUser = loginUserContextHolder.getLoginUserId(), + maxId = maxId?.toLong(), + minId = minId?.toLong(), + sinceId = sinceId?.toLong(), + limit = limit ?: 20, + types = types.orEmpty().mapNotNull { NotificationType.parse(it) }, excludeTypes = excludeTypes.orEmpty().mapNotNull { NotificationType.parse(it) }, accountId = accountId.orEmpty().mapNotNull { it.toLongOrNull() } ).asFlow() diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/MastodonNotificationStore.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/MastodonNotificationStore.kt index 80e66e14..68cc449c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/MastodonNotificationStore.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/MastodonNotificationStore.kt @@ -41,7 +41,7 @@ class MastodonNotificationStore(private val mastodonNotificationRepository: Mast val mastodonNotification = MastodonNotification( id = notification.id, - notification.userId, + userId = notification.userId, type = notificationType, createdAt = notification.createdAt, accountId = notification.sourceActorId, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt index 152b6bab..0849d69a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt @@ -4,6 +4,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Notification import dev.usbharu.hideout.mastodon.domain.model.NotificationType interface NotificationApiService { + @Suppress("LongParameterList") suspend fun notifications( loginUser: Long, maxId: Long?,