From 41f7fc605cdf7551551e5d8d745a6dd97546d25f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 29 Sep 2023 19:19:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=AE=E6=A7=8B=E7=AF=89=E6=99=82=E3=81=AB?= =?UTF-8?q?=E8=87=AA=E5=88=86=E8=87=AA=E8=BA=AB=E3=82=92=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=81=AB=E5=90=AB=E3=82=81=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/service/post/TimelineService.kt | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt index d0aeefbb..944b1dda 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/TimelineService.kt @@ -2,18 +2,23 @@ package dev.usbharu.hideout.service.post import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.Timeline +import dev.usbharu.hideout.domain.model.hideout.entity.Visibility import dev.usbharu.hideout.query.FollowerQueryService +import dev.usbharu.hideout.query.UserQueryService import dev.usbharu.hideout.repository.TimelineRepository import org.springframework.stereotype.Service @Service class TimelineService( private val followerQueryService: FollowerQueryService, + private val userQueryService: UserQueryService, private val timelineRepository: TimelineRepository ) { suspend fun publishTimeline(post: Post, isLocal: Boolean) { - val findFollowersById = followerQueryService.findFollowersById(post.userId) - timelineRepository.saveAll(findFollowersById.map { + // 自分自身も含める必要がある + val user = userQueryService.findById(post.userId) + val findFollowersById = followerQueryService.findFollowersById(post.userId).plus(user) + val timelines = findFollowersById.map { Timeline( id = timelineRepository.generateId(), userId = it.id, @@ -27,6 +32,24 @@ class TimelineService( sensitive = post.sensitive, isLocal = isLocal ) - }) + }.toMutableList() + if (post.visibility == Visibility.PUBLIC) { + timelines.add( + Timeline( + id = timelineRepository.generateId(), + userId = 0, + timelineId = 0, + postId = post.id, + postUserId = post.userId, + createdAt = post.createdAt, + replyId = post.replyId, + repostId = post.repostId, + visibility = post.visibility, + sensitive = post.sensitive, + isLocal = isLocal + ) + ) + } + timelineRepository.saveAll(timelines) } }