Prevent crash when mimetype is null
This commit is contained in:
parent
7fa76b9d35
commit
79f11ad686
@ -30,7 +30,7 @@ data class ContentAttachmentData(
|
|||||||
val exifOrientation: Int = ExifInterface.ORIENTATION_UNDEFINED,
|
val exifOrientation: Int = ExifInterface.ORIENTATION_UNDEFINED,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val path: String,
|
val path: String,
|
||||||
val mimeType: String,
|
val mimeType: String?,
|
||||||
val type: Type
|
val type: Type
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ data class VideoInfo(
|
|||||||
/**
|
/**
|
||||||
* The mimetype of the video e.g. "video/mp4".
|
* The mimetype of the video e.g. "video/mp4".
|
||||||
*/
|
*/
|
||||||
@Json(name = "mimetype") val mimeType: String,
|
@Json(name = "mimetype") val mimeType: String?,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the video in pixels.
|
* The width of the video in pixels.
|
||||||
|
@ -49,7 +49,7 @@ object MXEncryptedAttachments {
|
|||||||
* @param mimetype the mime type
|
* @param mimetype the mime type
|
||||||
* @return the encryption file info
|
* @return the encryption file info
|
||||||
*/
|
*/
|
||||||
fun encryptAttachment(attachmentStream: InputStream, mimetype: String): EncryptionResult {
|
fun encryptAttachment(attachmentStream: InputStream, mimetype: String?): EncryptionResult {
|
||||||
val t0 = System.currentTimeMillis()
|
val t0 = System.currentTimeMillis()
|
||||||
val secureRandom = SecureRandom()
|
val secureRandom = SecureRandom()
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ internal class FileUploader @Inject constructor(@Authenticated
|
|||||||
|
|
||||||
suspend fun uploadFile(file: File,
|
suspend fun uploadFile(file: File,
|
||||||
filename: String?,
|
filename: String?,
|
||||||
mimeType: String,
|
mimeType: String?,
|
||||||
progressListener: ProgressRequestBody.Listener? = null): ContentUploadResponse {
|
progressListener: ProgressRequestBody.Listener? = null): ContentUploadResponse {
|
||||||
val uploadBody = file.asRequestBody(mimeType.toMediaTypeOrNull())
|
val uploadBody = file.asRequestBody(mimeType?.toMediaTypeOrNull())
|
||||||
return upload(uploadBody, filename, progressListener)
|
return upload(uploadBody, filename, progressListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||||||
type = MessageType.MSGTYPE_AUDIO,
|
type = MessageType.MSGTYPE_AUDIO,
|
||||||
body = attachment.name ?: "audio",
|
body = attachment.name ?: "audio",
|
||||||
audioInfo = AudioInfo(
|
audioInfo = AudioInfo(
|
||||||
mimeType = attachment.mimeType.takeIf { it.isNotBlank() } ?: "audio/mpeg",
|
mimeType = attachment.mimeType?.takeIf { it.isNotBlank() } ?: "audio/mpeg",
|
||||||
size = attachment.size
|
size = attachment.size
|
||||||
),
|
),
|
||||||
url = attachment.path
|
url = attachment.path
|
||||||
@ -264,7 +264,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||||||
type = MessageType.MSGTYPE_FILE,
|
type = MessageType.MSGTYPE_FILE,
|
||||||
body = attachment.name ?: "file",
|
body = attachment.name ?: "file",
|
||||||
info = FileInfo(
|
info = FileInfo(
|
||||||
mimeType = attachment.mimeType.takeIf { it.isNotBlank() }
|
mimeType = attachment.mimeType?.takeIf { it.isNotBlank() }
|
||||||
?: "application/octet-stream",
|
?: "application/octet-stream",
|
||||||
size = attachment.size
|
size = attachment.size
|
||||||
),
|
),
|
||||||
|
@ -18,6 +18,7 @@ package im.vector.riotx.features.attachments
|
|||||||
|
|
||||||
import com.kbeanie.multipicker.api.entity.*
|
import com.kbeanie.multipicker.api.entity.*
|
||||||
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
fun ChosenContact.toContactAttachment(): ContactAttachment {
|
fun ChosenContact.toContactAttachment(): ContactAttachment {
|
||||||
return ContactAttachment(
|
return ContactAttachment(
|
||||||
@ -29,6 +30,7 @@ fun ChosenContact.toContactAttachment(): ContactAttachment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ChosenFile.toContentAttachmentData(): ContentAttachmentData {
|
fun ChosenFile.toContentAttachmentData(): ContentAttachmentData {
|
||||||
|
if (mimeType == null) Timber.w("No mimeType")
|
||||||
return ContentAttachmentData(
|
return ContentAttachmentData(
|
||||||
path = originalPath,
|
path = originalPath,
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
@ -40,6 +42,7 @@ fun ChosenFile.toContentAttachmentData(): ContentAttachmentData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ChosenAudio.toContentAttachmentData(): ContentAttachmentData {
|
fun ChosenAudio.toContentAttachmentData(): ContentAttachmentData {
|
||||||
|
if (mimeType == null) Timber.w("No mimeType")
|
||||||
return ContentAttachmentData(
|
return ContentAttachmentData(
|
||||||
path = originalPath,
|
path = originalPath,
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
@ -51,16 +54,17 @@ fun ChosenAudio.toContentAttachmentData(): ContentAttachmentData {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ChosenFile.mapType(): ContentAttachmentData.Type {
|
private fun ChosenFile.mapType(): ContentAttachmentData.Type {
|
||||||
return when {
|
return when {
|
||||||
mimeType.startsWith("image/") -> ContentAttachmentData.Type.IMAGE
|
mimeType?.startsWith("image/") == true -> ContentAttachmentData.Type.IMAGE
|
||||||
mimeType.startsWith("video/") -> ContentAttachmentData.Type.VIDEO
|
mimeType?.startsWith("video/") == true -> ContentAttachmentData.Type.VIDEO
|
||||||
mimeType.startsWith("audio/") -> ContentAttachmentData.Type.AUDIO
|
mimeType?.startsWith("audio/") == true -> ContentAttachmentData.Type.AUDIO
|
||||||
else -> ContentAttachmentData.Type.FILE
|
else -> ContentAttachmentData.Type.FILE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ChosenImage.toContentAttachmentData(): ContentAttachmentData {
|
fun ChosenImage.toContentAttachmentData(): ContentAttachmentData {
|
||||||
|
if (mimeType == null) Timber.w("No mimeType")
|
||||||
return ContentAttachmentData(
|
return ContentAttachmentData(
|
||||||
path = originalPath,
|
path = originalPath,
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
@ -75,6 +79,7 @@ fun ChosenImage.toContentAttachmentData(): ContentAttachmentData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ChosenVideo.toContentAttachmentData(): ContentAttachmentData {
|
fun ChosenVideo.toContentAttachmentData(): ContentAttachmentData {
|
||||||
|
if (mimeType == null) Timber.w("No mimeType")
|
||||||
return ContentAttachmentData(
|
return ContentAttachmentData(
|
||||||
path = originalPath,
|
path = originalPath,
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user