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
This commit is contained in:
Adam Brown 2021-11-24 10:21:12 +00:00
parent 72bc442fca
commit 5ee379e10d
5 changed files with 11 additions and 9 deletions

View file

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

View file

@ -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)
}

View file

@ -208,6 +208,7 @@ internal class LocalEchoEventFactory @Inject constructor(
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)
}
}

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")
return ContentAttachmentData(
mimeType = mimeType,
type = mapType(),
type = if (isVoiceMessage) ContentAttachmentData.Type.VOICE_MESSAGE else mapType(),
size = size,
name = displayName,
duration = duration,

View file

@ -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()
}