diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt index 5c6c56f4..42586a73 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt @@ -22,16 +22,53 @@ class TimelineObject( val postCreatedAt: Instant, val replyId: PostId?, val repostId: PostId?, - val visibility: Visibility, - val isPureRepost: Boolean, - val mediaIds: List, - val emojiIds: List, - val visibleActors: List, - val hasMedia: Boolean, - val hasMediaInRepost: Boolean, - val lastUpdatedAt: Instant, - val warnFilters: List, -) { + visibility: Visibility, + isPureRepost: Boolean, + mediaIds: List, + emojiIds: List, + visibleActors: List, + hasMediaInRepost: Boolean, + lastUpdatedAt: Instant, + var warnFilters: List, + + ) { + 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) { + 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) { + 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) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt index 4656d30a..6c3331fe 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt @@ -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) + suspend fun removeTimeline(timeline: Timeline) } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt index a06a217b..00ac8985 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/AbstractTimelineStore.kt @@ -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) + + protected abstract suspend fun getTimelineObjectByPostId(postId: PostId): List + + 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) { + TODO("Not yet implemented") + } + + override suspend fun removeTimeline(timeline: Timeline) { + TODO("Not yet implemented") + } } \ No newline at end of file