Merge pull request #4553 from vector-im/feature/adm/stricter-voice-file-deletion

Unable to upload .ogg to rooms
This commit is contained in:
Benoit Marty 2021-11-24 13:55:31 +01:00 committed by GitHub
commit 32441eb81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 13 deletions

1
changelog.d/4552.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes .ogg files failing to upload to rooms

View File

@ -44,7 +44,8 @@ data class ContentAttachmentData(
FILE, FILE,
IMAGE, IMAGE,
AUDIO, AUDIO,
VIDEO VIDEO,
VOICE_MESSAGE
} }
fun getSafeMimeType() = mimeType?.normalizeMimeType() fun getSafeMimeType() = mimeType?.normalizeMimeType()

View File

@ -280,7 +280,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
} }
// Delete the temporary voice message file // 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) context.contentResolver.delete(params.attachment.queryUri, null, null)
} }

View File

@ -205,10 +205,11 @@ internal class LocalEchoEventFactory @Inject constructor(
fun createMediaEvent(roomId: String, attachment: ContentAttachmentData): Event { fun createMediaEvent(roomId: String, attachment: ContentAttachmentData): Event {
return when (attachment.type) { return when (attachment.type) {
ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment) ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment)
ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment) ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment)
ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment) ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment, isVoiceMessage = false)
ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment) 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) return createMessageEvent(roomId, content)
} }
private fun createAudioEvent(roomId: String, attachment: ContentAttachmentData): Event { private fun createAudioEvent(roomId: String, attachment: ContentAttachmentData, isVoiceMessage: Boolean): Event {
val isVoiceMessage = attachment.waveform != null
val content = MessageAudioContent( val content = MessageAudioContent(
msgType = MessageType.MSGTYPE_AUDIO, msgType = MessageType.MSGTYPE_AUDIO,
body = attachment.name ?: "audio", body = attachment.name ?: "audio",

View File

@ -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") if (mimeType == null) Timber.w("No mimeType")
return ContentAttachmentData( return ContentAttachmentData(
mimeType = mimeType, mimeType = mimeType,
type = mapType(), type = if (isVoiceMessage) ContentAttachmentData.Type.VOICE_MESSAGE else mapType(),
size = size, size = size,
name = displayName, name = displayName,
duration = duration, duration = duration,
@ -75,7 +75,7 @@ fun MultiPickerBaseType.toContentAttachmentData(): ContentAttachmentData {
return when (this) { return when (this) {
is MultiPickerImageType -> toContentAttachmentData() is MultiPickerImageType -> toContentAttachmentData()
is MultiPickerVideoType -> toContentAttachmentData() is MultiPickerVideoType -> toContentAttachmentData()
is MultiPickerAudioType -> toContentAttachmentData() is MultiPickerAudioType -> toContentAttachmentData(isVoiceMessage = false)
is MultiPickerFileType -> toContentAttachmentData() is MultiPickerFileType -> toContentAttachmentData()
else -> throw IllegalStateException("Unknown file type") else -> throw IllegalStateException("Unknown file type")
} }

View File

@ -714,7 +714,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} else { } else {
voiceMessageHelper.stopRecording()?.let { audioType -> voiceMessageHelper.stopRecording()?.let { audioType ->
if (audioType.duration > 1000) { if (audioType.duration > 1000) {
room.sendMedia(audioType.toContentAttachmentData(), false, emptySet()) room.sendMedia(audioType.toContentAttachmentData(isVoiceMessage = true), false, emptySet())
} else { } else {
voiceMessageHelper.deleteRecording() voiceMessageHelper.deleteRecording()
} }

View File

@ -62,7 +62,7 @@ abstract class AbstractVoiceRecorder(
override fun startRecord() { override fun startRecord() {
init() init()
outputFile = File(outputDirectory, "${UUID.randomUUID()}$filenameExt") outputFile = File(outputDirectory, "${UUID.randomUUID()}.$filenameExt")
val mr = mediaRecorder ?: return val mr = mediaRecorder ?: return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {