style: fix lint

This commit is contained in:
usbharu 2024-01-08 17:39:55 +09:00
parent c83b990a78
commit 905f0f7c2f
20 changed files with 51 additions and 79 deletions

View File

@ -24,7 +24,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) } ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
} }
} else if (type.isValueNode) { } else if (type.isValueNode) {
ExtendedActivityVocabulary.values().firstOrNull() { it.name.equals(type.asText(), true) } ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(type.asText(), true) }
} else { } else {
null null
} }

View File

@ -36,7 +36,7 @@ class APLikeProcessor(
val emoji = if (content.startsWith(":")) { val emoji = if (content.startsWith(":")) {
val tag = activity.activity.tag 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 { } else {
UnicodeEmoji(content) UnicodeEmoji(content)
} }

View File

@ -83,8 +83,6 @@ class APResourceResolveServiceImpl(
return objects == other.objects return objects == other.objects
} }
override fun hashCode(): Int { override fun hashCode(): Int = objects.hashCode()
return objects.hashCode()
}
} }
} }

View File

@ -112,7 +112,7 @@ class InboxJobProcessor(
logger.debug("Is verifying success? {}", verify) logger.debug("Is verifying success? {}", verify)
val activityPubProcessor = val activityPubProcessor =
activityPubProcessorList.firstOrNull { it.isSupported(param.type) } as ActivityPubProcessor<Object>? activityPubProcessorList.firstOrNull { it.isSupported(param.type) } as? ActivityPubProcessor<Object>
if (activityPubProcessor == null) { if (activityPubProcessor == null) {
logger.warn("ActivityType {} is not support.", param.type) logger.warn("ActivityType {} is not support.", param.type)

View File

@ -26,9 +26,7 @@ class EmojiServiceImpl(
return fetchEmoji(emoji) return fetchEmoji(emoji)
} }
override suspend fun fetchEmoji(emoji: Emoji): Pair<Emoji, CustomEmoji> { override suspend fun fetchEmoji(emoji: Emoji): Pair<Emoji, CustomEmoji> = emoji to save(emoji)
return emoji to save(emoji)
}
private suspend fun save(emoji: Emoji): CustomEmoji { private suspend fun save(emoji: Emoji): CustomEmoji {
val domain = URL(emoji.id).host val domain = URL(emoji.id).host
@ -51,13 +49,13 @@ class EmojiServiceImpl(
) )
val customEmoji1 = CustomEmoji( val customEmoji1 = CustomEmoji(
customEmojiRepository.generateId(), id = customEmojiRepository.generateId(),
name, name = name,
domain, domain = domain,
instance.id, instanceId = instance.id,
media.url, url = media.url,
null, category = null,
Instant.now() createdAt = Instant.now()
) )
return customEmojiRepository.save(customEmoji1) return customEmojiRepository.save(customEmoji1)

View File

@ -113,7 +113,6 @@ class APNoteServiceImpl(
it.id it.id
} }
val mediaList = note.attachment.map { val mediaList = note.attachment.map {
mediaService.uploadRemoteMedia( mediaService.uploadRemoteMedia(
RemoteMedia( RemoteMedia(

View File

@ -13,12 +13,6 @@ import java.sql.Connection
@Service @Service
class ExposedTransaction : Transaction { class ExposedTransaction : Transaction {
override suspend fun <T> transaction(block: suspend () -> T): T { override suspend fun <T> 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) { return transaction(transactionIsolation = Connection.TRANSACTION_READ_COMMITTED) {
debug = true debug = true
warnLongQueriesDuration = 1000 warnLongQueriesDuration = 1000

View File

@ -5,6 +5,8 @@ import java.time.Instant
sealed class Emoji { sealed class Emoji {
abstract val domain: String abstract val domain: String
abstract val name: String abstract val name: String
@Suppress("FunctionMinLength")
abstract fun id(): String abstract fun id(): String
override fun toString(): String { override fun toString(): String {
return "Emoji(" + return "Emoji(" +
@ -23,16 +25,12 @@ data class CustomEmoji(
val category: String?, val category: String?,
val createdAt: Instant val createdAt: Instant
) : Emoji() { ) : Emoji() {
override fun id(): String { override fun id(): String = id.toString()
return id.toString()
}
} }
data class UnicodeEmoji( data class UnicodeEmoji(
override val name: String override val name: String
) : Emoji() { ) : Emoji() {
override val domain: String = "unicode.org" override val domain: String = "unicode.org"
override fun id(): String { override fun id(): String = name
return name
}
} }

View File

@ -12,9 +12,7 @@ class Nodeinfo private constructor() {
return links == other.links return links == other.links
} }
override fun hashCode(): Int { override fun hashCode(): Int = links.hashCode()
return links.hashCode()
}
} }
class Links private constructor() { class Links private constructor() {

View File

@ -4,7 +4,7 @@ import dev.usbharu.hideout.core.domain.model.emoji.Emoji
import org.springframework.stereotype.Repository import org.springframework.stereotype.Repository
@Repository @Repository
@Suppress("FunctionMaxLength") @Suppress("FunctionMaxLength", "TooManyFunction")
interface ReactionRepository { interface ReactionRepository {
suspend fun generateId(): Long suspend fun generateId(): Long
suspend fun save(reaction: Reaction): Reaction suspend fun save(reaction: Reaction): Reaction

View File

@ -11,6 +11,9 @@ import org.springframework.stereotype.Service
@Service @Service
class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() { class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() {
override val logger: Logger
get() = Companion.logger
override suspend fun save(relationship: Relationship): Relationship = query { override suspend fun save(relationship: Relationship): Relationship = query {
val singleOrNull = Relationships.select { val singleOrNull = Relationships.select {
(Relationships.actorId eq relationship.actorId).and( (Relationships.actorId eq relationship.actorId).and(
@ -94,9 +97,6 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository()
return@query query.map { it.toRelationships() } return@query query.map { it.toRelationships() }
} }
override val logger: Logger
get() = Companion.logger
companion object { companion object {
private val logger = LoggerFactory.getLogger(RelationshipRepositoryImpl::class.java) private val logger = LoggerFactory.getLogger(RelationshipRepositoryImpl::class.java)
} }

View File

@ -14,6 +14,9 @@ import org.springframework.stereotype.Repository
@Repository @Repository
class CustomEmojiRepositoryImpl(private val idGenerateService: IdGenerateService) : CustomEmojiRepository, class CustomEmojiRepositoryImpl(private val idGenerateService: IdGenerateService) : CustomEmojiRepository,
AbstractRepository() { AbstractRepository() {
override val logger: Logger
get() = Companion.logger
override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun generateId(): Long = idGenerateService.generateId()
override suspend fun save(customEmoji: CustomEmoji): CustomEmoji = query { override suspend fun save(customEmoji: CustomEmoji): CustomEmoji = query {
@ -56,22 +59,19 @@ class CustomEmojiRepositoryImpl(private val idGenerateService: IdGenerateService
?.toCustomEmoji() ?.toCustomEmoji()
} }
override val logger: Logger
get() = Companion.logger
companion object { companion object {
private val logger = LoggerFactory.getLogger(CustomEmojiRepositoryImpl::class.java) private val logger = LoggerFactory.getLogger(CustomEmojiRepositoryImpl::class.java)
} }
} }
fun ResultRow.toCustomEmoji(): CustomEmoji = CustomEmoji( fun ResultRow.toCustomEmoji(): CustomEmoji = CustomEmoji(
this[CustomEmojis.id], id = this[CustomEmojis.id],
this[CustomEmojis.name], name = this[CustomEmojis.name],
this[CustomEmojis.domain], domain = this[CustomEmojis.domain],
this[CustomEmojis.instanceId], instanceId = this[CustomEmojis.instanceId],
this[CustomEmojis.url], url = this[CustomEmojis.url],
this[CustomEmojis.category], category = this[CustomEmojis.category],
this[CustomEmojis.createdAt] createdAt = this[CustomEmojis.createdAt]
) )
fun ResultRow.toCustomEmojiOrNull(): CustomEmoji? { fun ResultRow.toCustomEmojiOrNull(): CustomEmoji? {

View File

@ -99,7 +99,6 @@ class ReactionRepositoryImpl(
.and(Reactions.unicodeEmoji.eq(emoji.name)) .and(Reactions.unicodeEmoji.eq(emoji.name))
} }
} }
} }
override suspend fun findByPostId(postId: Long): List<Reaction> = query { override suspend fun findByPostId(postId: Long): List<Reaction> = query {
@ -147,7 +146,6 @@ class ReactionRepositoryImpl(
.and(Reactions.actorId.eq(actorId)) .and(Reactions.actorId.eq(actorId))
} }
if (emoji is UnicodeEmoji) { if (emoji is UnicodeEmoji) {
query.andWhere { Reactions.unicodeEmoji eq emoji.name } query.andWhere { Reactions.unicodeEmoji eq emoji.name }
} else { } else {
@ -178,13 +176,13 @@ class ReactionRepositoryImpl(
fun ResultRow.toReaction(): Reaction { fun ResultRow.toReaction(): Reaction {
val emoji = if (this[Reactions.customEmojiId] != null) { val emoji = if (this[Reactions.customEmojiId] != null) {
CustomEmoji( CustomEmoji(
this[Reactions.customEmojiId]!!, id = this[Reactions.customEmojiId]!!,
this[CustomEmojis.name], name = this[CustomEmojis.name],
this[CustomEmojis.domain], domain = this[CustomEmojis.domain],
this[CustomEmojis.instanceId], instanceId = this[CustomEmojis.instanceId],
this[CustomEmojis.url], url = this[CustomEmojis.url],
this[CustomEmojis.category], category = this[CustomEmojis.category],
this[CustomEmojis.createdAt] createdAt = this[CustomEmojis.createdAt]
) )
} else if (this[Reactions.unicodeEmoji] != null) { } else if (this[Reactions.unicodeEmoji] != null) {
UnicodeEmoji(this[Reactions.unicodeEmoji]!!) UnicodeEmoji(this[Reactions.unicodeEmoji]!!)

View File

@ -26,11 +26,6 @@ class UserDetailsImpl(
accountNonLocked: Boolean, accountNonLocked: Boolean,
authorities: MutableCollection<out GrantedAuthority>? authorities: MutableCollection<out GrantedAuthority>?
) : User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities) { ) : User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities) {
companion object {
@Serial
private const val serialVersionUID: Long = -899168205656607781L
}
override fun toString(): String { override fun toString(): String {
return "UserDetailsImpl(" + return "UserDetailsImpl(" +
"id=$id" + "id=$id" +
@ -53,6 +48,11 @@ class UserDetailsImpl(
result = 31 * result + id.hashCode() result = 31 * result + id.hashCode()
return result return result
} }
companion object {
@Serial
private const val serialVersionUID: Long = -899168205656607781L
}
} }
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY) @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)

View File

@ -10,9 +10,7 @@ sealed class SavedMedia(val success: Boolean) {
return success == other.success return success == other.success
} }
override fun hashCode(): Int { override fun hashCode(): Int = success.hashCode()
return success.hashCode()
}
} }
class SuccessSavedMedia( class SuccessSavedMedia(

View File

@ -161,7 +161,7 @@ class StatusQueryServiceImpl : StatusQueryService {
mediaAttachments = it.mapNotNull { resultRow -> mediaAttachments = it.mapNotNull { resultRow ->
resultRow.toMediaOrNull()?.toMediaAttachments() resultRow.toMediaOrNull()?.toMediaAttachments()
}, },
emojis = it.mapNotNull { resultRow -> resultRow.toCustomEmoji()?.toMastodonEmoji() } emojis = it.mapNotNull { resultRow -> resultRow.toCustomEmojiOrNull()?.toMastodonEmoji() }
) to it.first()[Posts.repostId] ) to it.first()[Posts.repostId]
} }
return resolveReplyAndRepost(pairs) return resolveReplyAndRepost(pairs)

View File

@ -39,7 +39,5 @@ class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiSe
return ResponseEntity.ok(statusesApiService.emojiReactions(id.toLong(), uid, emoji)) return ResponseEntity.ok(statusesApiService.emojiReactions(id.toLong(), uid, emoji))
} }
override suspend fun apiV1StatusesIdGet(id: String): ResponseEntity<Status> { override suspend fun apiV1StatusesIdGet(id: String): ResponseEntity<Status> = super.apiV1StatusesIdGet(id)
return super.apiV1StatusesIdGet(id)
}
} }

View File

@ -49,6 +49,7 @@ interface StatusesApiService {
} }
@Service @Service
@Suppress("LongParameterList")
class StatsesApiServiceImpl( class StatsesApiServiceImpl(
private val postService: PostService, private val postService: PostService,
private val accountService: AccountService, private val accountService: AccountService,
@ -155,7 +156,6 @@ class StatsesApiServiceImpl(
} }
override suspend fun emojiReactions(postId: Long, userId: Long, emojiName: String): Status? { override suspend fun emojiReactions(postId: Long, userId: Long, emojiName: String): Status? {
status(statusQueryService.findByPostId(postId), userId) ?: return null status(statusQueryService.findByPostId(postId), userId) ?: return null
val emoji = try { val emoji = try {
@ -164,9 +164,9 @@ class StatsesApiServiceImpl(
} else { } else {
emojiService.findByEmojiName(emojiName)!! emojiService.findByEmojiName(emojiName)!!
} }
} catch (e: IllegalStateException) { } catch (_: IllegalStateException) {
UnicodeEmoji("") UnicodeEmoji("")
} catch (e: NullPointerException) { } catch (_: NullPointerException) {
UnicodeEmoji("") UnicodeEmoji("")
} }
reactionService.sendReaction(emoji, userId, postId) reactionService.sendReaction(emoji, userId, postId)
@ -174,7 +174,6 @@ class StatsesApiServiceImpl(
} }
override suspend fun removeEmojiReactions(postId: Long, userId: Long, emojiName: String): Status? { override suspend fun removeEmojiReactions(postId: Long, userId: Long, emojiName: String): Status? {
reactionService.removeReaction(userId, postId) reactionService.removeReaction(userId, postId)
return status(statusQueryService.findByPostId(postId), userId) return status(statusQueryService.findByPostId(postId), userId)

View File

@ -4,15 +4,11 @@ import Emojis
object EmojiUtil { object EmojiUtil {
val emojiMap by lazy { val emojiMap by lazy {
Emojis.allEmojis Emojis.allEmojis
.associate { it.code.replace(" ", "-") to it.char } .associate { it.code.replace(" ", "-") to it.char }
.filterValues { it != "" } .filterValues { it != "" }
} }
fun isEmoji(string: String): Boolean { fun isEmoji(string: String): Boolean = emojiMap.any { it.value == string }
return emojiMap.any { it.value == string }
}
} }

View File

@ -19,7 +19,5 @@ class TempFile<T : Path?>(val path: T) : AutoCloseable {
return path == other.path return path == other.path
} }
override fun hashCode(): Int { override fun hashCode(): Int = path?.hashCode() ?: 0
return path?.hashCode() ?: 0
}
} }