Правки
This commit is contained in:
@@ -6,6 +6,7 @@ import androidx.hilt.work.HiltWorker
|
||||
import androidx.work.*
|
||||
import chats.data.local.dao.MessageDao
|
||||
import chats.data.local.database.MessageEntity
|
||||
import chats.data.remote.api.AttachmentRequest
|
||||
import chats.data.remote.api.ChatApi
|
||||
import chats.data.remote.api.SendMessageRequest
|
||||
import chats.domain.model.MessageStatus
|
||||
@@ -99,9 +100,28 @@ class SendMessageWorker @AssistedInject constructor(
|
||||
)
|
||||
|
||||
// Выполняем запрос к API с Idempotency-Key
|
||||
// Десериализуем media из JSON
|
||||
val mediaList = try {
|
||||
val gson = com.google.gson.Gson()
|
||||
val type = object : com.google.gson.reflect.TypeToken<List<chats.domain.model.Media>>() {}.type
|
||||
gson.fromJson<List<chats.domain.model.Media>>(message.mediaJson, type) ?: emptyList()
|
||||
} catch (e: Exception) {
|
||||
emptyList<chats.domain.model.Media>()
|
||||
}
|
||||
|
||||
val attachments = mediaList.map {
|
||||
AttachmentRequest(
|
||||
type = it.type,
|
||||
url = it.url,
|
||||
fileName = it.filename ?: "",
|
||||
fileSize = it.size ?: 0L
|
||||
)
|
||||
}.takeIf { it.isNotEmpty() }
|
||||
|
||||
val request = SendMessageRequest(
|
||||
content = message.content,
|
||||
type = message.mediaType.lowercase(),
|
||||
attachments = attachments,
|
||||
replyToId = message.replyToServerId
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user