fix(android): render gif attachments reliably after send
This commit is contained in:
@@ -101,6 +101,7 @@ dependencies {
|
|||||||
implementation("androidx.compose.material:material-icons-extended:1.7.6")
|
implementation("androidx.compose.material:material-icons-extended:1.7.6")
|
||||||
implementation("io.coil-kt:coil:2.7.0")
|
implementation("io.coil-kt:coil:2.7.0")
|
||||||
implementation("io.coil-kt:coil-compose:2.7.0")
|
implementation("io.coil-kt:coil-compose:2.7.0")
|
||||||
|
implementation("io.coil-kt:coil-gif:2.7.0")
|
||||||
implementation("androidx.media3:media3-exoplayer:1.4.1")
|
implementation("androidx.media3:media3-exoplayer:1.4.1")
|
||||||
implementation("androidx.media3:media3-datasource:1.4.1")
|
implementation("androidx.media3:media3-datasource:1.4.1")
|
||||||
implementation("androidx.media3:media3-datasource-okhttp:1.4.1")
|
implementation("androidx.media3:media3-datasource-okhttp:1.4.1")
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import ru.daemonlord.messenger.di.IoDispatcher
|
|||||||
import ru.daemonlord.messenger.di.RefreshClient
|
import ru.daemonlord.messenger.di.RefreshClient
|
||||||
import ru.daemonlord.messenger.domain.common.AppError
|
import ru.daemonlord.messenger.domain.common.AppError
|
||||||
import ru.daemonlord.messenger.domain.common.AppResult
|
import ru.daemonlord.messenger.domain.common.AppResult
|
||||||
|
import ru.daemonlord.messenger.domain.media.model.UploadedAttachment
|
||||||
import ru.daemonlord.messenger.domain.media.repository.MediaRepository
|
import ru.daemonlord.messenger.domain.media.repository.MediaRepository
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -34,7 +35,7 @@ class NetworkMediaRepository @Inject constructor(
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
mimeType: String,
|
mimeType: String,
|
||||||
bytes: ByteArray,
|
bytes: ByteArray,
|
||||||
): AppResult<Unit> = withContext(ioDispatcher) {
|
): AppResult<UploadedAttachment> = withContext(ioDispatcher) {
|
||||||
try {
|
try {
|
||||||
val uploadPayload = prepareUploadPayload(
|
val uploadPayload = prepareUploadPayload(
|
||||||
fileName = fileName,
|
fileName = fileName,
|
||||||
@@ -74,7 +75,13 @@ class NetworkMediaRepository @Inject constructor(
|
|||||||
fileSize = uploadPayload.bytes.size.toLong(),
|
fileSize = uploadPayload.bytes.size.toLong(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
AppResult.Success(Unit)
|
AppResult.Success(
|
||||||
|
UploadedAttachment(
|
||||||
|
fileUrl = uploadInfo.fileUrl,
|
||||||
|
fileType = uploadPayload.mimeType,
|
||||||
|
fileSize = uploadPayload.bytes.size.toLong(),
|
||||||
|
)
|
||||||
|
)
|
||||||
} catch (error: Throwable) {
|
} catch (error: Throwable) {
|
||||||
AppResult.Error(error.toAppError())
|
AppResult.Error(error.toAppError())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import ru.daemonlord.messenger.data.common.toAppError
|
|||||||
import ru.daemonlord.messenger.data.message.local.dao.MessageDao
|
import ru.daemonlord.messenger.data.message.local.dao.MessageDao
|
||||||
import ru.daemonlord.messenger.data.message.local.dao.PendingMessageActionDao
|
import ru.daemonlord.messenger.data.message.local.dao.PendingMessageActionDao
|
||||||
import ru.daemonlord.messenger.data.message.local.entity.MessageEntity
|
import ru.daemonlord.messenger.data.message.local.entity.MessageEntity
|
||||||
|
import ru.daemonlord.messenger.data.message.local.entity.MessageAttachmentEntity
|
||||||
import ru.daemonlord.messenger.data.message.local.entity.PendingMessageActionEntity
|
import ru.daemonlord.messenger.data.message.local.entity.PendingMessageActionEntity
|
||||||
import ru.daemonlord.messenger.data.message.mapper.toDomain
|
import ru.daemonlord.messenger.data.message.mapper.toDomain
|
||||||
import ru.daemonlord.messenger.data.message.mapper.toEntity
|
import ru.daemonlord.messenger.data.message.mapper.toEntity
|
||||||
@@ -360,7 +361,27 @@ class NetworkMessageRepository @Inject constructor(
|
|||||||
)) {
|
)) {
|
||||||
is AppResult.Success -> {
|
is AppResult.Success -> {
|
||||||
messageDao.deleteMessage(tempId)
|
messageDao.deleteMessage(tempId)
|
||||||
syncRecentMessages(chatId = chatId)
|
messageDao.upsertMessages(listOf(created.toEntity()))
|
||||||
|
messageDao.upsertAttachments(
|
||||||
|
listOf(
|
||||||
|
MessageAttachmentEntity(
|
||||||
|
id = -System.currentTimeMillis(),
|
||||||
|
messageId = created.id,
|
||||||
|
fileUrl = mediaResult.data.fileUrl,
|
||||||
|
fileType = mediaResult.data.fileType,
|
||||||
|
fileSize = mediaResult.data.fileSize,
|
||||||
|
waveformPointsJson = null,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
chatDao.updateLastMessage(
|
||||||
|
chatId = chatId,
|
||||||
|
lastMessageText = created.text,
|
||||||
|
lastMessageType = created.type,
|
||||||
|
lastMessageCreatedAt = created.createdAt,
|
||||||
|
updatedSortAt = created.createdAt,
|
||||||
|
)
|
||||||
|
AppResult.Success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppResult.Error -> {
|
is AppResult.Error -> {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package ru.daemonlord.messenger.domain.media.model
|
||||||
|
|
||||||
|
data class UploadedAttachment(
|
||||||
|
val fileUrl: String,
|
||||||
|
val fileType: String,
|
||||||
|
val fileSize: Long,
|
||||||
|
)
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.daemonlord.messenger.domain.media.repository
|
package ru.daemonlord.messenger.domain.media.repository
|
||||||
|
|
||||||
import ru.daemonlord.messenger.domain.common.AppResult
|
import ru.daemonlord.messenger.domain.common.AppResult
|
||||||
|
import ru.daemonlord.messenger.domain.media.model.UploadedAttachment
|
||||||
|
|
||||||
interface MediaRepository {
|
interface MediaRepository {
|
||||||
suspend fun uploadAndAttach(
|
suspend fun uploadAndAttach(
|
||||||
@@ -8,5 +9,5 @@ interface MediaRepository {
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
mimeType: String,
|
mimeType: String,
|
||||||
bytes: ByteArray,
|
bytes: ByteArray,
|
||||||
): AppResult<Unit>
|
): AppResult<UploadedAttachment>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.daemonlord.messenger.domain.media.usecase
|
package ru.daemonlord.messenger.domain.media.usecase
|
||||||
|
|
||||||
import ru.daemonlord.messenger.domain.common.AppResult
|
import ru.daemonlord.messenger.domain.common.AppResult
|
||||||
|
import ru.daemonlord.messenger.domain.media.model.UploadedAttachment
|
||||||
import ru.daemonlord.messenger.domain.media.repository.MediaRepository
|
import ru.daemonlord.messenger.domain.media.repository.MediaRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ class UploadAndAttachMediaUseCase @Inject constructor(
|
|||||||
fileName: String,
|
fileName: String,
|
||||||
mimeType: String,
|
mimeType: String,
|
||||||
bytes: ByteArray,
|
bytes: ByteArray,
|
||||||
): AppResult<Unit> {
|
): AppResult<UploadedAttachment> {
|
||||||
return mediaRepository.uploadAndAttach(
|
return mediaRepository.uploadAndAttach(
|
||||||
messageId = messageId,
|
messageId = messageId,
|
||||||
fileName = fileName,
|
fileName = fileName,
|
||||||
|
|||||||
Reference in New Issue
Block a user