mirror of https://github.com/usbharu/Hideout.git
Merge branch 'develop' into feature/entity-builder
This commit is contained in:
commit
9065db5f44
|
@ -5,6 +5,7 @@ build:
|
||||||
MagicNumber: 0
|
MagicNumber: 0
|
||||||
InjectDispatcher: 0
|
InjectDispatcher: 0
|
||||||
EnumEntryNameCase: 0
|
EnumEntryNameCase: 0
|
||||||
|
ReplaceSafeCallChainWithRun: 0
|
||||||
|
|
||||||
style:
|
style:
|
||||||
ClassOrdering:
|
ClassOrdering:
|
||||||
|
|
|
@ -17,7 +17,9 @@ class NoteApControllerImpl(private val noteApApiService: NoteApApiService) : Not
|
||||||
@CurrentSecurityContext context: SecurityContext
|
@CurrentSecurityContext context: SecurityContext
|
||||||
): ResponseEntity<Note> {
|
): ResponseEntity<Note> {
|
||||||
val userId =
|
val userId =
|
||||||
if (context.authentication is PreAuthenticatedAuthenticationToken && context.authentication.details is HttpSignatureUser) {
|
if (context.authentication is PreAuthenticatedAuthenticationToken &&
|
||||||
|
context.authentication.details is HttpSignatureUser
|
||||||
|
) {
|
||||||
(context.authentication.details as HttpSignatureUser).id
|
(context.authentication.details as HttpSignatureUser).id
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package dev.usbharu.hideout.domain.model.hideout.dto
|
||||||
|
|
||||||
|
data class StatusQuery(
|
||||||
|
val postId: Long,
|
||||||
|
val replyId: Long?,
|
||||||
|
val repostId: Long?,
|
||||||
|
val mediaIds: List<Long>
|
||||||
|
)
|
|
@ -16,5 +16,7 @@ data class Timeline(
|
||||||
val repostId: Long?,
|
val repostId: Long?,
|
||||||
val visibility: Visibility,
|
val visibility: Visibility,
|
||||||
val sensitive: Boolean,
|
val sensitive: Boolean,
|
||||||
val isLocal: Boolean
|
val isLocal: Boolean,
|
||||||
|
val isPureRepost: Boolean = false,
|
||||||
|
val mediaIds: List<Long> = emptyList()
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.usbharu.hideout.query.mastodon
|
package dev.usbharu.hideout.query.mastodon
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||||
|
import dev.usbharu.hideout.domain.model.hideout.dto.StatusQuery
|
||||||
|
|
||||||
interface StatusQueryService {
|
interface StatusQueryService {
|
||||||
suspend fun findByPostIds(ids: List<Long>): List<Status>
|
suspend fun findByPostIds(ids: List<Long>): List<Status>
|
||||||
|
suspend fun findByPostIdsWithMediaIds(statusQueries: List<StatusQuery>): List<Status>
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Account
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.MediaAttachment
|
import dev.usbharu.hideout.domain.mastodon.model.generated.MediaAttachment
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||||
import dev.usbharu.hideout.domain.model.hideout.dto.FileType
|
import dev.usbharu.hideout.domain.model.hideout.dto.FileType
|
||||||
|
import dev.usbharu.hideout.domain.model.hideout.dto.StatusQuery
|
||||||
import dev.usbharu.hideout.repository.*
|
import dev.usbharu.hideout.repository.*
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.innerJoin
|
import org.jetbrains.exposed.sql.innerJoin
|
||||||
|
@ -16,6 +17,46 @@ class StatusQueryServiceImpl : StatusQueryService {
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
override suspend fun findByPostIds(ids: List<Long>): List<Status> = findByPostIdsWithMediaAttachments(ids)
|
override suspend fun findByPostIds(ids: List<Long>): List<Status> = findByPostIdsWithMediaAttachments(ids)
|
||||||
|
|
||||||
|
override suspend fun findByPostIdsWithMediaIds(statusQueries: List<StatusQuery>): List<Status> {
|
||||||
|
val postIdSet = mutableSetOf<Long>()
|
||||||
|
postIdSet.addAll(statusQueries.flatMap { listOfNotNull(it.postId, it.replyId, it.repostId) })
|
||||||
|
val mediaIdSet = mutableSetOf<Long>()
|
||||||
|
mediaIdSet.addAll(statusQueries.flatMap { it.mediaIds })
|
||||||
|
val postMap = Posts
|
||||||
|
.leftJoin(Users)
|
||||||
|
.select { Posts.id inList postIdSet }
|
||||||
|
.associate { it[Posts.id] to toStatus(it) }
|
||||||
|
val mediaMap = Media.select { Media.id inList mediaIdSet }
|
||||||
|
.associate {
|
||||||
|
it[Media.id] to it.toMedia().let {
|
||||||
|
MediaAttachment(
|
||||||
|
id = it.id.toString(),
|
||||||
|
type = when (it.type) {
|
||||||
|
FileType.Image -> MediaAttachment.Type.image
|
||||||
|
FileType.Video -> MediaAttachment.Type.video
|
||||||
|
FileType.Audio -> MediaAttachment.Type.audio
|
||||||
|
FileType.Unknown -> MediaAttachment.Type.unknown
|
||||||
|
},
|
||||||
|
url = it.url,
|
||||||
|
previewUrl = it.thumbnailUrl,
|
||||||
|
remoteUrl = it.remoteUrl,
|
||||||
|
description = "",
|
||||||
|
blurhash = it.blurHash,
|
||||||
|
textUrl = it.url
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return statusQueries.mapNotNull {
|
||||||
|
postMap[it.postId]?.copy(
|
||||||
|
inReplyToId = it.replyId?.toString(),
|
||||||
|
inReplyToAccountId = postMap[it.replyId]?.account?.id,
|
||||||
|
reblog = postMap[it.repostId],
|
||||||
|
mediaAttachments = it.mediaIds.mapNotNull { mediaMap[it] }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> {
|
private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> {
|
||||||
val pairs = Posts
|
val pairs = Posts
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package dev.usbharu.hideout.service.post
|
package dev.usbharu.hideout.service.post
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||||
|
import dev.usbharu.hideout.domain.model.hideout.dto.StatusQuery
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Timeline
|
import dev.usbharu.hideout.domain.model.hideout.entity.Timeline
|
||||||
import dev.usbharu.hideout.query.mastodon.StatusQueryService
|
import dev.usbharu.hideout.query.mastodon.StatusQueryService
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
|
@ -50,6 +51,15 @@ class MongoGenerateTimelineService(
|
||||||
|
|
||||||
val timelines = mongoTemplate.find(query, Timeline::class.java)
|
val timelines = mongoTemplate.find(query, Timeline::class.java)
|
||||||
|
|
||||||
return statusQueryService.findByPostIds(timelines.flatMap { setOfNotNull(it.postId, it.replyId, it.repostId) })
|
return statusQueryService.findByPostIdsWithMediaIds(
|
||||||
|
timelines.map {
|
||||||
|
StatusQuery(
|
||||||
|
it.postId,
|
||||||
|
it.replyId,
|
||||||
|
it.repostId,
|
||||||
|
it.mediaIds
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@ class TimelineService(
|
||||||
repostId = post.repostId,
|
repostId = post.repostId,
|
||||||
visibility = post.visibility,
|
visibility = post.visibility,
|
||||||
sensitive = post.sensitive,
|
sensitive = post.sensitive,
|
||||||
isLocal = isLocal
|
isLocal = isLocal,
|
||||||
|
isPureRepost = post.repostId == null || (post.text.isBlank() && post.overview.isNullOrBlank()),
|
||||||
|
mediaIds = post.mediaIds
|
||||||
)
|
)
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
if (post.visibility == Visibility.PUBLIC) {
|
if (post.visibility == Visibility.PUBLIC) {
|
||||||
|
@ -49,7 +51,9 @@ class TimelineService(
|
||||||
repostId = post.repostId,
|
repostId = post.repostId,
|
||||||
visibility = post.visibility,
|
visibility = post.visibility,
|
||||||
sensitive = post.sensitive,
|
sensitive = post.sensitive,
|
||||||
isLocal = isLocal
|
isLocal = isLocal,
|
||||||
|
isPureRepost = post.repostId == null || (post.text.isBlank() && post.overview.isNullOrBlank()),
|
||||||
|
mediaIds = post.mediaIds
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ class HttpSignatureFilter(private val httpSignatureHeaderParser: SignatureHeader
|
||||||
|
|
||||||
val signature = try {
|
val signature = try {
|
||||||
httpSignatureHeaderParser.parse(HttpHeaders(headers))
|
httpSignatureHeaderParser.parse(HttpHeaders(headers))
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (_: IllegalArgumentException) {
|
||||||
return null
|
return null
|
||||||
} catch (e: RuntimeException) {
|
} catch (_: RuntimeException) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return signature.keyId
|
return signature.keyId
|
||||||
|
|
Loading…
Reference in New Issue