fix(chat-room): 메시지 있는 방만 목록 조회되도록 쿼리 수정
This commit is contained in:
parent
28bd700b03
commit
4966aaeda9
|
@ -42,19 +42,20 @@ interface ChatRoomRepository : JpaRepository<ChatRoom, Long> {
|
|||
r.title,
|
||||
pc.character.imagePath,
|
||||
pc.character.characterType,
|
||||
COALESCE(MAX(m.createdAt), r.createdAt)
|
||||
MAX(m.createdAt)
|
||||
)
|
||||
FROM ChatRoom r
|
||||
JOIN r.participants p
|
||||
JOIN r.participants pc
|
||||
LEFT JOIN r.messages m
|
||||
JOIN r.messages m
|
||||
WHERE p.member = :member
|
||||
AND p.isActive = true
|
||||
AND pc.participantType = kr.co.vividnext.sodalive.chat.room.ParticipantType.CHARACTER
|
||||
AND pc.isActive = true
|
||||
AND r.isActive = true
|
||||
AND m.isActive = true
|
||||
GROUP BY r.id, r.title, r.createdAt, pc.character.imagePath, pc.character.characterType
|
||||
ORDER BY COALESCE(MAX(m.createdAt), r.createdAt) DESC
|
||||
ORDER BY MAX(m.createdAt) DESC
|
||||
"""
|
||||
)
|
||||
fun findMemberRoomsOrderByLastMessageDesc(
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory
|
|||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.client.RestTemplate
|
||||
import java.time.Duration
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
@Service
|
||||
|
@ -218,16 +220,16 @@ class ChatRoomService(
|
|||
}
|
||||
}
|
||||
|
||||
private fun formatRelativeTime(time: java.time.LocalDateTime?): String {
|
||||
private fun formatRelativeTime(time: LocalDateTime?): String {
|
||||
if (time == null) return ""
|
||||
val now = java.time.LocalDateTime.now()
|
||||
val duration = java.time.Duration.between(time, now)
|
||||
val now = LocalDateTime.now()
|
||||
val duration = Duration.between(time, now)
|
||||
val seconds = duration.seconds
|
||||
if (seconds <= 60) return "방금"
|
||||
val minutes = duration.toMinutes()
|
||||
if (minutes < 60) return "${'$'}minutes분 전"
|
||||
if (minutes < 60) return "${minutes}분 전"
|
||||
val hours = duration.toHours()
|
||||
if (hours < 24) return "${'$'}hours시간 전"
|
||||
if (hours < 24) return "${hours}시간 전"
|
||||
// 그 외: 날짜 (yyyy-MM-dd)
|
||||
return time.toLocalDate().toString()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue