feat(chat): 채팅방 UI 모델 매핑을 추가한다
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.chat.model
|
||||
|
||||
import android.content.Context
|
||||
import kr.co.vividnext.sodalive.v2.main.chat.data.ChatRoomListItemResponse
|
||||
|
||||
fun ChatRoomListItemResponse.toUiItem(context: Context): ChatRoomListUiItem? {
|
||||
val type = when (chatType) {
|
||||
ChatRoomType.AI.name -> ChatRoomType.AI
|
||||
ChatRoomType.DM.name -> ChatRoomType.DM
|
||||
else -> return null
|
||||
}
|
||||
|
||||
return ChatRoomListUiItem(
|
||||
roomId = roomId,
|
||||
chatType = type,
|
||||
targetName = targetName,
|
||||
targetImageUrl = targetImageUrl,
|
||||
lastMessage = lastMessage,
|
||||
lastMessageTimeText = formatChatRoomLastMessageTime(context, lastMessageAt),
|
||||
showDirectBadge = type == ChatRoomType.DM
|
||||
)
|
||||
}
|
||||
|
||||
fun List<ChatRoomListItemResponse>.toUiItems(context: Context): List<ChatRoomListUiItem> = mapNotNull { it.toUiItem(context) }
|
||||
@@ -0,0 +1,29 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.chat.model
|
||||
|
||||
enum class ChatRoomType {
|
||||
AI,
|
||||
DM
|
||||
}
|
||||
|
||||
data class ChatRoomListUiItem(
|
||||
val roomId: Long,
|
||||
val chatType: ChatRoomType,
|
||||
val targetName: String,
|
||||
val targetImageUrl: String,
|
||||
val lastMessage: String,
|
||||
val lastMessageTimeText: String,
|
||||
val showDirectBadge: Boolean
|
||||
)
|
||||
|
||||
sealed class ChatRoomListUiState {
|
||||
data object Loading : ChatRoomListUiState()
|
||||
|
||||
data class Content(
|
||||
val items: List<ChatRoomListUiItem>,
|
||||
val isAppending: Boolean = false
|
||||
) : ChatRoomListUiState()
|
||||
|
||||
data object Empty : ChatRoomListUiState()
|
||||
|
||||
data class Error(val message: String?) : ChatRoomListUiState()
|
||||
}
|
||||
Reference in New Issue
Block a user