Unverified Commit 318eff21 authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #1659 from RocketChat/fix/compress-image

[FIX] Check file size after compressing the image
parents fbc7df8a 10387d42
...@@ -33,6 +33,7 @@ import chat.rocket.android.server.domain.uploadMimeTypeFilter ...@@ -33,6 +33,7 @@ import chat.rocket.android.server.domain.uploadMimeTypeFilter
import chat.rocket.android.server.domain.useRealName import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.server.infraestructure.state import chat.rocket.android.server.infraestructure.state
import chat.rocket.android.util.extension.compressImageAndGetByteArray
import chat.rocket.android.util.extension.compressImageAndGetInputStream import chat.rocket.android.util.extension.compressImageAndGetInputStream
import chat.rocket.android.util.extension.launchUI import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.avatarUrl import chat.rocket.android.util.extensions.avatarUrl
...@@ -353,8 +354,9 @@ class ChatRoomPresenter @Inject constructor( ...@@ -353,8 +354,9 @@ class ChatRoomPresenter @Inject constructor(
try { try {
withContext(DefaultDispatcher) { withContext(DefaultDispatcher) {
val fileName = uriInteractor.getFileName(uri) ?: uri.toString() val fileName = uriInteractor.getFileName(uri) ?: uri.toString()
val fileSize = uriInteractor.getFileSize(uri)
val mimeType = uriInteractor.getMimeType(uri) val mimeType = uriInteractor.getMimeType(uri)
val byteArray = bitmap?.compressImageAndGetByteArray(mimeType)
val fileSize = byteArray?.size ?: uriInteractor.getFileSize(uri)
val maxFileSizeAllowed = settings.uploadMaxFileSize() val maxFileSizeAllowed = settings.uploadMaxFileSize()
when { when {
...@@ -362,12 +364,6 @@ class ChatRoomPresenter @Inject constructor( ...@@ -362,12 +364,6 @@ class ChatRoomPresenter @Inject constructor(
fileSize > maxFileSizeAllowed && maxFileSizeAllowed !in -1..0 -> fileSize > maxFileSizeAllowed && maxFileSizeAllowed !in -1..0 ->
view.showInvalidFileSize(fileSize, maxFileSizeAllowed) view.showInvalidFileSize(fileSize, maxFileSizeAllowed)
else -> { else -> {
var inputStream: InputStream? = uriInteractor.getInputStream(uri)
bitmap?.compressImageAndGetInputStream(mimeType)?.let {
inputStream = it
}
retryIO("uploadFile($roomId, $fileName, $mimeType") { retryIO("uploadFile($roomId, $fileName, $mimeType") {
client.uploadFile( client.uploadFile(
roomId, roomId,
...@@ -376,7 +372,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -376,7 +372,7 @@ class ChatRoomPresenter @Inject constructor(
msg, msg,
description = fileName description = fileName
) { ) {
inputStream byteArray?.inputStream() ?: uriInteractor.getInputStream(uri)
} }
} }
logMediaUploaded(mimeType) logMediaUploaded(mimeType)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment