mirror of https://github.com/usbharu/Hideout.git
Merge pull request #93 from usbharu/feature/enhanced-timeline
feat: タイムラインにメディア情報と純粋なリポスト日の情報を追加
This commit is contained in:
commit
2eca02e1c3
|
@ -5,6 +5,7 @@ build:
|
|||
MagicNumber: 0
|
||||
InjectDispatcher: 0
|
||||
EnumEntryNameCase: 0
|
||||
ReplaceSafeCallChainWithRun: 0
|
||||
|
||||
style:
|
||||
ClassOrdering:
|
||||
|
|
|
@ -17,7 +17,9 @@ class NoteApControllerImpl(private val noteApApiService: NoteApApiService) : Not
|
|||
@CurrentSecurityContext context: SecurityContext
|
||||
): ResponseEntity<Note> {
|
||||
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
|
||||
} else {
|
||||
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 visibility: Visibility,
|
||||
val sensitive: Boolean,
|
||||
val isLocal: Boolean
|
||||
val isLocal: Boolean,
|
||||
val isPureRepost: Boolean = false,
|
||||
val mediaIds: List<Long> = emptyList()
|
||||
)
|
||||
|
|
|
@ -21,7 +21,6 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository) : NoteQue
|
|||
.leftJoin(Media)
|
||||
.select { Posts.id eq id }
|
||||
.let { it.toNote() to it.toPost().first() }
|
||||
|
||||
}
|
||||
|
||||
private suspend fun ResultRow.toNote(mediaList: List<dev.usbharu.hideout.domain.model.hideout.entity.Media>): Note {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package dev.usbharu.hideout.query.mastodon
|
||||
|
||||
import dev.usbharu.hideout.domain.mastodon.model.generated.Status
|
||||
import dev.usbharu.hideout.domain.model.hideout.dto.StatusQuery
|
||||
|
||||
interface StatusQueryService {
|
||||
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.Status
|
||||
import dev.usbharu.hideout.domain.model.hideout.dto.FileType
|
||||
import dev.usbharu.hideout.domain.model.hideout.dto.StatusQuery
|
||||
import dev.usbharu.hideout.repository.*
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.innerJoin
|
||||
|
@ -16,6 +17,46 @@ class StatusQueryServiceImpl : StatusQueryService {
|
|||
@Suppress("LongMethod")
|
||||
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")
|
||||
private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> {
|
||||
val pairs = Posts
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.usbharu.hideout.service.post
|
||||
|
||||
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.query.mastodon.StatusQueryService
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
|
@ -50,6 +51,15 @@ class MongoGenerateTimelineService(
|
|||
|
||||
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,
|
||||
visibility = post.visibility,
|
||||
sensitive = post.sensitive,
|
||||
isLocal = isLocal
|
||||
isLocal = isLocal,
|
||||
isPureRepost = post.repostId == null || (post.text.isBlank() && post.overview.isNullOrBlank()),
|
||||
mediaIds = post.mediaIds
|
||||
)
|
||||
}.toMutableList()
|
||||
if (post.visibility == Visibility.PUBLIC) {
|
||||
|
@ -49,7 +51,9 @@ class TimelineService(
|
|||
repostId = post.repostId,
|
||||
visibility = post.visibility,
|
||||
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 {
|
||||
httpSignatureHeaderParser.parse(HttpHeaders(headers))
|
||||
} catch (e: IllegalArgumentException) {
|
||||
} catch (_: IllegalArgumentException) {
|
||||
return null
|
||||
} catch (e: RuntimeException) {
|
||||
} catch (_: RuntimeException) {
|
||||
return ""
|
||||
}
|
||||
return signature.keyId
|
||||
|
|
Loading…
Reference in New Issue