Вторая часть по кэшу
This commit is contained in:
@@ -7,6 +7,7 @@ import chats.domain.model.Chat
|
||||
* Преобразует Domain Chat в Entity
|
||||
*/
|
||||
fun Chat.toEntity(): ChatEntity {
|
||||
val timestamp = this.lastMessage?.createdAt?.let { parseTimestamp(it) }
|
||||
return ChatEntity(
|
||||
localId = this.id.takeIf { it.isNotBlank() } ?: java.util.UUID.randomUUID().toString(),
|
||||
remoteId = this.id,
|
||||
@@ -15,7 +16,7 @@ fun Chat.toEntity(): ChatEntity {
|
||||
avatar = this.avatar,
|
||||
unreadCount = this.unreadCount,
|
||||
lastMessageText = this.lastMessage?.content,
|
||||
lastMessageTimestamp = this.lastMessage?.createdAt
|
||||
lastMessageTimestamp = timestamp
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,3 +33,14 @@ fun ChatEntity.toDomain(): Chat {
|
||||
lastMessage = null // lastMessage загружается отдельно
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Парсит ISO-8601 timestamp в Long (millis)
|
||||
*/
|
||||
private fun parseTimestamp(isoTimestamp: String): Long? {
|
||||
return try {
|
||||
java.time.ZonedDateTime.parse(isoTimestamp).toInstant().toEpochMilli()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user