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