diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt index 74076768..f35b0c4f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt @@ -24,7 +24,7 @@ class ObjectDeserializer : JsonDeserializer() { ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } } } else if (type.isValueNode) { - ExtendedActivityVocabulary.values().firstOrNull() { it.name.equals(type.asText(), true) } + ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(type.asText(), true) } } else { null } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt index e230e230..47819d9b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/like/APLikeProcessor.kt @@ -36,7 +36,7 @@ class APLikeProcessor( val emoji = if (content.startsWith(":")) { val tag = activity.activity.tag - (tag.firstOrNull { it is Emoji } as Emoji?)?.let { emojiService.fetchEmoji(it).second } + (tag.firstOrNull { it is Emoji } as? Emoji)?.let { emojiService.fetchEmoji(it).second } } else { UnicodeEmoji(content) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt index 246b02d8..05eed6d7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/common/APResourceResolveServiceImpl.kt @@ -83,8 +83,6 @@ class APResourceResolveServiceImpl( return objects == other.objects } - override fun hashCode(): Int { - return objects.hashCode() - } + override fun hashCode(): Int = objects.hashCode() } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt index 2a884ae0..fbe38266 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt @@ -112,7 +112,7 @@ class InboxJobProcessor( logger.debug("Is verifying success? {}", verify) val activityPubProcessor = - activityPubProcessorList.firstOrNull { it.isSupported(param.type) } as ActivityPubProcessor? + activityPubProcessorList.firstOrNull { it.isSupported(param.type) } as? ActivityPubProcessor if (activityPubProcessor == null) { logger.warn("ActivityType {} is not support.", param.type) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/emoji/EmojiServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/emoji/EmojiServiceImpl.kt index 90a2e1a7..d54f508a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/emoji/EmojiServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/emoji/EmojiServiceImpl.kt @@ -26,9 +26,7 @@ class EmojiServiceImpl( return fetchEmoji(emoji) } - override suspend fun fetchEmoji(emoji: Emoji): Pair { - return emoji to save(emoji) - } + override suspend fun fetchEmoji(emoji: Emoji): Pair = emoji to save(emoji) private suspend fun save(emoji: Emoji): CustomEmoji { val domain = URL(emoji.id).host @@ -51,13 +49,13 @@ class EmojiServiceImpl( ) val customEmoji1 = CustomEmoji( - customEmojiRepository.generateId(), - name, - domain, - instance.id, - media.url, - null, - Instant.now() + id = customEmojiRepository.generateId(), + name = name, + domain = domain, + instanceId = instance.id, + url = media.url, + category = null, + createdAt = Instant.now() ) return customEmojiRepository.save(customEmoji1) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt index 80e2889e..43d0b7f1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteService.kt @@ -113,7 +113,6 @@ class APNoteServiceImpl( it.id } - val mediaList = note.attachment.map { mediaService.uploadRemoteMedia( RemoteMedia( diff --git a/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt index 05fe6305..535375c5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/ExposedTransaction.kt @@ -13,12 +13,6 @@ import java.sql.Connection @Service class ExposedTransaction : Transaction { override suspend fun transaction(block: suspend () -> T): T { -// return newSuspendedTransaction(MDCContext(), transactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED) { -// warnLongQueriesDuration = 1000 -// addLogger(Slf4jSqlDebugLogger) -// block() -// } - return transaction(transactionIsolation = Connection.TRANSACTION_READ_COMMITTED) { debug = true warnLongQueriesDuration = 1000 diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt index d02e9103..fb4579aa 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt @@ -5,6 +5,8 @@ import java.time.Instant sealed class Emoji { abstract val domain: String abstract val name: String + + @Suppress("FunctionMinLength") abstract fun id(): String override fun toString(): String { return "Emoji(" + @@ -23,16 +25,12 @@ data class CustomEmoji( val category: String?, val createdAt: Instant ) : Emoji() { - override fun id(): String { - return id.toString() - } + override fun id(): String = id.toString() } data class UnicodeEmoji( override val name: String ) : Emoji() { override val domain: String = "unicode.org" - override fun id(): String { - return name - } + override fun id(): String = name } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt index e2e44267..a17fc724 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/Nodeinfo.kt @@ -12,9 +12,7 @@ class Nodeinfo private constructor() { return links == other.links } - override fun hashCode(): Int { - return links.hashCode() - } + override fun hashCode(): Int = links.hashCode() } class Links private constructor() { 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 4d3964eb..df35e349 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") +@Suppress("FunctionMaxLength", "TooManyFunction") 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/RelationshipRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt index a8085686..9cea8aaa 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt @@ -11,6 +11,9 @@ import org.springframework.stereotype.Service @Service class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun save(relationship: Relationship): Relationship = query { val singleOrNull = Relationships.select { (Relationships.actorId eq relationship.actorId).and( @@ -94,9 +97,6 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() return@query query.map { it.toRelationships() } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(RelationshipRepositoryImpl::class.java) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt index 07c735ff..3310c138 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt @@ -14,6 +14,9 @@ import org.springframework.stereotype.Repository @Repository class CustomEmojiRepositoryImpl(private val idGenerateService: IdGenerateService) : CustomEmojiRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(customEmoji: CustomEmoji): CustomEmoji = query { @@ -56,22 +59,19 @@ class CustomEmojiRepositoryImpl(private val idGenerateService: IdGenerateService ?.toCustomEmoji() } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(CustomEmojiRepositoryImpl::class.java) } } fun ResultRow.toCustomEmoji(): CustomEmoji = CustomEmoji( - this[CustomEmojis.id], - this[CustomEmojis.name], - this[CustomEmojis.domain], - this[CustomEmojis.instanceId], - this[CustomEmojis.url], - this[CustomEmojis.category], - this[CustomEmojis.createdAt] + id = this[CustomEmojis.id], + name = this[CustomEmojis.name], + domain = this[CustomEmojis.domain], + instanceId = this[CustomEmojis.instanceId], + url = this[CustomEmojis.url], + category = this[CustomEmojis.category], + createdAt = this[CustomEmojis.createdAt] ) fun ResultRow.toCustomEmojiOrNull(): CustomEmoji? { diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt index b932a54f..50887de2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ReactionRepositoryImpl.kt @@ -99,7 +99,6 @@ class ReactionRepositoryImpl( .and(Reactions.unicodeEmoji.eq(emoji.name)) } } - } override suspend fun findByPostId(postId: Long): List = query { @@ -147,7 +146,6 @@ class ReactionRepositoryImpl( .and(Reactions.actorId.eq(actorId)) } - if (emoji is UnicodeEmoji) { query.andWhere { Reactions.unicodeEmoji eq emoji.name } } else { @@ -178,13 +176,13 @@ class ReactionRepositoryImpl( fun ResultRow.toReaction(): Reaction { val emoji = if (this[Reactions.customEmojiId] != null) { CustomEmoji( - this[Reactions.customEmojiId]!!, - this[CustomEmojis.name], - this[CustomEmojis.domain], - this[CustomEmojis.instanceId], - this[CustomEmojis.url], - this[CustomEmojis.category], - this[CustomEmojis.createdAt] + id = this[Reactions.customEmojiId]!!, + name = this[CustomEmojis.name], + domain = this[CustomEmojis.domain], + instanceId = this[CustomEmojis.instanceId], + url = this[CustomEmojis.url], + category = this[CustomEmojis.category], + createdAt = this[CustomEmojis.createdAt] ) } else if (this[Reactions.unicodeEmoji] != null) { UnicodeEmoji(this[Reactions.unicodeEmoji]!!) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt index cb06f2ce..f41d3fe4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/oauth2/UserDetailsImpl.kt @@ -26,11 +26,6 @@ class UserDetailsImpl( accountNonLocked: Boolean, authorities: MutableCollection? ) : User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities) { - companion object { - @Serial - private const val serialVersionUID: Long = -899168205656607781L - } - override fun toString(): String { return "UserDetailsImpl(" + "id=$id" + @@ -53,6 +48,11 @@ class UserDetailsImpl( result = 31 * result + id.hashCode() return result } + + companion object { + @Serial + private const val serialVersionUID: Long = -899168205656607781L + } } @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt index 50a2caac..7a5eaa1c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/SavedMedia.kt @@ -10,9 +10,7 @@ sealed class SavedMedia(val success: Boolean) { return success == other.success } - override fun hashCode(): Int { - return success.hashCode() - } + override fun hashCode(): Int = success.hashCode() } class SuccessSavedMedia( diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt index 86509c08..e3c47e6e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedquery/StatusQueryServiceImpl.kt @@ -161,7 +161,7 @@ class StatusQueryServiceImpl : StatusQueryService { mediaAttachments = it.mapNotNull { resultRow -> resultRow.toMediaOrNull()?.toMediaAttachments() }, - emojis = it.mapNotNull { resultRow -> resultRow.toCustomEmoji()?.toMastodonEmoji() } + emojis = it.mapNotNull { resultRow -> resultRow.toCustomEmojiOrNull()?.toMastodonEmoji() } ) to it.first()[Posts.repostId] } return resolveReplyAndRepost(pairs) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt index 6c4a6709..cc6443ce 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/status/MastodonStatusesApiContoller.kt @@ -39,7 +39,5 @@ class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiSe return ResponseEntity.ok(statusesApiService.emojiReactions(id.toLong(), uid, emoji)) } - override suspend fun apiV1StatusesIdGet(id: String): ResponseEntity { - return super.apiV1StatusesIdGet(id) - } + override suspend fun apiV1StatusesIdGet(id: String): ResponseEntity = super.apiV1StatusesIdGet(id) } diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/status/StatusesApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/status/StatusesApiService.kt index de96e340..563f2059 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/status/StatusesApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/status/StatusesApiService.kt @@ -49,6 +49,7 @@ interface StatusesApiService { } @Service +@Suppress("LongParameterList") class StatsesApiServiceImpl( private val postService: PostService, private val accountService: AccountService, @@ -155,7 +156,6 @@ class StatsesApiServiceImpl( } override suspend fun emojiReactions(postId: Long, userId: Long, emojiName: String): Status? { - status(statusQueryService.findByPostId(postId), userId) ?: return null val emoji = try { @@ -164,9 +164,9 @@ class StatsesApiServiceImpl( } else { emojiService.findByEmojiName(emojiName)!! } - } catch (e: IllegalStateException) { + } catch (_: IllegalStateException) { UnicodeEmoji("❤") - } catch (e: NullPointerException) { + } catch (_: NullPointerException) { UnicodeEmoji("❤") } reactionService.sendReaction(emoji, userId, postId) @@ -174,7 +174,6 @@ class StatsesApiServiceImpl( } override suspend fun removeEmojiReactions(postId: Long, userId: Long, emojiName: String): Status? { - reactionService.removeReaction(userId, postId) return status(statusQueryService.findByPostId(postId), userId) diff --git a/src/main/kotlin/dev/usbharu/hideout/util/EmojiUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/EmojiUtil.kt index 28eda408..4e5c5393 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/EmojiUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/EmojiUtil.kt @@ -4,15 +4,11 @@ import Emojis object EmojiUtil { - val emojiMap by lazy { Emojis.allEmojis .associate { it.code.replace(" ", "-") to it.char } .filterValues { it != "™" } - } - fun isEmoji(string: String): Boolean { - return emojiMap.any { it.value == string } - } + fun isEmoji(string: String): Boolean = emojiMap.any { it.value == string } } diff --git a/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt b/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt index 8a506767..7e57e31e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt +++ b/src/main/kotlin/dev/usbharu/hideout/util/TempFileUtil.kt @@ -19,7 +19,5 @@ class TempFile(val path: T) : AutoCloseable { return path == other.path } - override fun hashCode(): Int { - return path?.hashCode() ?: 0 - } + override fun hashCode(): Int = path?.hashCode() ?: 0 }