mirror of https://github.com/usbharu/Hideout.git
feat: タイムラインにメディア情報と純粋なリポスト日の情報を追加
This commit is contained in:
parent
fdc14444b6
commit
95037fd77d
|
@ -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,13 @@ 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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue