feat: タイムラインの構築時に自分自身を対象に含めるように

This commit is contained in:
usbharu 2023-09-29 19:19:30 +09:00
parent 4f411dddbf
commit 588b54ea7e
1 changed files with 26 additions and 3 deletions

View File

@ -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)
}
}