mirror of https://github.com/usbharu/Hideout.git
refactor: タイムラインの実装方式を変更
This commit is contained in:
parent
faee779cfb
commit
a4a3f4c0c4
|
@ -22,6 +22,7 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.Role
|
import dev.usbharu.hideout.core.domain.model.actor.Role
|
||||||
import dev.usbharu.hideout.core.domain.model.emoji.EmojiId
|
import dev.usbharu.hideout.core.domain.model.emoji.EmojiId
|
||||||
|
import dev.usbharu.hideout.core.domain.model.instance.InstanceId
|
||||||
import dev.usbharu.hideout.core.domain.model.media.MediaId
|
import dev.usbharu.hideout.core.domain.model.media.MediaId
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post.Companion.Action.*
|
import dev.usbharu.hideout.core.domain.model.post.Post.Companion.Action.*
|
||||||
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
|
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable
|
||||||
|
@ -32,6 +33,7 @@ import java.time.Instant
|
||||||
class Post(
|
class Post(
|
||||||
val id: PostId,
|
val id: PostId,
|
||||||
actorId: ActorId,
|
actorId: ActorId,
|
||||||
|
val instanceId: InstanceId,
|
||||||
overview: PostOverview?,
|
overview: PostOverview?,
|
||||||
content: PostContent,
|
content: PostContent,
|
||||||
val createdAt: Instant,
|
val createdAt: Instant,
|
||||||
|
@ -48,6 +50,7 @@ class Post(
|
||||||
moveTo: PostId?,
|
moveTo: PostId?,
|
||||||
) : DomainEventStorable() {
|
) : DomainEventStorable() {
|
||||||
|
|
||||||
|
|
||||||
val actorId = actorId
|
val actorId = actorId
|
||||||
get() {
|
get() {
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
|
@ -227,6 +230,7 @@ class Post(
|
||||||
return Post(
|
return Post(
|
||||||
id = id,
|
id = id,
|
||||||
actorId = actorId,
|
actorId = actorId,
|
||||||
|
instanceId = instanceId,
|
||||||
overview = overview,
|
overview = overview,
|
||||||
content = PostContent(this.content.text, this.content.content, emojis),
|
content = PostContent(this.content.text, this.content.content, emojis),
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
|
@ -273,6 +277,7 @@ class Post(
|
||||||
fun create(
|
fun create(
|
||||||
id: PostId,
|
id: PostId,
|
||||||
actorId: ActorId,
|
actorId: ActorId,
|
||||||
|
instanceId: InstanceId,
|
||||||
overview: PostOverview? = null,
|
overview: PostOverview? = null,
|
||||||
content: PostContent,
|
content: PostContent,
|
||||||
createdAt: Instant,
|
createdAt: Instant,
|
||||||
|
@ -301,6 +306,7 @@ class Post(
|
||||||
val post = Post(
|
val post = Post(
|
||||||
id = id,
|
id = id,
|
||||||
actorId = actorId,
|
actorId = actorId,
|
||||||
|
instanceId = instanceId,
|
||||||
overview = overview,
|
overview = overview,
|
||||||
content = content,
|
content = content,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
|
|
|
@ -22,4 +22,14 @@ 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>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data class FindRelationshipOption(
|
||||||
|
val follow: Boolean? = null,
|
||||||
|
val block: Boolean? = null,
|
||||||
|
val mute: Boolean? = null,
|
||||||
|
val followRequest: Boolean? = null,
|
||||||
|
val muteFollowRequest: Boolean? = null
|
||||||
|
)
|
|
@ -3,4 +3,6 @@ package dev.usbharu.hideout.core.domain.model.timeline
|
||||||
interface TimelineRepository {
|
interface TimelineRepository {
|
||||||
suspend fun save(timeline: Timeline): Timeline
|
suspend fun save(timeline: Timeline): Timeline
|
||||||
suspend fun delete(timeline: Timeline)
|
suspend fun delete(timeline: Timeline)
|
||||||
|
|
||||||
|
suspend fun findByIds(ids: List<TimelineId>): List<Timeline>
|
||||||
}
|
}
|
|
@ -1,4 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinebuilder
|
|
||||||
|
|
||||||
class TimelineBuilder(val id: TimelineBuilderId, val timelineBuilderName: TimelineBuilderName) {
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinebuilder
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class TimelineBuilderId(val value: Long)
|
|
|
@ -1,4 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinebuilder
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class TimelineBuilderName(val value: String)
|
|
|
@ -1,6 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinebuilder
|
|
||||||
|
|
||||||
interface TimelineBuilderRepository {
|
|
||||||
suspend fun save(timelineBuilder: TimelineBuilder): TimelineBuilder
|
|
||||||
suspend fun delete(timelineBuilder: TimelineBuilder)
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinerelationship
|
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
|
||||||
import dev.usbharu.hideout.core.domain.model.instance.InstanceId
|
|
||||||
|
|
||||||
class TimelineRelationship(
|
|
||||||
val timelineRelationshipId: TimelineRelationshipId,
|
|
||||||
val actorId: ActorId?,
|
|
||||||
val instanceId: InstanceId?
|
|
||||||
)
|
|
|
@ -1,4 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinerelationship
|
|
||||||
|
|
||||||
@JvmInline
|
|
||||||
value class TimelineRelationshipId(val value: Long)
|
|
|
@ -1,6 +0,0 @@
|
||||||
package dev.usbharu.hideout.core.domain.model.timelinerelationship
|
|
||||||
|
|
||||||
interface TimelineRelationshipRepository {
|
|
||||||
suspend fun save(timelineRelationship: TimelineRelationship): TimelineRelationship
|
|
||||||
suspend fun delete(timelineRelationship: TimelineRelationship)
|
|
||||||
}
|
|
7
hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt
vendored
Normal file
7
hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/timeline/TimelineStore.kt
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package dev.usbharu.hideout.core.external.timeline
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
|
|
||||||
|
interface TimelineStore {
|
||||||
|
suspend fun newPost(post: Post)
|
||||||
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
package dev.usbharu.hideout.core.infrastructure.exposedrepository
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.actor.ActorId
|
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.Relationship
|
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher
|
import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher
|
||||||
|
@ -66,11 +67,38 @@ class ExposedRelationshipRepository(override val domainEventPublisher: DomainEve
|
||||||
}.singleOrNull()?.toRelationships()
|
}.singleOrNull()?.toRelationships()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun findByTargetId(targetId: ActorId, option: FindRelationshipOption?): List<Relationship> {
|
||||||
|
val query = Relationships.selectAll().where {
|
||||||
|
Relationships.targetActorId eq targetId.id
|
||||||
|
}
|
||||||
|
option.apply(query)
|
||||||
|
return query.map(ResultRow::toRelationships)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val logger = LoggerFactory.getLogger(ExposedRelationshipRepository::class.java)
|
private val logger = LoggerFactory.getLogger(ExposedRelationshipRepository::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun FindRelationshipOption?.apply(query: Query) {
|
||||||
|
|
||||||
|
if (this?.follow != null) {
|
||||||
|
query.andWhere { Relationships.following eq this@apply.follow }
|
||||||
|
}
|
||||||
|
if (this?.mute != null) {
|
||||||
|
query.andWhere { Relationships.muting eq this@apply.mute }
|
||||||
|
}
|
||||||
|
if (this?.block != null) {
|
||||||
|
query.andWhere { Relationships.blocking eq this@apply.block }
|
||||||
|
}
|
||||||
|
if (this?.followRequest != null) {
|
||||||
|
query.andWhere { Relationships.followRequesting eq this@apply.followRequest }
|
||||||
|
}
|
||||||
|
if (this?.muteFollowRequest != null) {
|
||||||
|
query.andWhere { Relationships.mutingFollowRequest eq this@apply.muteFollowRequest }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun ResultRow.toRelationships(): Relationship = Relationship(
|
fun ResultRow.toRelationships(): Relationship = Relationship(
|
||||||
actorId = ActorId(this[Relationships.actorId]),
|
actorId = ActorId(this[Relationships.actorId]),
|
||||||
targetActorId = ActorId(this[Relationships.targetActorId]),
|
targetActorId = ActorId(this[Relationships.targetActorId]),
|
||||||
|
|
|
@ -52,6 +52,7 @@ class PostFactoryImpl(
|
||||||
return Post.create(
|
return Post.create(
|
||||||
id = PostId(id),
|
id = PostId(id),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
overview = overview,
|
overview = overview,
|
||||||
content = postContentFactoryImpl.create(content),
|
content = postContentFactoryImpl.create(content),
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package dev.usbharu.hideout.core.infrastructure.timeline
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
abstract class AbstractTimelineStore(
|
||||||
|
private val timelineRepository: TimelineRepository,
|
||||||
|
private val relationshipRepository: RelationshipRepository
|
||||||
|
) :
|
||||||
|
TimelineStore {
|
||||||
|
override suspend fun newPost(post: Post) {
|
||||||
|
relationshipRepository.findByTargetId(post.actorId, FindRelationshipOption(follow = true, mute = false))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -312,6 +312,7 @@ class PostTest {
|
||||||
Post.create(
|
Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
overview = null,
|
overview = null,
|
||||||
content = PostContent.empty,
|
content = PostContent.empty,
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
|
@ -327,7 +328,6 @@ class PostTest {
|
||||||
hide = false,
|
hide = false,
|
||||||
moveTo = null,
|
moveTo = null,
|
||||||
actor = actor
|
actor = actor
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
overview = null,
|
overview = null,
|
||||||
content = PostContent.empty,
|
content = PostContent.empty,
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
|
@ -366,6 +367,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
overview = null,
|
overview = null,
|
||||||
content = PostContent.empty,
|
content = PostContent.empty,
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
|
@ -396,6 +398,7 @@ class PostTest {
|
||||||
Post.create(
|
Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
overview = null,
|
overview = null,
|
||||||
content = PostContent.empty,
|
content = PostContent.empty,
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
|
@ -425,6 +428,7 @@ class PostTest {
|
||||||
Post.create(
|
Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
content = PostContent.empty,
|
content = PostContent.empty,
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
|
@ -447,6 +451,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
content = PostContent("aaa", "aaa", emojiIds),
|
content = PostContent("aaa", "aaa", emojiIds),
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
|
@ -472,6 +477,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
content = PostContent("aaa", "aaa", emojiIds),
|
content = PostContent("aaa", "aaa", emojiIds),
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
|
@ -510,6 +516,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
content = PostContent("aaa", "aaa", emojiIds),
|
content = PostContent("aaa", "aaa", emojiIds),
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
|
@ -536,6 +543,7 @@ class PostTest {
|
||||||
val post = Post.create(
|
val post = Post.create(
|
||||||
id = PostId(1),
|
id = PostId(1),
|
||||||
actorId = actor.id,
|
actorId = actor.id,
|
||||||
|
instanceId = actor.instance,
|
||||||
content = PostContent("aaa", "aaa", emojiIds),
|
content = PostContent("aaa", "aaa", emojiIds),
|
||||||
createdAt = Instant.now(),
|
createdAt = Instant.now(),
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
|
|
Loading…
Reference in New Issue