mirror of https://github.com/usbharu/Hideout.git
style: fix lint
This commit is contained in:
parent
7189159cb0
commit
d06b4062c8
|
@ -180,7 +180,21 @@ class APNoteServiceImpl(
|
||||||
}.map { it.id }
|
}.map { it.id }
|
||||||
|
|
||||||
val createPost =
|
val createPost =
|
||||||
if (quote != null) {
|
post(quote, person, note, visibility, reply, mediaList, emojis)
|
||||||
|
|
||||||
|
val createRemote = postService.createRemote(createPost)
|
||||||
|
return note to createRemote
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun post(
|
||||||
|
quote: Post?,
|
||||||
|
person: Pair<Person, Actor>,
|
||||||
|
note: Note,
|
||||||
|
visibility: Visibility,
|
||||||
|
reply: Post?,
|
||||||
|
mediaList: List<Long>,
|
||||||
|
emojis: List<Long>
|
||||||
|
) = if (quote != null) {
|
||||||
postBuilder.quoteRepostOf(
|
postBuilder.quoteRepostOf(
|
||||||
id = postRepository.generateId(),
|
id = postRepository.generateId(),
|
||||||
actorId = person.second.id,
|
actorId = person.second.id,
|
||||||
|
@ -211,10 +225,6 @@ class APNoteServiceImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val createRemote = postService.createRemote(createPost)
|
|
||||||
return note to createRemote
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun buildEmojis(note: Note) = note.tag
|
private suspend fun buildEmojis(note: Note) = note.tag
|
||||||
.filterIsInstance<Emoji>()
|
.filterIsInstance<Emoji>()
|
||||||
.map {
|
.map {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.filter
|
package dev.usbharu.hideout.core.domain.model.filter
|
||||||
|
|
||||||
|
@Suppress("EnumEntryNameCase", "EnumNaming")
|
||||||
enum class FilterAction {
|
enum class FilterAction {
|
||||||
warn,
|
warn,
|
||||||
hide
|
hide
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.filter
|
package dev.usbharu.hideout.core.domain.model.filter
|
||||||
|
|
||||||
|
@Suppress("EnumEntryNameCase", "EnumNaming")
|
||||||
enum class FilterType {
|
enum class FilterType {
|
||||||
home,
|
home,
|
||||||
notifications,
|
notifications,
|
||||||
|
|
|
@ -89,6 +89,7 @@ data class Post private constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun pureRepostOf(
|
fun pureRepostOf(
|
||||||
id: Long,
|
id: Long,
|
||||||
actorId: Long,
|
actorId: Long,
|
||||||
|
@ -110,24 +111,25 @@ data class Post private constructor(
|
||||||
require(actorId >= 0) { "actorId must be greater than or equal to 0." }
|
require(actorId >= 0) { "actorId must be greater than or equal to 0." }
|
||||||
|
|
||||||
return Post(
|
return Post(
|
||||||
id,
|
id = id,
|
||||||
actorId,
|
actorId = actorId,
|
||||||
null,
|
overview = null,
|
||||||
"",
|
content = "",
|
||||||
"",
|
text = "",
|
||||||
createdAt.toEpochMilli(),
|
createdAt = createdAt.toEpochMilli(),
|
||||||
fixedVisibility,
|
visibility = fixedVisibility,
|
||||||
url,
|
url = url,
|
||||||
repost.id,
|
repostId = repost.id,
|
||||||
null,
|
replyId = null,
|
||||||
false,
|
sensitive = false,
|
||||||
apId,
|
apId = apId,
|
||||||
emptyList(),
|
mediaIds = emptyList(),
|
||||||
false,
|
delted = false,
|
||||||
emptyList()
|
emojiIds = emptyList()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun quoteRepostOf(
|
fun quoteRepostOf(
|
||||||
id: Long,
|
id: Long,
|
||||||
actorId: Long,
|
actorId: Long,
|
||||||
|
|
|
@ -28,14 +28,14 @@ class ExposedFilterRepository(private val idGenerateService: IdGenerateService)
|
||||||
it[id] = filter.id
|
it[id] = filter.id
|
||||||
it[userId] = filter.userId
|
it[userId] = filter.userId
|
||||||
it[name] = filter.name
|
it[name] = filter.name
|
||||||
it[context] = filter.context.joinToString(",") { it.name }
|
it[context] = filter.context.joinToString(",") { filterType -> filterType.name }
|
||||||
it[filterAction] = filter.filterAction.name
|
it[filterAction] = filter.filterAction.name
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Filters.update({ Filters.id eq filter.id }) {
|
Filters.update({ Filters.id eq filter.id }) {
|
||||||
it[userId] = filter.userId
|
it[userId] = filter.userId
|
||||||
it[name] = filter.name
|
it[name] = filter.name
|
||||||
it[context] = filter.context.joinToString(",") { it.name }
|
it[context] = filter.context.joinToString(",") { filterType -> filterType.name }
|
||||||
it[filterAction] = filter.filterAction.name
|
it[filterAction] = filter.filterAction.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ExposedFilterQueryService : FilterQueryService {
|
||||||
.map {
|
.map {
|
||||||
FilterQueryModel.of(
|
FilterQueryModel.of(
|
||||||
it.first().toFilter(),
|
it.first().toFilter(),
|
||||||
it.map { it.toFilterKeyword() }
|
it.map { resultRow -> resultRow.toFilterKeyword() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,14 @@ data class FilterQueryModel(
|
||||||
val keywords: List<FilterKeyword>
|
val keywords: List<FilterKeyword>
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@Suppress("FunctionMinLength")
|
||||||
fun of(filter: Filter, keywords: List<FilterKeyword>): FilterQueryModel = FilterQueryModel(
|
fun of(filter: Filter, keywords: List<FilterKeyword>): FilterQueryModel = FilterQueryModel(
|
||||||
filter.id,
|
id = filter.id,
|
||||||
filter.userId,
|
userId = filter.userId,
|
||||||
filter.name,
|
name = filter.name,
|
||||||
filter.context,
|
context = filter.context,
|
||||||
filter.filterAction,
|
filterAction = filter.filterAction,
|
||||||
keywords
|
keywords = keywords
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,32 @@
|
||||||
package dev.usbharu.hideout.mastodon.interfaces.api.filter
|
package dev.usbharu.hideout.mastodon.interfaces.api.filter
|
||||||
|
|
||||||
import dev.usbharu.hideout.controller.mastodon.generated.FilterApi
|
import dev.usbharu.hideout.controller.mastodon.generated.FilterApi
|
||||||
|
import dev.usbharu.hideout.core.infrastructure.springframework.security.LoginUserContextHolder
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
||||||
|
import dev.usbharu.hideout.mastodon.service.filter.MastodonFilterApiService
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
class MastodonFilterApiController : FilterApi {
|
class MastodonFilterApiController(
|
||||||
|
private val mastodonFilterApiService: MastodonFilterApiService,
|
||||||
|
private val loginUserContextHolder: LoginUserContextHolder
|
||||||
|
) : FilterApi {
|
||||||
|
|
||||||
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {
|
override suspend fun apiV1FiltersIdDelete(id: String): ResponseEntity<Any> {
|
||||||
return super.apiV1FiltersIdDelete(id)
|
mastodonFilterApiService.deleteV1FilterById(loginUserContextHolder.getLoginUserId(), id.toLong())
|
||||||
|
return ResponseEntity.ok().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1FiltersIdGet(
|
override suspend fun apiV1FiltersIdGet(
|
||||||
id: String
|
id: String
|
||||||
): ResponseEntity<V1Filter> {
|
): ResponseEntity<V1Filter> {
|
||||||
return super.apiV1FiltersIdGet(id)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.getV1FilterById(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
id.toLong()
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV1FiltersIdPut(
|
override suspend fun apiV1FiltersIdPut(
|
||||||
|
@ -25,35 +36,47 @@ class MastodonFilterApiController : FilterApi {
|
||||||
irreversible: Boolean?,
|
irreversible: Boolean?,
|
||||||
wholeWord: Boolean?,
|
wholeWord: Boolean?,
|
||||||
expiresIn: Int?
|
expiresIn: Int?
|
||||||
): ResponseEntity<V1Filter> {
|
): ResponseEntity<V1Filter> = super.apiV1FiltersIdPut(id, phrase, context, irreversible, wholeWord, expiresIn)
|
||||||
return super.apiV1FiltersIdPut(id, phrase, context, irreversible, wholeWord, expiresIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity<V1Filter> {
|
override suspend fun apiV1FiltersPost(v1FilterPostRequest: V1FilterPostRequest): ResponseEntity<V1Filter> {
|
||||||
return super.apiV1FiltersPost(v1FilterPostRequest)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.createByV1Filter(loginUserContextHolder.getLoginUserId(), v1FilterPostRequest)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersFilterIdKeywordsPost(
|
override suspend fun apiV2FiltersFilterIdKeywordsPost(
|
||||||
filterId: String,
|
filterId: String,
|
||||||
filterKeywordsPostRequest: FilterKeywordsPostRequest
|
filterKeywordsPostRequest: FilterKeywordsPostRequest
|
||||||
): ResponseEntity<FilterKeyword> {
|
): ResponseEntity<FilterKeyword> {
|
||||||
return super.apiV2FiltersFilterIdKeywordsPost(filterId, filterKeywordsPostRequest)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.addKeyword(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
filterId.toLong(),
|
||||||
|
filterKeywordsPostRequest
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersFilterIdStatusesPost(
|
override suspend fun apiV2FiltersFilterIdStatusesPost(
|
||||||
filterId: String,
|
filterId: String,
|
||||||
filterStatusRequest: FilterStatusRequest
|
filterStatusRequest: FilterStatusRequest
|
||||||
): ResponseEntity<FilterStatus> {
|
): ResponseEntity<FilterStatus> {
|
||||||
return super.apiV2FiltersFilterIdStatusesPost(filterId, filterStatusRequest)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.addFilterStatus(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
filterId.toLong(),
|
||||||
|
filterStatusRequest
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersIdDelete(id: String): ResponseEntity<Any> {
|
override suspend fun apiV2FiltersIdDelete(id: String): ResponseEntity<Any> {
|
||||||
return super.apiV2FiltersIdDelete(id)
|
mastodonFilterApiService.deleteById(loginUserContextHolder.getLoginUserId(), id.toLong())
|
||||||
|
return ResponseEntity.ok().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity<Filter> {
|
override suspend fun apiV2FiltersIdGet(id: String): ResponseEntity<Filter> =
|
||||||
return super.apiV2FiltersIdGet(id)
|
ResponseEntity.ok(mastodonFilterApiService.getById(loginUserContextHolder.getLoginUserId(), id.toLong()))
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun apiV2FiltersIdPut(
|
override suspend fun apiV2FiltersIdPut(
|
||||||
id: String,
|
id: String,
|
||||||
|
@ -62,16 +85,21 @@ class MastodonFilterApiController : FilterApi {
|
||||||
filterAction: String?,
|
filterAction: String?,
|
||||||
expiresIn: Int?,
|
expiresIn: Int?,
|
||||||
keywordsAttributes: List<FilterPubRequestKeyword>?
|
keywordsAttributes: List<FilterPubRequestKeyword>?
|
||||||
): ResponseEntity<Filter> {
|
): ResponseEntity<Filter> =
|
||||||
return super.apiV2FiltersIdPut(id, title, context, filterAction, expiresIn, keywordsAttributes)
|
super.apiV2FiltersIdPut(id, title, context, filterAction, expiresIn, keywordsAttributes)
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun apiV2FiltersKeywordsIdDelete(id: String): ResponseEntity<Any> {
|
override suspend fun apiV2FiltersKeywordsIdDelete(id: String): ResponseEntity<Any> {
|
||||||
return super.apiV2FiltersKeywordsIdDelete(id)
|
mastodonFilterApiService.deleteKeyword(loginUserContextHolder.getLoginUserId(), id.toLong())
|
||||||
|
return ResponseEntity.ok().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersKeywordsIdGet(id: String): ResponseEntity<FilterKeyword> {
|
override suspend fun apiV2FiltersKeywordsIdGet(id: String): ResponseEntity<FilterKeyword> {
|
||||||
return super.apiV2FiltersKeywordsIdGet(id)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.getKeywordById(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
id.toLong()
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersKeywordsIdPut(
|
override suspend fun apiV2FiltersKeywordsIdPut(
|
||||||
|
@ -79,19 +107,27 @@ class MastodonFilterApiController : FilterApi {
|
||||||
keyword: String?,
|
keyword: String?,
|
||||||
wholeWord: Boolean?,
|
wholeWord: Boolean?,
|
||||||
regex: Boolean?
|
regex: Boolean?
|
||||||
): ResponseEntity<FilterKeyword> {
|
): ResponseEntity<FilterKeyword> = super.apiV2FiltersKeywordsIdPut(id, keyword, wholeWord, regex)
|
||||||
return super.apiV2FiltersKeywordsIdPut(id, keyword, wholeWord, regex)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity<Filter> {
|
override suspend fun apiV2FiltersPost(filterPostRequest: FilterPostRequest): ResponseEntity<Filter> =
|
||||||
return super.apiV2FiltersPost(filterPostRequest)
|
ResponseEntity.ok(
|
||||||
}
|
mastodonFilterApiService.createFilter(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
filterPostRequest
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
override suspend fun apiV2FiltersStatusesIdDelete(id: String): ResponseEntity<Any> {
|
override suspend fun apiV2FiltersStatusesIdDelete(id: String): ResponseEntity<Any> {
|
||||||
return super.apiV2FiltersStatusesIdDelete(id)
|
mastodonFilterApiService.deleteFilterStatusById(loginUserContextHolder.getLoginUserId(), id.toLong())
|
||||||
|
return ResponseEntity.ok().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun apiV2FiltersStatusesIdGet(id: String): ResponseEntity<FilterStatus> {
|
override suspend fun apiV2FiltersStatusesIdGet(id: String): ResponseEntity<FilterStatus> {
|
||||||
return super.apiV2FiltersStatusesIdGet(id)
|
return ResponseEntity.ok(
|
||||||
|
mastodonFilterApiService.getFilterStatusById(
|
||||||
|
loginUserContextHolder.getLoginUserId(),
|
||||||
|
id.toLong()
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import kotlin.math.min
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
interface AccountApiService {
|
interface AccountApiService {
|
||||||
|
|
||||||
@Suppress("ongParameterList")
|
@Suppress("LongParameterList")
|
||||||
suspend fun accountsStatuses(
|
suspend fun accountsStatuses(
|
||||||
userid: Long,
|
userid: Long,
|
||||||
onlyMedia: Boolean,
|
onlyMedia: Boolean,
|
||||||
|
|
|
@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.emptyFlow
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
interface MastodonFilterApiService {
|
interface MastodonFilterApiService {
|
||||||
fun v1Filters(userId: Long): Flow<V1Filter>
|
fun v1Filters(userId: Long): Flow<V1Filter>
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ interface MastodonFilterApiService {
|
||||||
|
|
||||||
fun filterStatuses(userId: Long, filterId: Long): Flow<FilterStatus>
|
fun filterStatuses(userId: Long, filterId: Long): Flow<FilterStatus>
|
||||||
|
|
||||||
suspend fun addFilterStatus(userId: Long, filterId: Long, filterStatusRequest: FilterStatusRequest)
|
suspend fun addFilterStatus(userId: Long, filterId: Long, filterStatusRequest: FilterStatusRequest): FilterStatus
|
||||||
|
|
||||||
fun filters(userId: Long): Flow<Filter>
|
fun filters(userId: Long): Flow<Filter>
|
||||||
|
|
||||||
|
@ -65,8 +66,8 @@ class MastodonFilterApiServiceImpl(
|
||||||
V1Filter(
|
V1Filter(
|
||||||
id = it.id.toString(),
|
id = it.id.toString(),
|
||||||
phrase = it.keyword,
|
phrase = it.keyword,
|
||||||
context = filterQueryModel.context.map {
|
context = filterQueryModel.context.map { filterType ->
|
||||||
when (it) {
|
when (filterType) {
|
||||||
home -> Context.home
|
home -> Context.home
|
||||||
notifications -> Context.notifications
|
notifications -> Context.notifications
|
||||||
public -> Context.public
|
public -> Context.public
|
||||||
|
@ -178,19 +179,20 @@ class MastodonFilterApiServiceImpl(
|
||||||
return toFilterKeyword(filterKeyword)
|
return toFilterKeyword(filterKeyword)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun filterStatuses(userId: Long, filterId: Long): Flow<FilterStatus> {
|
override fun filterStatuses(userId: Long, filterId: Long): Flow<FilterStatus> = emptyFlow()
|
||||||
return emptyFlow()
|
|
||||||
|
override suspend fun addFilterStatus(
|
||||||
|
userId: Long,
|
||||||
|
filterId: Long,
|
||||||
|
filterStatusRequest: FilterStatusRequest
|
||||||
|
): FilterStatus {
|
||||||
|
TODO()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addFilterStatus(userId: Long, filterId: Long, filterStatusRequest: FilterStatusRequest) {
|
override fun filters(userId: Long): Flow<Filter> =
|
||||||
return
|
runBlocking { filterQueryService.findByUserId(userId) }.map { filterQueryModel ->
|
||||||
}
|
|
||||||
|
|
||||||
override fun filters(userId: Long): Flow<Filter> {
|
|
||||||
return runBlocking { filterQueryService.findByUserId(userId) }.map { filterQueryModel ->
|
|
||||||
toFilter(filterQueryModel)
|
toFilter(filterQueryModel)
|
||||||
}.asFlow()
|
}.asFlow()
|
||||||
}
|
|
||||||
|
|
||||||
private fun toFilter(filterQueryModel: FilterQueryModel) = Filter(
|
private fun toFilter(filterQueryModel: FilterQueryModel) = Filter(
|
||||||
id = filterQueryModel.id.toString(),
|
id = filterQueryModel.id.toString(),
|
||||||
|
@ -221,9 +223,8 @@ class MastodonFilterApiServiceImpl(
|
||||||
it.mode == FilterMode.WHOLE_WORD
|
it.mode == FilterMode.WHOLE_WORD
|
||||||
)
|
)
|
||||||
|
|
||||||
override suspend fun deleteById(userId: Long, filterId: Long) {
|
override suspend fun deleteById(userId: Long, filterId: Long) =
|
||||||
filterRepository.deleteByUserIdAndId(userId, filterId)
|
filterRepository.deleteByUserIdAndId(userId, filterId)
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getById(userId: Long, filterId: Long): Filter? =
|
override suspend fun getById(userId: Long, filterId: Long): Filter? =
|
||||||
filterQueryService.findByUserIdAndId(userId, filterId)?.let { toFilter(it) }
|
filterQueryService.findByUserIdAndId(userId, filterId)?.let { toFilter(it) }
|
||||||
|
@ -278,11 +279,7 @@ class MastodonFilterApiServiceImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteFilterStatusById(userId: Long, filterPostsId: Long) {
|
override suspend fun deleteFilterStatusById(userId: Long, filterPostsId: Long) = Unit
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getFilterStatusById(userId: Long, filterPostsId: Long): FilterStatus? {
|
override suspend fun getFilterStatusById(userId: Long, filterPostsId: Long): FilterStatus? = null
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue