mirror of https://github.com/usbharu/Hideout.git
feat: AbstractTimelineStoreを作成
This commit is contained in:
parent
0d39e779c4
commit
0143038707
|
@ -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
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
package dev.usbharu.hideout.core.domain.model.timelinerelationship
|
||||
|
||||
@JvmInline
|
||||
value class TimelineRelationshipId(val value: Long)
|
|
@ -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)
|
||||
}
|
|
@ -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<ActorId>
|
||||
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>)
|
||||
}
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue