diff --git a/changelog.d/4552.bugfix b/changelog.d/4552.bugfix new file mode 100644 index 0000000000..188e5fb1f6 --- /dev/null +++ b/changelog.d/4552.bugfix @@ -0,0 +1 @@ +Fixes .ogg files failing to upload to rooms \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt index 7ee26de8db..a3d8e83740 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/content/ContentAttachmentData.kt @@ -44,7 +44,8 @@ data class ContentAttachmentData( FILE, IMAGE, AUDIO, - VIDEO + VIDEO, + VOICE_MESSAGE } fun getSafeMimeType() = mimeType?.normalizeMimeType() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt index 86e0630fcf..7f35c91010 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt @@ -280,7 +280,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter } // Delete the temporary voice message file - if (params.attachment.type == ContentAttachmentData.Type.AUDIO && params.attachment.mimeType == MimeTypes.Ogg) { + if (params.attachment.type == ContentAttachmentData.Type.VOICE_MESSAGE) { context.contentResolver.delete(params.attachment.queryUri, null, null) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt index 5cb9687518..a31d0cdec3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt @@ -205,10 +205,11 @@ internal class LocalEchoEventFactory @Inject constructor( fun createMediaEvent(roomId: String, attachment: ContentAttachmentData): Event { return when (attachment.type) { - ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment) - ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment) - ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment) - ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment) + ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment) + ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment) + ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment, isVoiceMessage = false) + ContentAttachmentData.Type.VOICE_MESSAGE -> createAudioEvent(roomId, attachment, isVoiceMessage = true) + ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment) } } @@ -296,8 +297,7 @@ internal class LocalEchoEventFactory @Inject constructor( return createMessageEvent(roomId, content) } - private fun createAudioEvent(roomId: String, attachment: ContentAttachmentData): Event { - val isVoiceMessage = attachment.waveform != null + private fun createAudioEvent(roomId: String, attachment: ContentAttachmentData, isVoiceMessage: Boolean): Event { val content = MessageAudioContent( msgType = MessageType.MSGTYPE_AUDIO, body = attachment.name ?: "audio", diff --git a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsMapper.kt b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsMapper.kt index 420ed7c928..00ed6dd6cc 100644 --- a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsMapper.kt +++ b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsMapper.kt @@ -49,11 +49,11 @@ fun MultiPickerFileType.toContentAttachmentData(): ContentAttachmentData { ) } -fun MultiPickerAudioType.toContentAttachmentData(): ContentAttachmentData { +fun MultiPickerAudioType.toContentAttachmentData(isVoiceMessage: Boolean): ContentAttachmentData { if (mimeType == null) Timber.w("No mimeType") return ContentAttachmentData( mimeType = mimeType, - type = mapType(), + type = if (isVoiceMessage) ContentAttachmentData.Type.VOICE_MESSAGE else mapType(), size = size, name = displayName, duration = duration, @@ -75,7 +75,7 @@ fun MultiPickerBaseType.toContentAttachmentData(): ContentAttachmentData { return when (this) { is MultiPickerImageType -> toContentAttachmentData() is MultiPickerVideoType -> toContentAttachmentData() - is MultiPickerAudioType -> toContentAttachmentData() + is MultiPickerAudioType -> toContentAttachmentData(isVoiceMessage = false) is MultiPickerFileType -> toContentAttachmentData() else -> throw IllegalStateException("Unknown file type") } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 7ccee0220c..f4bfb32fce 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -714,7 +714,7 @@ class MessageComposerViewModel @AssistedInject constructor( } else { voiceMessageHelper.stopRecording()?.let { audioType -> if (audioType.duration > 1000) { - room.sendMedia(audioType.toContentAttachmentData(), false, emptySet()) + room.sendMedia(audioType.toContentAttachmentData(isVoiceMessage = true), false, emptySet()) } else { voiceMessageHelper.deleteRecording() } diff --git a/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt b/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt index 5d8bce1ea3..17e08d20b7 100644 --- a/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt +++ b/vector/src/main/java/im/vector/app/features/voice/AbstractVoiceRecorder.kt @@ -62,7 +62,7 @@ abstract class AbstractVoiceRecorder( override fun startRecord() { init() - outputFile = File(outputDirectory, "${UUID.randomUUID()}$filenameExt") + outputFile = File(outputDirectory, "${UUID.randomUUID()}.$filenameExt") val mr = mediaRecorder ?: return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {