feat: AbstractTimelineStoreを作成

This commit is contained in:
usbharu 2024-07-14 16:21:56 +09:00
parent 0d39e779c4
commit 0143038707
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
5 changed files with 70 additions and 4 deletions

View File

@ -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
)

View File

@ -0,0 +1,4 @@
package dev.usbharu.hideout.core.domain.model.timelinerelationship
@JvmInline
value class TimelineRelationshipId(val value: Long)

View File

@ -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)
}

View File

@ -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)
}
protected abstract suspend fun getFollowers(actorId: ActorId): List<ActorId>
insertTimelineObject(timelineObjectList)
}
protected abstract suspend fun getTimeline(actorId: ActorId): List<Timeline>
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<Filter>
protected abstract suspend fun applyFilters(post: Post, filters: List<Filter>): FilteredPost
protected abstract suspend fun getPost(postId: PostId): Post?
protected abstract suspend fun insertTimelineObject(timelineObjectList: List<TimelineObject>)
}

View File

@ -9,7 +9,7 @@ open class DefaultTimelineStore(
private val timelineRepository: TimelineRepository,
private val relationshipRepository: RelationshipRepository
) : AbstractTimelineStore() {
override suspend fun getFollowers(actorId: ActorId): List<ActorId> {
override suspend fun getTimeline(actorId: ActorId): List<ActorId> {
return relationshipRepository
.findByTargetId(
actorId, FindRelationshipOption(follow = true, mute = false),