mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-18 04:50:08 +03:00
Remove redundant mimetype (vector-im/element-web#2547)
This commit is contained in:
parent
edd24de4c3
commit
0d02a197a5
9 changed files with 15 additions and 21 deletions
1
changelog.d/3273.feature
Normal file
1
changelog.d/3273.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Remove redundant mimetype (vector-im/element-web#2547)
|
|
@ -54,5 +54,5 @@ data class MessageAudioContent(
|
||||||
) : MessageWithAttachmentContent {
|
) : MessageWithAttachmentContent {
|
||||||
|
|
||||||
override val mimeType: String?
|
override val mimeType: String?
|
||||||
get() = encryptedFileInfo?.mimetype ?: audioInfo?.mimeType
|
get() = audioInfo?.mimeType
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,7 @@ data class MessageFileContent(
|
||||||
) : MessageWithAttachmentContent {
|
) : MessageWithAttachmentContent {
|
||||||
|
|
||||||
override val mimeType: String?
|
override val mimeType: String?
|
||||||
get() = encryptedFileInfo?.mimetype
|
get() = info?.mimeType
|
||||||
?: info?.mimeType
|
|
||||||
?: MimeTypeMap.getFileExtensionFromUrl(filename ?: body)?.let { extension ->
|
?: MimeTypeMap.getFileExtensionFromUrl(filename ?: body)?.let { extension ->
|
||||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import org.matrix.android.sdk.api.session.events.model.Content
|
import org.matrix.android.sdk.api.session.events.model.Content
|
||||||
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
|
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
|
||||||
import org.matrix.android.sdk.api.util.MimeTypes
|
|
||||||
import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileInfo
|
import org.matrix.android.sdk.internal.crypto.model.rest.EncryptedFileInfo
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
|
@ -55,5 +54,5 @@ data class MessageImageContent(
|
||||||
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
||||||
) : MessageImageInfoContent {
|
) : MessageImageInfoContent {
|
||||||
override val mimeType: String?
|
override val mimeType: String?
|
||||||
get() = encryptedFileInfo?.mimetype ?: info?.mimeType ?: MimeTypes.Images
|
get() = info?.mimeType
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,5 +55,5 @@ data class MessageStickerContent(
|
||||||
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
||||||
) : MessageImageInfoContent {
|
) : MessageImageInfoContent {
|
||||||
override val mimeType: String?
|
override val mimeType: String?
|
||||||
get() = encryptedFileInfo?.mimetype ?: info?.mimeType
|
get() = info?.mimeType
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,5 @@ data class MessageVideoContent(
|
||||||
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
@Json(name = "file") override val encryptedFileInfo: EncryptedFileInfo? = null
|
||||||
) : MessageWithAttachmentContent {
|
) : MessageWithAttachmentContent {
|
||||||
override val mimeType: String?
|
override val mimeType: String?
|
||||||
get() = encryptedFileInfo?.mimetype ?: videoInfo?.mimeType
|
get() = videoInfo?.mimeType
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,9 @@ internal object MXEncryptedAttachments {
|
||||||
private const val SECRET_KEY_SPEC_ALGORITHM = "AES"
|
private const val SECRET_KEY_SPEC_ALGORITHM = "AES"
|
||||||
private const val MESSAGE_DIGEST_ALGORITHM = "SHA-256"
|
private const val MESSAGE_DIGEST_ALGORITHM = "SHA-256"
|
||||||
|
|
||||||
fun encrypt(clearStream: InputStream, mimetype: String?, outputFile: File, progress: ((current: Int, total: Int) -> Unit)): EncryptedFileInfo {
|
fun encrypt(clearStream: InputStream,
|
||||||
|
outputFile: File,
|
||||||
|
progress: ((current: Int, total: Int) -> Unit)): EncryptedFileInfo {
|
||||||
val t0 = System.currentTimeMillis()
|
val t0 = System.currentTimeMillis()
|
||||||
val secureRandom = SecureRandom()
|
val secureRandom = SecureRandom()
|
||||||
val initVectorBytes = ByteArray(16) { 0.toByte() }
|
val initVectorBytes = ByteArray(16) { 0.toByte() }
|
||||||
|
@ -86,7 +88,6 @@ internal object MXEncryptedAttachments {
|
||||||
|
|
||||||
return EncryptedFileInfo(
|
return EncryptedFileInfo(
|
||||||
url = null,
|
url = null,
|
||||||
mimetype = mimetype,
|
|
||||||
key = EncryptedFileKey(
|
key = EncryptedFileKey(
|
||||||
alg = "A256CTR",
|
alg = "A256CTR",
|
||||||
ext = true,
|
ext = true,
|
||||||
|
@ -155,10 +156,9 @@ internal object MXEncryptedAttachments {
|
||||||
* Encrypt an attachment stream.
|
* Encrypt an attachment stream.
|
||||||
* DO NOT USE for big files, it will load all in memory
|
* DO NOT USE for big files, it will load all in memory
|
||||||
* @param attachmentStream the attachment stream. Will be closed after this method call.
|
* @param attachmentStream the attachment stream. Will be closed after this method call.
|
||||||
* @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): EncryptionResult {
|
||||||
val t0 = System.currentTimeMillis()
|
val t0 = System.currentTimeMillis()
|
||||||
val secureRandom = SecureRandom()
|
val secureRandom = SecureRandom()
|
||||||
|
|
||||||
|
@ -207,7 +207,6 @@ internal object MXEncryptedAttachments {
|
||||||
return EncryptionResult(
|
return EncryptionResult(
|
||||||
encryptedFileInfo = EncryptedFileInfo(
|
encryptedFileInfo = EncryptedFileInfo(
|
||||||
url = null,
|
url = null,
|
||||||
mimetype = mimetype,
|
|
||||||
key = EncryptedFileKey(
|
key = EncryptedFileKey(
|
||||||
alg = "A256CTR",
|
alg = "A256CTR",
|
||||||
ext = true,
|
ext = true,
|
||||||
|
@ -232,7 +231,9 @@ internal object MXEncryptedAttachments {
|
||||||
* @param outputStream the outputStream where the decrypted attachment will be write.
|
* @param outputStream the outputStream where the decrypted attachment will be write.
|
||||||
* @return true in case of success, false in case of error
|
* @return true in case of success, false in case of error
|
||||||
*/
|
*/
|
||||||
fun decryptAttachment(attachmentStream: InputStream?, elementToDecrypt: ElementToDecrypt?, outputStream: OutputStream): Boolean {
|
fun decryptAttachment(attachmentStream: InputStream?,
|
||||||
|
elementToDecrypt: ElementToDecrypt?,
|
||||||
|
outputStream: OutputStream): Boolean {
|
||||||
// sanity checks
|
// sanity checks
|
||||||
if (null == attachmentStream || elementToDecrypt == null) {
|
if (null == attachmentStream || elementToDecrypt == null) {
|
||||||
Timber.e("## decryptAttachment() : null stream")
|
Timber.e("## decryptAttachment() : null stream")
|
||||||
|
|
|
@ -29,12 +29,6 @@ data class EncryptedFileInfo(
|
||||||
@Json(name = "url")
|
@Json(name = "url")
|
||||||
val url: String? = null,
|
val url: String? = null,
|
||||||
|
|
||||||
/**
|
|
||||||
* Not documented
|
|
||||||
*/
|
|
||||||
@Json(name = "mimetype")
|
|
||||||
val mimetype: String? = null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required. A JSON Web Key object.
|
* Required. A JSON Web Key object.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -234,7 +234,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
|
||||||
.also { filesToDelete.add(it) }
|
.also { filesToDelete.add(it) }
|
||||||
|
|
||||||
uploadedFileEncryptedFileInfo =
|
uploadedFileEncryptedFileInfo =
|
||||||
MXEncryptedAttachments.encrypt(fileToUpload.inputStream(), attachment.getSafeMimeType(), encryptedFile) { read, total ->
|
MXEncryptedAttachments.encrypt(fileToUpload.inputStream(), encryptedFile) { read, total ->
|
||||||
notifyTracker(params) {
|
notifyTracker(params) {
|
||||||
contentUploadStateTracker.setEncrypting(it, read.toLong(), total.toLong())
|
contentUploadStateTracker.setEncrypting(it, read.toLong(), total.toLong())
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
|
||||||
if (params.isEncrypted) {
|
if (params.isEncrypted) {
|
||||||
Timber.v("Encrypt thumbnail")
|
Timber.v("Encrypt thumbnail")
|
||||||
notifyTracker(params) { contentUploadStateTracker.setEncryptingThumbnail(it) }
|
notifyTracker(params) { contentUploadStateTracker.setEncryptingThumbnail(it) }
|
||||||
val encryptionResult = MXEncryptedAttachments.encryptAttachment(thumbnailData.bytes.inputStream(), thumbnailData.mimeType)
|
val encryptionResult = MXEncryptedAttachments.encryptAttachment(thumbnailData.bytes.inputStream())
|
||||||
val contentUploadResponse = fileUploader.uploadByteArray(
|
val contentUploadResponse = fileUploader.uploadByteArray(
|
||||||
byteArray = encryptionResult.encryptedByteArray,
|
byteArray = encryptionResult.encryptedByteArray,
|
||||||
filename = null,
|
filename = null,
|
||||||
|
|
Loading…
Add table
Reference in a new issue