From 5ee379e10d48a94bf338928de99e733b999c4b6e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 24 Nov 2021 10:21:12 +0000 Subject: [PATCH 1/5] including a new voice message attachment type - allows for us to explictly delete voice message after uploading rather than inferring that audio message with the .ogg extension are voice messages which could have caused us to delete users files --- .../sdk/api/session/content/ContentAttachmentData.kt | 3 ++- .../sdk/internal/session/content/UploadContentWorker.kt | 2 +- .../internal/session/room/send/LocalEchoEventFactory.kt | 9 +++++---- .../vector/app/features/attachments/AttachmentsMapper.kt | 4 ++-- .../room/detail/composer/MessageComposerViewModel.kt | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) 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..91433fde18 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) + ContentAttachmentData.Type.VOICE_MESSAGE -> createAudioEvent(roomId, attachment) + ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment) } } 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..5b43b67aac 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, 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 b9932e32ee..579394c1ae 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() } From 00059e7b70ab216ff7d13a50605f5da659f480e8 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 24 Nov 2021 10:33:53 +0000 Subject: [PATCH 2/5] adding missing . for file extension --- .../java/im/vector/app/features/voice/AbstractVoiceRecorder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From aa3631f3288b6450f071923a9f60078f6f68656d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 24 Nov 2021 10:58:21 +0000 Subject: [PATCH 3/5] fixing recursive call --- .../im/vector/app/features/attachments/AttachmentsMapper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b43b67aac..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 @@ -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") } From 8a8a5bfa50136d4ad3fe74e2f2eacf580140e83e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 24 Nov 2021 11:00:43 +0000 Subject: [PATCH 4/5] adding changelog entry --- changelog.d/4552.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4552.bugfix 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 From 31bd4fd2d04706355bf10b4541673682a15f4a73 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 24 Nov 2021 11:38:28 +0000 Subject: [PATCH 5/5] avoiding inferred voice type check via waveform in favour of using the attachment type --- .../internal/session/room/send/LocalEchoEventFactory.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 91433fde18..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 @@ -207,8 +207,8 @@ internal class LocalEchoEventFactory @Inject constructor( return when (attachment.type) { ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment) ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment) - ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment) - ContentAttachmentData.Type.VOICE_MESSAGE -> createAudioEvent(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) } } @@ -297,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",