style: fix lint

This commit is contained in:
usbharu 2024-01-28 17:49:44 +09:00
parent acd2dded30
commit beac1ccdcb
17 changed files with 105 additions and 104 deletions

View File

@ -272,7 +272,9 @@ class SecurityConfig {
fun jwtTokenCustomizer(): OAuth2TokenCustomizer<JwtEncodingContext> { fun jwtTokenCustomizer(): OAuth2TokenCustomizer<JwtEncodingContext> {
return OAuth2TokenCustomizer { context: JwtEncodingContext -> 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<Authentication>().principal as UserDetailsImpl val userDetailsImpl = context.getPrincipal<Authentication>().principal as UserDetailsImpl
context.claims.claim("uid", userDetailsImpl.id.toString()) context.claims.claim("uid", userDetailsImpl.id.toString())
} }

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.domain.exception.media
import java.io.Serial import java.io.Serial
@Suppress("UnnecessaryAbstractClass")
abstract class MediaException : RuntimeException { abstract class MediaException : RuntimeException {
constructor() : super() constructor() : super()
constructor(message: String?) : super(message) constructor(message: String?) : super(message)

View File

@ -63,14 +63,14 @@ class ExposedNotificationRepository(private val idGenerateService: IdGenerateSer
} }
fun ResultRow.toNotifications() = Notification( fun ResultRow.toNotifications() = Notification(
this[Notifications.id], id = this[Notifications.id],
this[Notifications.type], type = this[Notifications.type],
this[Notifications.userId], userId = this[Notifications.userId],
this[Notifications.sourceActorId], sourceActorId = this[Notifications.sourceActorId],
this[Notifications.postId], postId = this[Notifications.postId],
this[Notifications.text], text = this[Notifications.text],
this[Notifications.reactionId], reactionId = this[Notifications.reactionId],
this[Notifications.createdAt], createdAt = this[Notifications.createdAt],
) )
object Notifications : Table("notifications") { object Notifications : Table("notifications") {

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", "TooManyFunction") @Suppress("FunctionMaxLength", "TooManyFunctions")
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

@ -43,6 +43,7 @@ interface RelationshipRepository {
ignoreFollowRequest: Boolean ignoreFollowRequest: Boolean
): List<Relationship> ): List<Relationship>
@Suppress("FunctionMaxLength")
suspend fun findByActorIdAntMutingAndMaxIdAndSinceId( suspend fun findByActorIdAntMutingAndMaxIdAndSinceId(
actorId: Long, actorId: Long,
muting: Boolean, muting: Boolean,

View File

@ -22,14 +22,14 @@ data class MentionNotificationRequest(
), ),
PostId { PostId {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
postId, postId = postId,
null, text = null,
null, reactionId = null,
createdAt createdAt = createdAt
) )
} }
@ -40,14 +40,14 @@ data class PostNotificationRequest(
) : NotificationRequest(userId, sourceActorId, "post"), PostId { ) : NotificationRequest(userId, sourceActorId, "post"), PostId {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
postId, postId = postId,
null, text = null,
null, reactionId = null,
createdAt createdAt = createdAt
) )
} }
@ -57,14 +57,14 @@ data class RepostNotificationRequest(
override val postId: Long override val postId: Long
) : NotificationRequest(userId, sourceActorId, "repost"), PostId { ) : NotificationRequest(userId, sourceActorId, "repost"), PostId {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
postId, postId = postId,
null, text = null,
null, reactionId = null,
createdAt createdAt = createdAt
) )
} }
@ -73,14 +73,14 @@ data class FollowNotificationRequest(
override val sourceActorId: Long override val sourceActorId: Long
) : NotificationRequest(userId, sourceActorId, "follow") { ) : NotificationRequest(userId, sourceActorId, "follow") {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
null, postId = null,
null, text = null,
null, reactionId = null,
createdAt createdAt = createdAt
) )
} }
@ -89,14 +89,14 @@ data class FollowRequestNotificationRequest(
override val sourceActorId: Long override val sourceActorId: Long
) : NotificationRequest(userId, sourceActorId, "follow-request") { ) : NotificationRequest(userId, sourceActorId, "follow-request") {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
null, postId = null,
null, text = null,
null, reactionId = null,
createdAt createdAt = createdAt
) )
} }
@ -108,13 +108,13 @@ data class ReactionNotificationRequest(
) : NotificationRequest(userId, sourceActorId, "reaction"), PostId { ) : NotificationRequest(userId, sourceActorId, "reaction"), PostId {
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification( override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
id, id = id,
type, type = type,
userId, userId = userId,
sourceActorId, sourceActorId = sourceActorId,
postId, postId = postId,
null, text = null,
reactionId, reactionId = reactionId,
createdAt createdAt = createdAt
) )
} }

View File

@ -59,6 +59,7 @@ class NotificationServiceImpl(
logger.debug("push to {} notification store.", notificationStoreList.size) logger.debug("push to {} notification store.", notificationStoreList.size)
for (it in notificationStoreList) { for (it in notificationStoreList) {
@Suppress("TooGenericExceptionCaught")
try { try {
it.publishNotification(savedNotification, user, sourceActor, post, reaction) it.publishNotification(savedNotification, user, sourceActor, post, reaction)
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -67,13 +67,13 @@ class DefaultPostContentFormatter(private val policyFactory: PolicyFactory) : Po
private fun printHtml(element: Elements): String { private fun printHtml(element: Elements): String {
return element.joinToString("\n\n") { return element.joinToString("\n\n") {
it.childNodes().joinToString("") { it.childNodes().joinToString("") { node ->
if (it is Element && it.tagName() == "br") { if (node is Element && node.tagName() == "br") {
"\n" "\n"
} else if (it is Element) { } else if (node is Element) {
it.text() node.text()
} else if (it is TextNode) { } else if (node is TextNode) {
it.text() node.text()
} else { } else {
"" ""
} }

View File

@ -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.UserNotFoundException
import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException
import dev.usbharu.hideout.core.domain.exception.resource.PostNotFoundException 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.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.post.PostRepository 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) logger.info("START Create Remote Post user: {}, remote url: {}", post.actorId, post.apId)
val actor = val actor =
actorRepository.findById(post.actorId) ?: throw UserNotFoundException("${post.actorId} was not found.") 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) logger.info("SUCCESS Create Remote Post url: {}", createdPost.url)
return createdPost return createdPost
} }
@ -79,11 +78,10 @@ class PostServiceImpl(
actorRepository.save(actor.copy(postsCount = 0, lastPostDate = null)) 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 { return try {
val save = postRepository.save(post) val save = postRepository.save(post)
timelineService.publishTimeline(post, isLocal) timelineService.publishTimeline(post, isLocal)
// actorRepository.save(actor.incrementPostsCount())
save save
} catch (_: DuplicateException) { } catch (_: DuplicateException) {
postRepository.findByApId(post.apId) ?: throw PostNotFoundException.withApId(post.apId) postRepository.findByApId(post.apId) ?: throw PostNotFoundException.withApId(post.apId)
@ -105,7 +103,7 @@ class PostServiceImpl(
replyId = post.repolyId, replyId = post.repolyId,
repostId = post.repostId, repostId = post.repostId,
) )
return internalCreate(createPost, isLocal, user) return internalCreate(createPost, isLocal)
} }
companion object { companion object {

View File

@ -4,6 +4,8 @@ interface MastodonNotificationRepository {
suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification
suspend fun deleteById(id: Long) suspend fun deleteById(id: Long)
suspend fun findById(id: Long): MastodonNotification? suspend fun findById(id: Long): MastodonNotification?
@Suppress("LongParameterList", "FunctionMaxLength")
suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
loginUser: Long, loginUser: Long,
maxId: Long?, maxId: Long?,

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.mastodon.domain.model package dev.usbharu.hideout.mastodon.domain.model
@Suppress("EnumEntryName", "EnumNaming", "EnumEntryNameCase")
enum class NotificationType { enum class NotificationType {
mention, mention,
status, status,

View File

@ -105,18 +105,16 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab
} }
} }
fun ResultRow.toMastodonNotification(): MastodonNotification { fun ResultRow.toMastodonNotification(): MastodonNotification = MastodonNotification(
return MastodonNotification( id = this[MastodonNotifications.id],
this[MastodonNotifications.id], userId = this[MastodonNotifications.userId],
this[MastodonNotifications.userId], type = NotificationType.valueOf(this[MastodonNotifications.type]),
NotificationType.valueOf(this[MastodonNotifications.type]), createdAt = this[MastodonNotifications.createdAt],
this[MastodonNotifications.createdAt], accountId = this[MastodonNotifications.accountId],
this[MastodonNotifications.accountId], statusId = this[MastodonNotifications.statusId],
this[MastodonNotifications.statusId], reportId = this[MastodonNotifications.reportId],
this[MastodonNotifications.reportId], relationshipServeranceEvent = this[MastodonNotifications.relationshipServeranceEventId],
this[MastodonNotifications.relationshipServeranceEventId], )
)
}
object MastodonNotifications : Table("mastodon_notifications") { object MastodonNotifications : Table("mastodon_notifications") {
val id = long("id") val id = long("id")

View File

@ -18,17 +18,13 @@ class MongoMastodonNotificationRepositoryWrapper(
private val mongoTemplate: MongoTemplate private val mongoTemplate: MongoTemplate
) : ) :
MastodonNotificationRepository { MastodonNotificationRepository {
override suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification { override suspend fun save(mastodonNotification: MastodonNotification): MastodonNotification =
return mongoMastodonNotificationRepository.save(mastodonNotification) mongoMastodonNotificationRepository.save(mastodonNotification)
}
override suspend fun deleteById(id: Long) { override suspend fun deleteById(id: Long) = mongoMastodonNotificationRepository.deleteById(id)
mongoMastodonNotificationRepository.deleteById(id)
}
override suspend fun findById(id: Long): MastodonNotification? { override suspend fun findById(id: Long): MastodonNotification? =
return mongoMastodonNotificationRepository.findById(id).getOrNull() mongoMastodonNotificationRepository.findById(id).getOrNull()
}
override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
loginUser: Long, loginUser: Long,

View File

@ -31,12 +31,12 @@ class MastodonNotificationApiController(
accountId: List<String>? accountId: List<String>?
): ResponseEntity<Flow<Notification>> = runBlocking { ): ResponseEntity<Flow<Notification>> = runBlocking {
val notificationFlow = notificationApiService.notifications( val notificationFlow = notificationApiService.notifications(
loginUserContextHolder.getLoginUserId(), loginUser = loginUserContextHolder.getLoginUserId(),
maxId?.toLong(), maxId = maxId?.toLong(),
minId?.toLong(), minId = minId?.toLong(),
sinceId?.toLong(), sinceId = sinceId?.toLong(),
limit ?: 20, limit = limit ?: 20,
types.orEmpty().mapNotNull { NotificationType.parse(it) }, types = types.orEmpty().mapNotNull { NotificationType.parse(it) },
excludeTypes = excludeTypes.orEmpty().mapNotNull { NotificationType.parse(it) }, excludeTypes = excludeTypes.orEmpty().mapNotNull { NotificationType.parse(it) },
accountId = accountId.orEmpty().mapNotNull { it.toLongOrNull() } accountId = accountId.orEmpty().mapNotNull { it.toLongOrNull() }
).asFlow() ).asFlow()

View File

@ -41,7 +41,7 @@ class MastodonNotificationStore(private val mastodonNotificationRepository: Mast
val mastodonNotification = MastodonNotification( val mastodonNotification = MastodonNotification(
id = notification.id, id = notification.id,
notification.userId, userId = notification.userId,
type = notificationType, type = notificationType,
createdAt = notification.createdAt, createdAt = notification.createdAt,
accountId = notification.sourceActorId, accountId = notification.sourceActorId,

View File

@ -4,6 +4,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Notification
import dev.usbharu.hideout.mastodon.domain.model.NotificationType import dev.usbharu.hideout.mastodon.domain.model.NotificationType
interface NotificationApiService { interface NotificationApiService {
@Suppress("LongParameterList")
suspend fun notifications( suspend fun notifications(
loginUser: Long, loginUser: Long,
maxId: Long?, maxId: Long?,