style: スタイルを修正

This commit is contained in:
usbharu 2023-06-08 22:54:37 +09:00
parent e8965f798a
commit 0cb58002eb
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
17 changed files with 373 additions and 362 deletions

View File

@ -5,16 +5,19 @@ open class Emoji : Object {
var icon: Image? = null var icon: Image? = null
protected constructor() : super() protected constructor() : super()
constructor(type: List<String>, constructor(
type: List<String>,
name: String?, name: String?,
actor: String?, actor: String?,
id: String?, id: String?,
updated: String?, updated: String?,
icon: Image?) : super( icon: Image?
) : super(
type = add(type, "Emoji"), type = add(type, "Emoji"),
name = name, name = name,
actor = actor, actor = actor,
id = id) { id = id
) {
this.updated = updated this.updated = updated
this.icon = icon this.icon = icon
} }
@ -36,6 +39,4 @@ open class Emoji : Object {
} }
override fun toString(): String = "Emoji(updated=$updated, icon=$icon) ${super.toString()}" override fun toString(): String = "Emoji(updated=$updated, icon=$icon) ${super.toString()}"
} }

View File

@ -10,7 +10,8 @@ open class Like : Object {
var tag: List<Object> = emptyList() var tag: List<Object> = emptyList()
protected constructor() : super() protected constructor() : super()
constructor(type: List<String>, constructor(
type: List<String>,
name: String?, name: String?,
actor: String?, actor: String?,
id: String?, id: String?,
@ -21,7 +22,8 @@ open class Like : Object {
type = add(type, "Like"), type = add(type, "Like"),
name = name, name = name,
actor = actor, actor = actor,
id = id) { id = id
) {
this.`object` = `object` this.`object` = `object`
this.content = content this.content = content
this.tag = tag this.tag = tag
@ -46,6 +48,4 @@ open class Like : Object {
} }
override fun toString(): String = "Like(`object`=$`object`, content=$content, tag=$tag) ${super.toString()}" override fun toString(): String = "Like(`object`=$`object`, content=$content, tag=$tag) ${super.toString()}"
} }

View File

@ -10,7 +10,10 @@ import org.jetbrains.exposed.sql.transactions.transaction
import org.koin.core.annotation.Single import org.koin.core.annotation.Single
@Single @Single
class ReactionRepositoryImpl(private val database: Database, private val idGenerateService: IdGenerateService) : ReactionRepository { class ReactionRepositoryImpl(
private val database: Database,
private val idGenerateService: IdGenerateService
) : ReactionRepository {
init { init {
transaction(database) { transaction(database) {
@ -19,7 +22,6 @@ class ReactionRepositoryImpl(private val database: Database, private val idGener
} }
} }
@Suppress("InjectDispatcher") @Suppress("InjectDispatcher")
suspend fun <T> query(block: suspend () -> T): T = suspend fun <T> query(block: suspend () -> T): T =
newSuspendedTransaction(Dispatchers.IO) { block() } newSuspendedTransaction(Dispatchers.IO) { block() }
@ -40,7 +42,6 @@ class ReactionRepositoryImpl(private val database: Database, private val idGener
it[emojiId] = reaction.emojiId it[emojiId] = reaction.emojiId
it[postId] = reaction.postId it[postId] = reaction.postId
it[userId] = reaction.userId it[userId] = reaction.userId
} }
} }
} }
@ -49,7 +50,11 @@ class ReactionRepositoryImpl(private val database: Database, private val idGener
override suspend fun reactionAlreadyExist(postId: Long, userId: Long, emojiId: Long): Boolean { override suspend fun reactionAlreadyExist(postId: Long, userId: Long, emojiId: Long): Boolean {
return query { return query {
Reactions.select { Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and(Reactions.emojiId.eq(emojiId)) }.empty().not() Reactions.select {
Reactions.postId.eq(postId).and(Reactions.userId.eq(userId)).and(
Reactions.emojiId.eq(emojiId)
)
}.empty().not()
} }
} }
} }

View File

@ -11,13 +11,14 @@ import dev.usbharu.hideout.service.user.IUserService
import io.ktor.http.* import io.ktor.http.*
import org.koin.core.annotation.Single import org.koin.core.annotation.Single
@Single @Single
class ActivityPubLikeServiceImpl(private val reactionService: IReactionService, class ActivityPubLikeServiceImpl(
private val reactionService: IReactionService,
private val activityPubUserService: ActivityPubUserService, private val activityPubUserService: ActivityPubUserService,
private val userService: IUserService, private val userService: IUserService,
private val postService: IPostRepository, private val postService: IPostRepository,
private val activityPubNoteService: ActivityPubNoteService) : ActivityPubLikeService { private val activityPubNoteService: ActivityPubNoteService
) : ActivityPubLikeService {
override suspend fun receiveLike(like: Like): ActivityPubResponse { override suspend fun receiveLike(like: Like): ActivityPubResponse {
val actor = like.actor ?: throw IllegalActivityPubObjectException("actor is null") val actor = like.actor ?: throw IllegalActivityPubObjectException("actor is null")
val content = like.content ?: throw IllegalActivityPubObjectException("content is null") val content = like.content ?: throw IllegalActivityPubObjectException("content is null")
@ -25,8 +26,10 @@ class ActivityPubLikeServiceImpl(private val reactionService: IReactionService,
val person = activityPubUserService.fetchPerson(actor) val person = activityPubUserService.fetchPerson(actor)
activityPubNoteService.fetchNote(like.`object`!!) activityPubNoteService.fetchNote(like.`object`!!)
val user = userService.findByUrl(person.url val user = userService.findByUrl(
?: throw IllegalActivityPubObjectException("actor is not found")) person.url
?: throw IllegalActivityPubObjectException("actor is not found")
)
val post = postService.findByUrl(like.`object`!!) val post = postService.findByUrl(like.`object`!!)
?: throw PostNotFoundException("${like.`object`} was not found") ?: throw PostNotFoundException("${like.`object`} was not found")

View File

@ -75,7 +75,8 @@ class ActivityPubNoteServiceImpl(
return postToNote(post) return postToNote(post)
} }
val response = httpClient.getAp( val response = httpClient.getAp(
url, targetActor?.let { "$targetActor#pubkey" } url,
targetActor?.let { "$targetActor#pubkey" }
) )
val note = Config.configData.objectMapper.readValue<Note>(response.bodyAsText()) val note = Config.configData.objectMapper.readValue<Note>(response.bodyAsText())
return note(note, targetActor, url) return note(note, targetActor, url)

View File

@ -3,6 +3,7 @@ package dev.usbharu.hideout.service.api
import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.Post
import java.time.Instant import java.time.Instant
@Suppress("LongParameterList")
interface IPostApiService { interface IPostApiService {
suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post suspend fun createPost(postForm: dev.usbharu.hideout.domain.model.hideout.form.Post, userId: Long): Post
suspend fun getById(id: Long, userId: Long?): Post suspend fun getById(id: Long, userId: Long?): Post

View File

@ -56,15 +56,15 @@ class PostApiServiceImpl(
return if (idOrNull == null) { return if (idOrNull == null) {
val acct = AcctUtil.parse(nameOrId) val acct = AcctUtil.parse(nameOrId)
postRepository.findByUserNameAndDomain( postRepository.findByUserNameAndDomain(
acct.username, username = acct.username,
acct.domain s = acct.domain
?: Config.configData.domain, ?: Config.configData.domain,
since, since = since,
until, until = until,
minId, minId = minId,
maxId, maxId = maxId,
limit, limit = limit,
userId userId = userId
) )
} else { } else {
postRepository.findByUserId(idOrNull, since, until, minId, maxId, limit, userId) postRepository.findByUserId(idOrNull, since, until, minId, maxId, limit, userId)