Merge pull request #4553 from vector-im/feature/adm/stricter-voice-file-deletion
Unable to upload .ogg to rooms
This commit is contained in:
commit
32441eb81b
1
changelog.d/4552.bugfix
Normal file
1
changelog.d/4552.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fixes .ogg files failing to upload to rooms
|
@ -44,7 +44,8 @@ data class ContentAttachmentData(
|
||||
FILE,
|
||||
IMAGE,
|
||||
AUDIO,
|
||||
VIDEO
|
||||
VIDEO,
|
||||
VOICE_MESSAGE
|
||||
}
|
||||
|
||||
fun getSafeMimeType() = mimeType?.normalizeMimeType()
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user