From 0143038707200cb44cf0faaa706be030ae6b72d6 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:21:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20AbstractTimelineStore=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimelineRelationship.kt | 10 ++++ .../TimelineRelationshipId.kt | 4 ++ .../TimelineRelationshipRepository.kt | 6 +++ .../timeline/AbstractTimelineStore.kt | 52 +++++++++++++++++-- .../timeline/DefaultTimelineStore.kt | 2 +- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt new file mode 100644 index 00000000..39e3eae6 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationship.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.core.domain.model.timelinerelationship + +import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.timeline.TimelineId + +class TimelineRelationship( + val timelineRelationshipId: TimelineRelationshipId, + val timelineId: TimelineId, + val actorId: ActorId +) \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt new file mode 100644 index 00000000..5de526a7 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipId.kt @@ -0,0 +1,4 @@ +package dev.usbharu.hideout.core.domain.model.timelinerelationship + +@JvmInline +value class TimelineRelationshipId(val value: Long) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt new file mode 100644 index 00000000..520d6e88 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelinerelationship/TimelineRelationshipRepository.kt @@ -0,0 +1,6 @@ +package dev.usbharu.hideout.core.domain.model.timelinerelationship + +interface TimelineRelationshipRepository { + suspend fun save(timelineRelationship: TimelineRelationship): TimelineRelationship + suspend fun delete(timelineRelationship: TimelineRelationship) +} \ 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 43db5447..a06a217b 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 @@ -1,14 +1,60 @@ package dev.usbharu.hideout.core.infrastructure.timeline import dev.usbharu.hideout.core.domain.model.actor.ActorId +import dev.usbharu.hideout.core.domain.model.filter.Filter +import dev.usbharu.hideout.core.domain.model.filter.FilteredPost import dev.usbharu.hideout.core.domain.model.post.Post +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.userdetails.UserDetailId +import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService import dev.usbharu.hideout.core.external.timeline.TimelineStore -abstract class AbstractTimelineStore() : TimelineStore { +abstract class AbstractTimelineStore(private val idGenerateService: IdGenerateService) : TimelineStore { override suspend fun newPost(post: Post) { - getFollowers(post.actorId) + val timelineList = getTimeline(post.actorId) + + val repost = post.repostId?.let { getPost(it) } + + val timelineObjectList = timelineList.map { + createTimelineObject(post, repost, it) + } + + insertTimelineObject(timelineObjectList) } - protected abstract suspend fun getFollowers(actorId: ActorId): List + protected abstract suspend fun getTimeline(actorId: ActorId): List + protected suspend fun createTimelineObject(post: Post, repost: Post?, timeline: Timeline): TimelineObject { + val filters = getFilters(timeline.userDetailId) + + val applyFilters = applyFilters(post, filters) + + if (repost != null) { + return TimelineObject.create( + TimelineObjectId(idGenerateService.generateId()), + timeline, + post, + repost, + applyFilters.filterResults + ) + } + + return TimelineObject.create( + TimelineObjectId(idGenerateService.generateId()), + timeline, + post, + applyFilters.filterResults + ) + } + + protected abstract suspend fun getFilters(userDetailId: UserDetailId): List + + protected abstract suspend fun applyFilters(post: Post, filters: List): FilteredPost + + protected abstract suspend fun getPost(postId: PostId): Post? + + protected abstract suspend fun insertTimelineObject(timelineObjectList: List) } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt index fd5779a5..5d09c399 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/timeline/DefaultTimelineStore.kt @@ -9,7 +9,7 @@ open class DefaultTimelineStore( private val timelineRepository: TimelineRepository, private val relationshipRepository: RelationshipRepository ) : AbstractTimelineStore() { - override suspend fun getFollowers(actorId: ActorId): List { + override suspend fun getTimeline(actorId: ActorId): List { return relationshipRepository .findByTargetId( actorId, FindRelationshipOption(follow = true, mute = false),