mirror of https://github.com/usbharu/Hideout.git
style: fix lint
This commit is contained in:
parent
acd2dded30
commit
beac1ccdcb
|
@ -272,7 +272,9 @@ class SecurityConfig {
|
|||
fun jwtTokenCustomizer(): OAuth2TokenCustomizer<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
|
||||
context.claims.claim("uid", userDetailsImpl.id.toString())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -43,6 +43,7 @@ interface RelationshipRepository {
|
|||
ignoreFollowRequest: Boolean
|
||||
): List<Relationship>
|
||||
|
||||
@Suppress("FunctionMaxLength")
|
||||
suspend fun findByActorIdAntMutingAndMaxIdAndSinceId(
|
||||
actorId: Long,
|
||||
muting: Boolean,
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
""
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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?,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.mastodon.domain.model
|
||||
|
||||
@Suppress("EnumEntryName", "EnumNaming", "EnumEntryNameCase")
|
||||
enum class NotificationType {
|
||||
mention,
|
||||
status,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -31,12 +31,12 @@ class MastodonNotificationApiController(
|
|||
accountId: List<String>?
|
||||
): ResponseEntity<Flow<Notification>> = 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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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?,
|
||||
|
|
Loading…
Reference in New Issue