diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index 369905ec..5b6841c6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -49,9 +49,9 @@ constructor( @Suppress("CyclomaticComplexMethod") override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + name.hashCode() + result = 31 * result + (name?.hashCode() ?: 0) result = 31 * result + id.hashCode() - result = 31 * result + (preferredUsername?.hashCode() ?: 0) + result = 31 * result + preferredUsername.hashCode() result = 31 * result + (summary?.hashCode() ?: 0) result = 31 * result + inbox.hashCode() result = 31 * result + outbox.hashCode() @@ -61,15 +61,15 @@ constructor( result = 31 * result + endpoints.hashCode() result = 31 * result + (followers?.hashCode() ?: 0) result = 31 * result + (following?.hashCode() ?: 0) - result = 31 * result + manuallyApprovesFollowers.hashCode() + result = 31 * result + (manuallyApprovesFollowers?.hashCode() ?: 0) return result } override fun toString(): String { return "Person(" + - "name='$name', " + + "name=$name, " + "id='$id', " + - "preferredUsername=$preferredUsername, " + + "preferredUsername='$preferredUsername', " + "summary=$summary, " + "inbox='$inbox', " + "outbox='$outbox', " + diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt index b0807f48..a009e6fe 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt @@ -26,8 +26,10 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v .leftJoin(Media) .select { Posts.id eq id } .let { - (it.toNote() ?: return null) to (postQueryMapper.map(it) - .singleOrNull() ?: return null) + (it.toNote() ?: return null) to ( + postQueryMapper.map(it) + .singleOrNull() ?: return null + ) } } @@ -38,8 +40,10 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v .leftJoin(Media) .select { Posts.apId eq apId } .let { - (it.toNote() ?: return null) to (postQueryMapper.map(it) - .singleOrNull() ?: return null) + (it.toNote() ?: return null) to ( + postQueryMapper.map(it) + .singleOrNull() ?: return null + ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt index 8a3559d8..1ad2acbf 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/delete/APDeleteProcessor.kt @@ -36,14 +36,12 @@ class APDeleteProcessor( val actor = actorRepository.findByUrl(deleteId) actor?.let { userService.deleteRemoteActor(it.id) } - val post = postRepository.findByApId(deleteId) if (post == null) { logger.warn("FAILED Delete id: {} is not found.", deleteId) return } postService.deleteRemote(post) - } override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Delete 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 8ac309ed..994e2135 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 @@ -42,7 +42,6 @@ class APLikeProcessor( logger.trace("", e) return } - } override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Like diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 84d25edb..864c848f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -24,70 +24,32 @@ class APUndoProcessor( private val reactionService: ReactionService, private val actorRepository: ActorRepository, private val postRepository: PostRepository -) : - AbstractActivityPubProcessor(transaction) { +) : AbstractActivityPubProcessor(transaction) { override suspend fun internalProcess(activity: ActivityPubProcessContext) { val undo = activity.activity - val type = - undo.apObject.type - .firstOrNull { it == "Block" || it == "Follow" || it == "Like" || it == "Announce" || it == "Accept" } - ?: return + val type = undo.apObject.type.firstOrNull { + it == "Block" || it == "Follow" || it == "Like" || it == "Announce" || it == "Accept" + } ?: return when (type) { "Follow" -> { - val follow = undo.apObject as Follow - - val follower = apUserService.fetchPersonWithEntity(undo.actor, follow.apObject).second - val target = - actorRepository.findByUrl(follow.apObject) ?: throw UserNotFoundException.withUrl(follow.apObject) - - relationshipService.unfollow(follower.id, target.id) + follow(undo) return } "Block" -> { - val block = undo.apObject as Block - - val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second - val target = - actorRepository.findByUrl(block.apObject) ?: throw UserNotFoundException.withUrl(block.apObject) - - relationshipService.unblock(blocker.id, target.id) + block(undo) return } "Accept" -> { - val accept = undo.apObject as Accept - - val acceptObject = if (accept.apObject is ObjectValue) { - accept.apObject.`object` - } else if (accept.apObject is Follow) { - accept.apObject.apObject - } else { - logger.warn("FAILED Unsupported type. Undo Accept {}", accept.apObject.type) - return - } - - val accepter = apUserService.fetchPersonWithEntity(undo.actor, acceptObject).second - val target = - actorRepository.findByUrl(acceptObject) ?: throw UserNotFoundException.withUrl(acceptObject) - - relationshipService.rejectFollowRequest(accepter.id, target.id) + accept(undo) return } "Like" -> { - val like = undo.apObject as Like - - val post = - postRepository.findByUrl(like.apObject) ?: throw PostNotFoundException.withUrl(like.apObject) - - val signer = - actorRepository.findById(post.actorId) ?: throw LocalUserNotFoundException.withId(post.actorId) - val actor = apUserService.fetchPersonWithEntity(like.actor, signer.url).second - - reactionService.receiveRemoveReaction(actor.id, post.id) + like(undo) return } @@ -96,6 +58,57 @@ class APUndoProcessor( TODO() } + private suspend fun accept(undo: Undo) { + val accept = undo.apObject as Accept + + val acceptObject = if (accept.apObject is ObjectValue) { + accept.apObject.`object` + } else if (accept.apObject is Follow) { + accept.apObject.apObject + } else { + logger.warn("FAILED Unsupported type. Undo Accept {}", accept.apObject.type) + return + } + + val accepter = apUserService.fetchPersonWithEntity(undo.actor, acceptObject).second + val target = actorRepository.findByUrl(acceptObject) ?: throw UserNotFoundException.withUrl(acceptObject) + + relationshipService.rejectFollowRequest(accepter.id, target.id) + return + } + + private suspend fun like(undo: Undo) { + val like = undo.apObject as Like + + val post = postRepository.findByUrl(like.apObject) ?: throw PostNotFoundException.withUrl(like.apObject) + + val signer = actorRepository.findById(post.actorId) ?: throw LocalUserNotFoundException.withId(post.actorId) + val actor = apUserService.fetchPersonWithEntity(like.actor, signer.url).second + + reactionService.receiveRemoveReaction(actor.id, post.id) + return + } + + private suspend fun block(undo: Undo) { + val block = undo.apObject as Block + + val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second + val target = actorRepository.findByUrl(block.apObject) ?: throw UserNotFoundException.withUrl(block.apObject) + + relationshipService.unblock(blocker.id, target.id) + return + } + + private suspend fun follow(undo: Undo) { + val follow = undo.apObject as Follow + + val follower = apUserService.fetchPersonWithEntity(undo.actor, follow.apObject).second + val target = actorRepository.findByUrl(follow.apObject) ?: throw UserNotFoundException.withUrl(follow.apObject) + + relationshipService.unfollow(follower.id, target.id) + return + } + override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Undo override fun type(): Class = Undo::class.java 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 f090390e..aac33e17 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 @@ -91,8 +91,7 @@ class InboxJobProcessor( logger.debug("Has signature? {}", signature != null) - - //todo 不正なactorを取得してしまわないようにする + // todo 不正なactorを取得してしまわないようにする val verify = signature?.let { verifyHttpSignature( 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 c0c4bea1..7d284e0f 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 @@ -53,7 +53,9 @@ class APNoteServiceImpl( apResourceResolveService.resolve(url, null as Long?) } catch (e: ClientRequestException) { logger.warn( - "FAILED Failed to retrieve ActivityPub resource. HTTP Status Code: {} url: {}", e.response.status, url + "FAILED Failed to retrieve ActivityPub resource. HTTP Status Code: {} url: {}", + e.response.status, + url ) throw FailedToGetActivityPubResourceException("Could not retrieve $url.", e) } @@ -63,14 +65,15 @@ class APNoteServiceImpl( } private suspend fun saveIfMissing( - note: Note, targetActor: String?, url: String - ): Pair { - return noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor, url) - } + note: Note, + targetActor: String?, + url: String + ): Pair = noteQueryService.findByApid(note.id) ?: saveNote(note, targetActor, url) private suspend fun saveNote(note: Note, targetActor: String?, url: String): Pair { val person = apUserService.fetchPersonWithEntity( - note.attributedTo, targetActor + note.attributedTo, + targetActor ) val post = postRepository.findByApId(note.id) @@ -101,7 +104,10 @@ class APNoteServiceImpl( val mediaList = note.attachment.map { mediaService.uploadRemoteMedia( RemoteMedia( - it.name, it.url, it.mediaType, description = it.name + it.name, + it.url, + it.mediaType, + description = it.name ) ) }.map { it.id } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt index f366ac2f..503785c5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt @@ -12,7 +12,6 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.service.user.RemoteUserCreateDto import dev.usbharu.hideout.core.service.user.UserService -import org.slf4j.LoggerFactory import org.springframework.stereotype.Service interface APUserService { @@ -83,7 +82,6 @@ class APUserServiceImpl( return entityToPerson(userEntity, userEntity.url) to userEntity } - val person = apResourceResolveService.resolve(url, null as Long?) val id = person.id @@ -111,7 +109,6 @@ class APUserServiceImpl( locked = person.manuallyApprovesFollowers ) ) - } private fun entityToPerson( @@ -141,8 +138,4 @@ class APUserServiceImpl( following = actorEntity.following, manuallyApprovesFollowers = actorEntity.locked ) - - companion object { - private val logger = LoggerFactory.getLogger(APUserServiceImpl::class.java) - } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/UserNotFoundException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/UserNotFoundException.kt index 0560be92..30e2f133 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/UserNotFoundException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/UserNotFoundException.kt @@ -18,7 +18,6 @@ open class UserNotFoundException : NotFoundException { @Serial private const val serialVersionUID: Long = 3219433672235626200L - fun withName(string: String, throwable: Throwable? = null): UserNotFoundException = UserNotFoundException("name: $string was not found.", throwable) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/local/LocalUserNotFoundException.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/local/LocalUserNotFoundException.kt index b2cdb0ae..672dfc53 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/local/LocalUserNotFoundException.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/exception/resource/local/LocalUserNotFoundException.kt @@ -15,7 +15,6 @@ class LocalUserNotFoundException : UserNotFoundException { writableStackTrace ) - companion object { @Serial private const val serialVersionUID: Long = -4742548128672528145L @@ -29,5 +28,4 @@ class LocalUserNotFoundException : UserNotFoundException { fun withUrl(url: String, throwable: Throwable? = null): LocalUserNotFoundException = LocalUserNotFoundException("url: $url was not found.", throwable) } - } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index 5eb351e3..71fed7e9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -57,7 +57,6 @@ data class Actor private constructor( postsCount: Int = 0, lastPostDate: Instant? = null ): Actor { - if (id == 0L) { return Actor( id = id, diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRepository.kt index ae39290a..5f87a817 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/ActorRepository.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.domain.model.actor import org.springframework.stereotype.Repository @Repository +@Suppress("TooManyFunctions") interface ActorRepository { suspend fun save(actor: Actor): Actor diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt index c9ada9ff..c7676096 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/instance/InstanceRepository.kt @@ -5,5 +5,5 @@ interface InstanceRepository { suspend fun save(instance: Instance): Instance suspend fun findById(id: Long): Instance? suspend fun delete(instance: Instance) - suspend fun findByUrl(url:String):Instance? + suspend fun findByUrl(url: String): Instance? } 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 ae8cad08..0b6183b5 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 @@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.domain.model.reaction import org.springframework.stereotype.Repository @Repository +@Suppress("FunctionMaxLength") 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 4496f146..ac96db6b 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 @@ -31,8 +31,9 @@ interface RelationshipRepository { suspend fun deleteByActorIdOrTargetActorId(actorId: Long, targetActorId: Long) - suspend fun findByTargetIdAndFollowing(targetId: Long,following:Boolean):List + suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List + @Suppress("LongParameterList", "FunctionMaxLength") suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest( maxId: Long?, sinceId: Long?, 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 ab4278de..a8085686 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 @@ -12,13 +12,11 @@ import org.springframework.stereotype.Service @Service class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() { override suspend fun save(relationship: Relationship): Relationship = query { - val singleOrNull = - Relationships - .select { - (Relationships.actorId eq relationship.actorId) - .and(Relationships.targetActorId eq relationship.targetActorId) - }.forUpdate() - .singleOrNull() + val singleOrNull = Relationships.select { + (Relationships.actorId eq relationship.actorId).and( + Relationships.targetActorId eq relationship.targetActorId + ) + }.forUpdate().singleOrNull() if (singleOrNull == null) { Relationships.insert { @@ -31,34 +29,33 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() it[ignoreFollowRequestFromTarget] = relationship.ignoreFollowRequestToTarget } } else { - Relationships - .update({ - (Relationships.actorId eq relationship.actorId) - .and(Relationships.targetActorId eq relationship.targetActorId) - }) { - it[following] = relationship.following - it[blocking] = relationship.blocking - it[muting] = relationship.muting - it[followRequest] = relationship.followRequest - it[ignoreFollowRequestFromTarget] = relationship.ignoreFollowRequestToTarget - } + Relationships.update({ + (Relationships.actorId eq relationship.actorId).and( + Relationships.targetActorId eq relationship.targetActorId + ) + }) { + it[following] = relationship.following + it[blocking] = relationship.blocking + it[muting] = relationship.muting + it[followRequest] = relationship.followRequest + it[ignoreFollowRequestFromTarget] = relationship.ignoreFollowRequestToTarget + } } return@query relationship } override suspend fun delete(relationship: Relationship): Unit = query { Relationships.deleteWhere { - (Relationships.actorId eq relationship.actorId) - .and(Relationships.targetActorId eq relationship.targetActorId) + (Relationships.actorId eq relationship.actorId).and( + Relationships.targetActorId eq relationship.targetActorId + ) } } override suspend fun findByUserIdAndTargetUserId(actorId: Long, targetActorId: Long): Relationship? = query { return@query Relationships.select { - (Relationships.actorId eq actorId) - .and(Relationships.targetActorId eq targetActorId) - }.singleOrNull() - ?.toRelationships() + (Relationships.actorId eq actorId).and(Relationships.targetActorId eq targetActorId) + }.singleOrNull()?.toRelationships() } override suspend fun deleteByActorIdOrTargetActorId(actorId: Long, targetActorId: Long): Unit = query { @@ -68,7 +65,8 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() } override suspend fun findByTargetIdAndFollowing(targetId: Long, following: Boolean): List = query { - return@query Relationships.select { Relationships.targetActorId eq targetId and (Relationships.following eq following) } + return@query Relationships + .select { Relationships.targetActorId eq targetId and (Relationships.following eq following) } .map { it.toRelationships() } } @@ -81,8 +79,7 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() ignoreFollowRequest: Boolean ): List = query { val query = Relationships.select { - Relationships.targetActorId.eq(targetId) - .and(Relationships.followRequest.eq(followRequest)) + Relationships.targetActorId.eq(targetId).and(Relationships.followRequest.eq(followRequest)) .and(Relationships.ignoreFollowRequestFromTarget.eq(ignoreFollowRequest)) }.limit(limit) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/AbstractRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/AbstractRepository.kt index 14da46c8..3e22db17 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/AbstractRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/AbstractRepository.kt @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator import java.sql.SQLException +@Suppress("VarCouldBeVal") abstract class AbstractRepository { protected abstract val logger: Logger private val sqlErrorCodeSQLExceptionTranslator = SQLErrorCodeSQLExceptionTranslator() @@ -18,8 +19,8 @@ abstract class AbstractRepository { private var traceQueryCall: Boolean = false protected suspend fun query(block: () -> T): T = try { - if (traceQueryCall) { + @Suppress("ThrowingExceptionsWithoutMessageOrCause") logger.trace( """ ***** QUERY CALL STACK TRACE ***** @@ -29,11 +30,9 @@ ${Throwable().stackTrace.joinToString("\n")} ***** QUERY CALL STACK TRACE ***** """ ) - } block.invoke() - } catch (e: SQLException) { if (traceQueryException) { logger.trace("FAILED EXECUTE SQL", e) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt index fcb8a736..f4a70693 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt @@ -18,14 +18,12 @@ class ActorRepositoryImpl( private val actorResultRowMapper: ResultRowMapper, private val actorQueryMapper: QueryMapper ) : ActorRepository, AbstractRepository() { - + override val logger: Logger + get() = Companion.logger override suspend fun save(actor: Actor): Actor = query { - - val singleOrNull = Actors.select { Actors.id eq actor.id }.forUpdate().empty() if (singleOrNull) { - Actors.insert { it[id] = actor.id it[name] = actor.name @@ -125,9 +123,6 @@ class ActorRepositoryImpl( companion object { private val logger = LoggerFactory.getLogger(ActorRepositoryImpl::class.java) } - - override val logger: Logger - get() = Companion.logger } object Actors : Table("actors") { @@ -136,14 +131,16 @@ object Actors : Table("actors") { val domain: Column = varchar("domain", length = 1000) val screenName: Column = varchar("screen_name", length = 300) val description: Column = varchar( - "description", length = 10000 + "description", + length = 10000 ) val inbox: Column = varchar("inbox", length = 1000).uniqueIndex() val outbox: Column = varchar("outbox", length = 1000).uniqueIndex() val url: Column = varchar("url", length = 1000).uniqueIndex() val publicKey: Column = varchar("public_key", length = 10000) val privateKey: Column = varchar( - "private_key", length = 10000 + "private_key", + length = 10000 ).nullable() val createdAt: Column = long("created_at") val keyId = varchar("key_id", length = 1000) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt index 4495e151..36b22b80 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt @@ -11,6 +11,9 @@ import org.springframework.stereotype.Repository @Repository class DeletedActorRepositoryImpl : DeletedActorRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun save(deletedActor: DeletedActor): DeletedActor = query { val singleOrNull = DeletedActors.select { DeletedActors.id eq deletedActor.id }.forUpdate().singleOrNull() @@ -51,9 +54,6 @@ class DeletedActorRepositoryImpl : DeletedActorRepository, AbstractRepository() ?.toDeletedActor() } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(DeletedActorRepositoryImpl::class.java) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt index e90a63e0..2630f733 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedTimelineRepository.kt @@ -16,6 +16,9 @@ import org.springframework.stereotype.Repository @ConditionalOnProperty("hideout.use-mongodb", havingValue = "false", matchIfMissing = true) class ExposedTimelineRepository(private val idGenerateService: IdGenerateService) : TimelineRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(timeline: Timeline): Timeline = query { @@ -82,16 +85,14 @@ class ExposedTimelineRepository(private val idGenerateService: IdGenerateService .map { it.toTimeline() } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(ExposedTimelineRepository::class.java) } } fun ResultRow.toTimeline(): Timeline { - return Timeline(id = this[Timelines.id], + return Timeline( + id = this[Timelines.id], userId = this[Timelines.userId], timelineId = this[Timelines.timelineId], postId = this[Timelines.postId], @@ -103,7 +104,8 @@ fun ResultRow.toTimeline(): Timeline { sensitive = this[Timelines.sensitive], isLocal = this[Timelines.isLocal], isPureRepost = this[Timelines.isPureRepost], - mediaIds = this[Timelines.mediaIds].split(",").mapNotNull { it.toLongOrNull() }) + mediaIds = this[Timelines.mediaIds].split(",").mapNotNull { it.toLongOrNull() } + ) } object Timelines : Table("timelines") { diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt index 2a49c939..485cf6de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/InstanceRepositoryImpl.kt @@ -13,6 +13,9 @@ import dev.usbharu.hideout.core.domain.model.instance.Instance as InstanceEntity @Repository class InstanceRepositoryImpl(private val idGenerateService: IdGenerateService) : InstanceRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(instance: InstanceEntity): InstanceEntity = query { @@ -62,9 +65,6 @@ class InstanceRepositoryImpl(private val idGenerateService: IdGenerateService) : return@query Instance.select { Instance.url eq url }.singleOrNull()?.toInstance() } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(InstanceRepositoryImpl::class.java) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt index 979c4a76..c838031c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/MediaRepositoryImpl.kt @@ -14,6 +14,9 @@ import dev.usbharu.hideout.core.domain.model.media.Media as EntityMedia @Repository class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : MediaRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(media: EntityMedia): EntityMedia = query { @@ -65,10 +68,7 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me override suspend fun findByRemoteUrl(remoteUrl: String): dev.usbharu.hideout.core.domain.model.media.Media? = query { return@query Media.select { Media.remoteUrl eq remoteUrl }.singleOrNull()?.toMedia() - } - - override val logger: Logger - get() = Companion.logger + } companion object { private val logger = LoggerFactory.getLogger(MediaRepositoryImpl::class.java) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt index c8e88d96..2a1899fd 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt @@ -15,6 +15,8 @@ class PostRepositoryImpl( private val idGenerateService: IdGenerateService, private val postQueryMapper: QueryMapper ) : PostRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger override suspend fun generateId(): Long = idGenerateService.generateId() @@ -97,9 +99,6 @@ class PostRepositoryImpl( Posts.deleteWhere { Posts.id eq id } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(PostRepositoryImpl::class.java) } 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 e1ead404..1a3a14ff 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 @@ -14,6 +14,8 @@ import org.springframework.stereotype.Repository class ReactionRepositoryImpl( private val idGenerateService: IdGenerateService ) : ReactionRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger override suspend fun generateId(): Long = idGenerateService.generateId() @@ -85,9 +87,6 @@ class ReactionRepositoryImpl( .map { it.toReaction() } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(ReactionRepositoryImpl::class.java) } @@ -95,7 +94,10 @@ class ReactionRepositoryImpl( fun ResultRow.toReaction(): Reaction { return Reaction( - this[Reactions.id].value, this[Reactions.emojiId], this[Reactions.postId], this[Reactions.actorId] + this[Reactions.id].value, + this[Reactions.emojiId], + this[Reactions.postId], + this[Reactions.actorId] ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt index b64008dd..9b58365d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/UserDetailRepositoryImpl.kt @@ -14,6 +14,9 @@ import org.springframework.stereotype.Repository @Repository class UserDetailRepositoryImpl : UserDetailRepository, AbstractRepository() { + override val logger: Logger + get() = Companion.logger + override suspend fun save(userDetail: UserDetail): UserDetail = query { val singleOrNull = UserDetails.select { UserDetails.actorId eq userDetail.actorId }.forUpdate().singleOrNull() if (singleOrNull == null) { @@ -48,9 +51,6 @@ class UserDetailRepositoryImpl : UserDetailRepository, AbstractRepository() { } } - override val logger: Logger - get() = Companion.logger - companion object { private val logger = LoggerFactory.getLogger(UserDetailRepositoryImpl::class.java) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/httpsignature/HttpRequestMixIn.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/httpsignature/HttpRequestMixIn.kt index 4f998d91..4e14bdae 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/httpsignature/HttpRequestMixIn.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/httpsignature/HttpRequestMixIn.kt @@ -13,6 +13,7 @@ import java.net.URL @JsonDeserialize(using = HttpRequestDeserializer::class) @JsonSubTypes +@Suppress("UnnecessaryAbstractClass") abstract class HttpRequestMixIn class HttpRequestDeserializer : JsonDeserializer() { diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt index 71283023..6e5fdad1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/kjobmongodb/KJobMongoJobQueueWorkerService.kt @@ -41,8 +41,8 @@ class KJobMongoJobQueueWorkerService( } for (jobProcessor in jobQueueProcessorList) { kjob.register(jobProcessor.job()) { - execute { + @Suppress("TooGenericExceptionCaught") try { MDC.put("x-job-id", this.jobId) val param = it.convertUnsafe(props) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index b42f791b..972df120 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -6,5 +6,6 @@ import org.springframework.web.bind.annotation.GetMapping @Controller class AuthController { @GetMapping("/auth/sign_up") + @Suppress("FunctionOnlyReturningConstant") fun signUp(): String = "sign_up" } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt index 2b329ebb..bae8977d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/LocalFileSystemMediaDataStore.kt @@ -74,6 +74,7 @@ class LocalFileSystemMediaDataStore( val fileSavePathString = fileSavePath.toAbsolutePath().toString() logger.info("MEDIA save. path: {}", fileSavePathString) + @Suppress("TooGenericExceptionCaught") try { dataSaveRequest.filePath.copyTo(fileSavePath) dataSaveRequest.thumbnailPath?.copyTo(thumbnailSavePath) @@ -97,6 +98,7 @@ class LocalFileSystemMediaDataStore( */ override suspend fun delete(id: String) { logger.info("START Media delete. id: {}", id) + @Suppress("TooGenericExceptionCaught") try { buildSavePath(savePath, id).deleteIfExists() buildSavePath(savePath, "thumbnail-$id").deleteIfExists() diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt index 1bcf9c69..6cc50463 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/MediaServiceImpl.kt @@ -99,7 +99,6 @@ class MediaServiceImpl( override suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia): Media { logger.info("MEDIA Remote media. filename:${remoteMedia.name} url:${remoteMedia.url}") - val findByRemoteUrl = mediaRepository.findByRemoteUrl(remoteMedia.url) if (findByRemoteUrl != null) { logger.warn("DUPLICATED Remote media is duplicated. url: {}", remoteMedia.url) @@ -156,7 +155,7 @@ class MediaServiceImpl( } } - protected fun findMediaProcessor(mimeType: MimeType): MediaProcessService { + private fun findMediaProcessor(mimeType: MimeType): MediaProcessService { try { return mediaProcessServices.first { try { @@ -170,7 +169,7 @@ class MediaServiceImpl( } } - protected fun generateBlurhash(process: ProcessedMediaPath): String { + private fun generateBlurhash(process: ProcessedMediaPath): String { val path = if (process.thumbnailPath != null && process.thumbnailMimeType != null) { process.thumbnailPath } 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 52211b17..fcd44f67 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 @@ -81,7 +81,7 @@ class PostServiceImpl( timelineService.publishTimeline(post, isLocal) actorRepository.save(actor.incrementPostsCount()) save - } catch (e: DuplicateException) { + } catch (_: DuplicateException) { postRepository.findByApId(post.apId) ?: throw PostNotFoundException.withApId(post.apId) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index 9d957dc1..2a731029 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -42,7 +42,6 @@ class ReactionServiceImpl( reactionRepository.delete(findByPostIdAndUserIdAndEmojiId) } - val reaction = Reaction(reactionRepository.generateId(), 0, postId, actorId) reactionRepository.save(reaction) apReactionService.reaction(reaction) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt index 8cb59ba7..fc35b768 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/resource/InMemoryCacheManager.kt @@ -33,7 +33,6 @@ class InMemoryCacheManager : CacheManager { val processed = try { block() } catch (e: Exception) { - e.printStackTrace() cacheKey.remove(key) throw e } 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 c51aca0c..1a095d82 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 @@ -59,7 +59,6 @@ class StatsesApiServiceImpl( } else { actorRepository.findById(findById.actorId)?.id } - } else { null }