feat: タイムラインを実装

This commit is contained in:
usbharu 2024-07-15 17:30:28 +09:00
parent 5303b13b08
commit b4c62fbd43
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
3 changed files with 98 additions and 14 deletions

View File

@ -22,16 +22,53 @@ class TimelineObject(
val postCreatedAt: Instant,
val replyId: PostId?,
val repostId: PostId?,
val visibility: Visibility,
val isPureRepost: Boolean,
val mediaIds: List<MediaId>,
val emojiIds: List<EmojiId>,
val visibleActors: List<ActorId>,
val hasMedia: Boolean,
val hasMediaInRepost: Boolean,
val lastUpdatedAt: Instant,
val warnFilters: List<TimelineObjectWarnFilter>,
) {
visibility: Visibility,
isPureRepost: Boolean,
mediaIds: List<MediaId>,
emojiIds: List<EmojiId>,
visibleActors: List<ActorId>,
hasMediaInRepost: Boolean,
lastUpdatedAt: Instant,
var warnFilters: List<TimelineObjectWarnFilter>,
) {
var isPureRepost = isPureRepost
private set
var visibleActors = visibleActors
private set
var hasMediaInRepost = hasMediaInRepost
private set
val hasMedia
get() = mediaIds.isNotEmpty()
var lastUpdatedAt = lastUpdatedAt
private set
var visibility = visibility
private set
var mediaIds = mediaIds
private set
var emojiIds = emojiIds
private set
fun updateWith(post: Post, filterResults: List<FilterResult>) {
visibleActors = post.visibleActors.toList()
visibility = post.visibility
mediaIds = post.mediaIds.toList()
emojiIds = post.emojiIds.toList()
lastUpdatedAt = Instant.now()
isPureRepost =
post.repostId != null && post.replyId == null && post.text.isEmpty() && post.overview?.overview.isNullOrEmpty()
warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) }
}
fun updateWith(post: Post, repost: Post, filterResults: List<FilterResult>) {
require(repost.id == post.repostId)
require(repostId == post.repostId)
updateWith(post, filterResults)
hasMediaInRepost = repost.mediaIds.isNotEmpty()
}
companion object {
fun create(
@ -54,7 +91,6 @@ class TimelineObject(
mediaIds = post.mediaIds,
emojiIds = post.emojiIds,
visibleActors = post.visibleActors.toList(),
hasMedia = post.mediaIds.isNotEmpty(),
hasMediaInRepost = false,
lastUpdatedAt = Instant.now(),
warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) }
@ -88,7 +124,6 @@ class TimelineObject(
mediaIds = post.mediaIds,
emojiIds = post.emojiIds,
visibleActors = post.visibleActors.toList(),
hasMedia = post.mediaIds.isNotEmpty(),
hasMediaInRepost = repost.mediaIds.isNotEmpty(),
lastUpdatedAt = Instant.now(),
warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) }

View File

@ -1,7 +1,15 @@
package dev.usbharu.hideout.core.external.timeline
import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship
interface TimelineStore {
suspend fun newPost(post: Post)
suspend fun addPost(post: Post)
suspend fun updatePost(post: Post)
suspend fun removePost(post: Post)
suspend fun addTimelineRelationship(timelineRelationship: TimelineRelationship)
suspend fun removeTimelineRelationship(timelineRelationship: TimelineRelationship)
suspend fun addTimeline(timeline: Timeline, timelineRelationshipList: List<TimelineRelationship>)
suspend fun removeTimeline(timeline: Timeline)
}

View File

@ -8,12 +8,13 @@ import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
import dev.usbharu.hideout.core.domain.model.timelineobject.TimelineObject
import dev.usbharu.hideout.core.domain.model.timelineobject.TimelineObjectId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import dev.usbharu.hideout.core.external.timeline.TimelineStore
abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateService) : TimelineStore {
override suspend fun newPost(post: Post) {
override suspend fun addPost(post: Post) {
val timelineList = getTimeline(post.actorId)
val repost = post.repostId?.let { getPost(it) }
@ -57,4 +58,44 @@ abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateSe
protected abstract suspend fun getPost(postId: PostId): Post?
protected abstract suspend fun insertTimelineObject(timelineObjectList: List<TimelineObject>)
protected abstract suspend fun getTimelineObjectByPostId(postId: PostId): List<TimelineObject>
protected abstract suspend fun removeTimelineObject(postId: PostId)
override suspend fun updatePost(post: Post) {
val timelineObjectByPostId = getTimelineObjectByPostId(post.id)
val repost = post.repostId?.let { getPost(it) }
if (repost != null) {
timelineObjectByPostId.map {
val filters = getFilters(it.userDetailId)
val applyFilters = applyFilters(post, filters)
it.updateWith(post, repost, applyFilters.filterResults)
}
}
}
override suspend fun removePost(post: Post) {
TODO("Not yet implemented")
}
override suspend fun addTimelineRelationship(timelineRelationship: TimelineRelationship) {
TODO("Not yet implemented")
}
override suspend fun removeTimelineRelationship(timelineRelationship: TimelineRelationship) {
TODO("Not yet implemented")
}
override suspend fun addTimeline(timeline: Timeline, timelineRelationshipList: List<TimelineRelationship>) {
TODO("Not yet implemented")
}
override suspend fun removeTimeline(timeline: Timeline) {
TODO("Not yet implemented")
}
}