From faee779cfb7a2d9bcc06ebae8261fe8a29606472 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 30 Jun 2024 13:48:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Timeline=E3=81=AE=E6=A7=8B=E7=AF=89?= =?UTF-8?q?=E3=81=AB=E5=BF=85=E8=A6=81=E3=81=AA=E3=82=82=E3=81=AE=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/core/domain/model/actor/Actor.kt | 2 +- .../core/domain/model/emoji/CustomEmoji.kt | 2 +- .../{shared => support/domain}/Domain.kt | 2 +- .../model/support/postdetail/PostDetail.kt | 22 ++++++ .../core/domain/model/timeline/Timeline.kt | 2 - .../model/timelineobject/TimelineObject.kt | 69 ++++++++++++++++++- .../exposed/ActorResultRowMapper.kt | 2 +- .../CustomEmojiRepositoryImpl.kt | 2 +- .../ExposedActorRepository.kt | 2 +- .../factory/ActorFactoryImpl.kt | 2 +- .../domain/model/actor/TestActorFactory.kt | 2 +- 11 files changed, 98 insertions(+), 11 deletions(-) rename hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/{shared => support/domain}/Domain.kt (92%) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/postdetail/PostDetail.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index a90c343d..3e981ab8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -21,7 +21,7 @@ import dev.usbharu.hideout.core.domain.event.actor.ActorEvent.* 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.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventStorable import java.net.URI import java.time.Instant diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt index 34240b2e..e0e29b17 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/emoji/CustomEmoji.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.core.domain.model.emoji import dev.usbharu.hideout.core.domain.model.instance.InstanceId -import dev.usbharu.hideout.core.domain.model.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import java.net.URI import java.time.Instant diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/domain/Domain.kt similarity index 92% rename from hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt rename to hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/domain/Domain.kt index cf6f9f1b..b17ab7bd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/shared/Domain.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/domain/Domain.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package dev.usbharu.hideout.core.domain.model.shared +package dev.usbharu.hideout.core.domain.model.support.domain @JvmInline value class Domain(val domain: String) { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/postdetail/PostDetail.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/postdetail/PostDetail.kt new file mode 100644 index 00000000..a05ce174 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/support/postdetail/PostDetail.kt @@ -0,0 +1,22 @@ +package dev.usbharu.hideout.core.domain.model.support.postdetail + +import dev.usbharu.hideout.core.domain.model.actor.Actor +import dev.usbharu.hideout.core.domain.model.post.Post + +data class PostDetail( + val post: Post, + val reply: Post? = null, + val repost: Post? = null, + val postActor: Actor, + val replyActor: Actor? = null, + val repostActor: Actor? = null +) { + init { + require(post.replyId == reply?.id) + require(post.repostId == repost?.id) + + require(post.actorId == postActor.id) + require(reply?.actorId == replyActor?.id) + require(repost?.actorId == repostActor?.id) + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt index 1a421254..e3fe6f74 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timeline/Timeline.kt @@ -25,6 +25,4 @@ class Timeline( var name = name private set - - } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt index f2064513..5c6c56f4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/timelineobject/TimelineObject.kt @@ -2,9 +2,13 @@ package dev.usbharu.hideout.core.domain.model.timelineobject import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.emoji.EmojiId +import dev.usbharu.hideout.core.domain.model.filter.FilterResult import dev.usbharu.hideout.core.domain.model.media.MediaId +import dev.usbharu.hideout.core.domain.model.post.Post +import dev.usbharu.hideout.core.domain.model.post.PostContent import dev.usbharu.hideout.core.domain.model.post.PostId import dev.usbharu.hideout.core.domain.model.post.Visibility +import dev.usbharu.hideout.core.domain.model.timeline.Timeline import dev.usbharu.hideout.core.domain.model.timeline.TimelineId import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId import java.time.Instant @@ -26,6 +30,69 @@ class TimelineObject( val hasMedia: Boolean, val hasMediaInRepost: Boolean, val lastUpdatedAt: Instant, - val warnFilters: List + val warnFilters: List, ) { + companion object { + + fun create( + timelineObjectId: TimelineObjectId, + timeline: Timeline, + post: Post, + filterResults: List + ): TimelineObject { + return TimelineObject( + id = timelineObjectId, + userDetailId = timeline.userDetailId, + timelineId = timeline.id, + postId = post.id, + postActorId = post.actorId, + postCreatedAt = post.createdAt, + replyId = post.replyId, + repostId = null, + visibility = post.visibility, + isPureRepost = true, + mediaIds = post.mediaIds, + emojiIds = post.emojiIds, + visibleActors = post.visibleActors.toList(), + hasMedia = post.mediaIds.isNotEmpty(), + hasMediaInRepost = false, + lastUpdatedAt = Instant.now(), + warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) } + ) + } + + fun create( + timelineObjectId: TimelineObjectId, + timeline: Timeline, + post: Post, + repost: Post, + filterResults: List + ): TimelineObject { + + require(post.repostId == repost.id) + + return TimelineObject( + id = timelineObjectId, + userDetailId = timeline.userDetailId, + timelineId = timeline.id, + postId = post.id, + postActorId = post.actorId, + postCreatedAt = post.createdAt, + replyId = post.replyId, + repostId = repost.id, + visibility = post.visibility, + isPureRepost = repost.mediaIds.isEmpty() && + repost.overview == null && + repost.content == PostContent.empty && + repost.replyId == null, + mediaIds = post.mediaIds, + emojiIds = post.emojiIds, + visibleActors = post.visibleActors.toList(), + hasMedia = post.mediaIds.isNotEmpty(), + hasMediaInRepost = repost.mediaIds.isNotEmpty(), + lastUpdatedAt = Instant.now(), + warnFilters = filterResults.map { TimelineObjectWarnFilter(it.filter.id, it.matchedKeyword) } + ) + } + } } \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorResultRowMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorResultRowMapper.kt index 3bb58e43..2a52527c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorResultRowMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/ActorResultRowMapper.kt @@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.domain.model.actor.* 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.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.infrastructure.exposedrepository.Actors import org.jetbrains.exposed.sql.ResultRow import org.springframework.stereotype.Component diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt index 9af0e090..56fcc6d1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/CustomEmojiRepositoryImpl.kt @@ -20,7 +20,7 @@ import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji import dev.usbharu.hideout.core.domain.model.emoji.CustomEmojiRepository 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.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.javatime.CurrentTimestamp diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt index e9c25f19..758c2126 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedActorRepository.kt @@ -1,7 +1,7 @@ package dev.usbharu.hideout.core.infrastructure.exposedrepository import dev.usbharu.hideout.core.domain.model.actor.* -import dev.usbharu.hideout.core.domain.model.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.domain.shared.domainevent.DomainEventPublisher import dev.usbharu.hideout.core.domain.shared.repository.DomainEventPublishableRepository import dev.usbharu.hideout.core.infrastructure.exposed.QueryMapper diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt index 0fb961c5..2628fe22 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt @@ -19,7 +19,7 @@ package dev.usbharu.hideout.core.infrastructure.factory import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.* import dev.usbharu.hideout.core.domain.model.instance.InstanceId -import dev.usbharu.hideout.core.domain.model.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService import org.springframework.stereotype.Component import java.net.URI diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt index 57e3d0d5..7f390e57 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/domain/model/actor/TestActorFactory.kt @@ -2,7 +2,7 @@ package dev.usbharu.hideout.core.domain.model.actor 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.shared.Domain +import dev.usbharu.hideout.core.domain.model.support.domain.Domain import dev.usbharu.hideout.core.infrastructure.other.TwitterSnowflakeIdGenerateService import kotlinx.coroutines.runBlocking import java.net.URI