Офлайн режим, начало
This commit is contained in:
@@ -2,6 +2,9 @@ package chats.data.repository
|
||||
|
||||
import chats.data.remote.dto.*
|
||||
import chats.domain.model.*
|
||||
import core.database.data.ChatEntity
|
||||
import core.database.data.MessageEntity
|
||||
import core.database.data.SyncStatus
|
||||
|
||||
// Mappers
|
||||
fun ChatDto.toDomain(currentUserId: String, baseUrl: String): Chat {
|
||||
@@ -23,6 +26,38 @@ fun ChatDto.toDomain(currentUserId: String, baseUrl: String): Chat {
|
||||
)
|
||||
}
|
||||
|
||||
fun Chat.toEntity(): ChatEntity {
|
||||
return ChatEntity(
|
||||
id = id,
|
||||
name = name,
|
||||
avatar = avatar,
|
||||
type = type,
|
||||
lastMessageId = lastMessage?.id,
|
||||
lastMessageText = lastMessage?.content,
|
||||
lastMessageAt = lastMessage?.createdAt?.let {
|
||||
try { java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", java.util.Locale.US).parse(it)?.time ?: 0L }
|
||||
catch (e: Exception) { 0L }
|
||||
} ?: 0L,
|
||||
unreadCount = unreadCount,
|
||||
isPinned = false
|
||||
)
|
||||
}
|
||||
|
||||
fun ChatEntity.toDomain(
|
||||
currentUserId: String,
|
||||
baseUrl: String,
|
||||
lastMessage: Message? = null
|
||||
): Chat {
|
||||
return Chat(
|
||||
id = id,
|
||||
type = type,
|
||||
name = name,
|
||||
avatar = avatar,
|
||||
unreadCount = unreadCount,
|
||||
lastMessage = lastMessage
|
||||
)
|
||||
}
|
||||
|
||||
fun Message.toEntity(gson: com.google.gson.Gson): core.database.data.MessageEntity {
|
||||
return core.database.data.MessageEntity(
|
||||
id = id,
|
||||
@@ -37,7 +72,12 @@ fun Message.toEntity(gson: com.google.gson.Gson): core.database.data.MessageEnti
|
||||
mediaJson = gson.toJson(media),
|
||||
reactionsJson = gson.toJson(reactions),
|
||||
isRead = isRead,
|
||||
replyToId = replyTo?.id
|
||||
replyToId = replyTo?.id,
|
||||
syncStatus = SyncStatus.SYNCED,
|
||||
isDeletedLocally = false,
|
||||
isEditedLocally = false,
|
||||
editedContent = null,
|
||||
lastUpdated = System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user