mirror of https://github.com/usbharu/Hideout.git
refactor: タイムラインの実装方式を変更
This commit is contained in:
parent
a4a3f4c0c4
commit
0d39e779c4
|
@ -22,7 +22,11 @@ interface RelationshipRepository {
|
||||||
suspend fun save(relationship: Relationship): Relationship
|
suspend fun save(relationship: Relationship): Relationship
|
||||||
suspend fun delete(relationship: Relationship)
|
suspend fun delete(relationship: Relationship)
|
||||||
suspend fun findByActorIdAndTargetId(actorId: ActorId, targetId: ActorId): Relationship?
|
suspend fun findByActorIdAndTargetId(actorId: ActorId, targetId: ActorId): Relationship?
|
||||||
suspend fun findByTargetId(targetId: ActorId, option: FindRelationshipOption? = null): List<Relationship>
|
suspend fun findByTargetId(
|
||||||
|
targetId: ActorId,
|
||||||
|
option: FindRelationshipOption? = null,
|
||||||
|
inverseOption: FindRelationshipOption? = null
|
||||||
|
): List<Relationship>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,11 +67,19 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve
|
||||||
}.singleOrNull()?.toRelationships()
|
}.singleOrNull()?.toRelationships()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTargetId(targetId: ActorId, option: FindRelationshipOption?): List<Relationship> {
|
override suspend fun findByTargetId(
|
||||||
val query = Relationships.selectAll().where {
|
targetId: ActorId,
|
||||||
|
option: FindRelationshipOption?,
|
||||||
|
inverseOption: FindRelationshipOption?
|
||||||
|
): List<Relationship> {
|
||||||
|
val query1 = Relationships.selectAll().where { Relationships.actorId eq targetId.id }
|
||||||
|
inverseOption.apply(query1)
|
||||||
|
//todo 逆のほうがいいかも
|
||||||
|
val query = query1.alias("INV").selectAll().where {
|
||||||
Relationships.targetActorId eq targetId.id
|
Relationships.targetActorId eq targetId.id
|
||||||
}
|
}
|
||||||
option.apply(query)
|
option.apply(query)
|
||||||
|
|
||||||
return query.map(ResultRow::toRelationships)
|
return query.map(ResultRow::toRelationships)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.timeline
|
package dev.usbharu.hideout.core.infrastructure.timeline
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.FindRelationshipOption
|
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
|
||||||
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
|
||||||
import dev.usbharu.hideout.core.external.timeline.TimelineStore
|
import dev.usbharu.hideout.core.external.timeline.TimelineStore
|
||||||
|
|
||||||
abstract class AbstractTimelineStore(
|
abstract class AbstractTimelineStore() : TimelineStore {
|
||||||
private val timelineRepository: TimelineRepository,
|
|
||||||
private val relationshipRepository: RelationshipRepository
|
|
||||||
) :
|
|
||||||
TimelineStore {
|
|
||||||
override suspend fun newPost(post: Post) {
|
override suspend fun newPost(post: Post) {
|
||||||
relationshipRepository.findByTargetId(post.actorId, FindRelationshipOption(follow = true, mute = false))
|
getFollowers(post.actorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract suspend fun getFollowers(actorId: ActorId): List<ActorId>
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package dev.usbharu.hideout.core.infrastructure.timeline
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||||
|
import dev.usbharu.hideout.core.domain.model.relationship.FindRelationshipOption
|
||||||
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
|
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
||||||
|
|
||||||
|
open class DefaultTimelineStore(
|
||||||
|
private val timelineRepository: TimelineRepository,
|
||||||
|
private val relationshipRepository: RelationshipRepository
|
||||||
|
) : AbstractTimelineStore() {
|
||||||
|
override suspend fun getFollowers(actorId: ActorId): List<ActorId> {
|
||||||
|
return relationshipRepository
|
||||||
|
.findByTargetId(
|
||||||
|
actorId, FindRelationshipOption(follow = true, mute = false),
|
||||||
|
FindRelationshipOption(block = false)
|
||||||
|
)
|
||||||
|
.map { it.actorId }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue