Extract more content from audio messages. (#1607)
`TimelineItemAudioContent`: - Use `java.time.Duration` instead of milliseconds. This will ease up things in the future because currently milliseconds are sent over the wire but in the future seconds will be sent (as per the stable MSC). Using `Duration` will allow our downstream code to be independent of what's passed over the wire. - Rename `audioSource` property to `mediaSource` to better match its type. `AudioMessageType`: - Add and populate new fields `details` and `isVoiceMessage` to be used by voice messages.
This commit is contained in:
parent
fb02f698d7
commit
80870adfe3
9 changed files with 77 additions and 11 deletions
|
|
@ -238,7 +238,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
backstack.push(navTarget)
|
backstack.push(navTarget)
|
||||||
}
|
}
|
||||||
is TimelineItemAudioContent -> {
|
is TimelineItemAudioContent -> {
|
||||||
val mediaSource = event.content.audioSource
|
val mediaSource = event.content.mediaSource
|
||||||
val navTarget = NavTarget.MediaViewer(
|
val navTarget = NavTarget.MediaViewer(
|
||||||
mediaInfo = MediaInfo(
|
mediaInfo = MediaInfo(
|
||||||
name = event.content.body,
|
name = event.content.body,
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.NoticeMessage
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.UnknownMessageType
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||||
|
import java.time.Duration
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class TimelineItemContentMessageFactory @Inject constructor(
|
class TimelineItemContentMessageFactory @Inject constructor(
|
||||||
|
|
@ -103,11 +104,11 @@ class TimelineItemContentMessageFactory @Inject constructor(
|
||||||
}
|
}
|
||||||
is AudioMessageType -> TimelineItemAudioContent(
|
is AudioMessageType -> TimelineItemAudioContent(
|
||||||
body = messageType.body,
|
body = messageType.body,
|
||||||
audioSource = messageType.source,
|
mediaSource = messageType.source,
|
||||||
duration = messageType.info?.duration?.toMillis() ?: 0L,
|
duration = messageType.info?.duration ?: Duration.ZERO,
|
||||||
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
|
mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream,
|
||||||
formattedFileSize = fileSizeFormatter.format(messageType.info?.size ?: 0),
|
formattedFileSize = fileSizeFormatter.format(messageType.info?.size ?: 0),
|
||||||
fileExtension = fileExtensionExtractor.extractFromName(messageType.body)
|
fileExtension = fileExtensionExtractor.extractFromName(messageType.body),
|
||||||
)
|
)
|
||||||
is FileMessageType -> {
|
is FileMessageType -> {
|
||||||
val fileExtension = fileExtensionExtractor.extractFromName(messageType.body)
|
val fileExtension = fileExtensionExtractor.extractFromName(messageType.body)
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,12 @@ package io.element.android.features.messages.impl.timeline.model.event
|
||||||
|
|
||||||
import io.element.android.features.messages.impl.media.helper.formatFileExtensionAndSize
|
import io.element.android.features.messages.impl.media.helper.formatFileExtensionAndSize
|
||||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
|
import java.time.Duration
|
||||||
|
|
||||||
data class TimelineItemAudioContent(
|
data class TimelineItemAudioContent(
|
||||||
val body: String,
|
val body: String,
|
||||||
val duration: Long,
|
val duration: Duration,
|
||||||
val audioSource: MediaSource,
|
val mediaSource: MediaSource,
|
||||||
val mimeType: String,
|
val mimeType: String,
|
||||||
val formattedFileSize: String,
|
val formattedFileSize: String,
|
||||||
val fileExtension: String,
|
val fileExtension: String,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package io.element.android.features.messages.impl.timeline.model.event
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
|
import java.time.Duration
|
||||||
|
|
||||||
open class TimelineItemAudioContentProvider : PreviewParameterProvider<TimelineItemAudioContent> {
|
open class TimelineItemAudioContentProvider : PreviewParameterProvider<TimelineItemAudioContent> {
|
||||||
override val values: Sequence<TimelineItemAudioContent>
|
override val values: Sequence<TimelineItemAudioContent>
|
||||||
|
|
@ -34,6 +35,6 @@ fun aTimelineItemAudioContent(fileName: String = "A sound.mp3") = TimelineItemAu
|
||||||
mimeType = MimeTypes.Pdf,
|
mimeType = MimeTypes.Pdf,
|
||||||
formattedFileSize = "100kB",
|
formattedFileSize = "100kB",
|
||||||
fileExtension = "mp3",
|
fileExtension = "mp3",
|
||||||
duration = 100,
|
duration = Duration.ofMillis(100),
|
||||||
audioSource = MediaSource(""),
|
mediaSource = MediaSource(""),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ class DefaultRoomLastMessageFormatterTest {
|
||||||
val sharedContentMessagesTypes = arrayOf(
|
val sharedContentMessagesTypes = arrayOf(
|
||||||
TextMessageType(body, null),
|
TextMessageType(body, null),
|
||||||
VideoMessageType(body, MediaSource("url"), null),
|
VideoMessageType(body, MediaSource("url"), null),
|
||||||
AudioMessageType(body, MediaSource("url"), null),
|
AudioMessageType(body, MediaSource("url"), null, null, false),
|
||||||
ImageMessageType(body, MediaSource("url"), null),
|
ImageMessageType(body, MediaSource("url"), null),
|
||||||
FileMessageType(body, MediaSource("url"), null),
|
FileMessageType(body, MediaSource("url"), null),
|
||||||
LocationMessageType(body, "geo:1,2", null),
|
LocationMessageType(body, "geo:1,2", null),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.matrix.api.media
|
||||||
|
|
||||||
|
import java.time.Duration
|
||||||
|
|
||||||
|
data class AudioDetails(
|
||||||
|
val duration: Duration,
|
||||||
|
val waveform: List<Int>,
|
||||||
|
)
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package io.element.android.libraries.matrix.api.timeline.item.event
|
package io.element.android.libraries.matrix.api.timeline.item.event
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.media.AudioDetails
|
||||||
import io.element.android.libraries.matrix.api.media.AudioInfo
|
import io.element.android.libraries.matrix.api.media.AudioInfo
|
||||||
import io.element.android.libraries.matrix.api.media.FileInfo
|
import io.element.android.libraries.matrix.api.media.FileInfo
|
||||||
import io.element.android.libraries.matrix.api.media.ImageInfo
|
import io.element.android.libraries.matrix.api.media.ImageInfo
|
||||||
|
|
@ -46,7 +47,9 @@ data class LocationMessageType(
|
||||||
data class AudioMessageType(
|
data class AudioMessageType(
|
||||||
val body: String,
|
val body: String,
|
||||||
val source: MediaSource,
|
val source: MediaSource,
|
||||||
val info: AudioInfo?
|
val info: AudioInfo?,
|
||||||
|
val details: AudioDetails?,
|
||||||
|
val isVoiceMessage: Boolean,
|
||||||
) : MessageType
|
) : MessageType
|
||||||
|
|
||||||
data class VideoMessageType(
|
data class VideoMessageType(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.matrix.impl.media
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.media.AudioDetails
|
||||||
|
import org.matrix.rustcomponents.sdk.UnstableAudioDetailsContent as RustAudioDetails
|
||||||
|
|
||||||
|
fun RustAudioDetails.map(): AudioDetails = AudioDetails(
|
||||||
|
duration = duration,
|
||||||
|
waveform = waveform.map { it.toInt() },
|
||||||
|
)
|
||||||
|
|
||||||
|
fun AudioDetails.map(): RustAudioDetails = RustAudioDetails(
|
||||||
|
duration = duration,
|
||||||
|
waveform = waveform.map { it.toUShort() }
|
||||||
|
)
|
||||||
|
|
@ -75,7 +75,13 @@ class EventMessageMapper {
|
||||||
|
|
||||||
fun mapMessageType(type: RustMessageType?) = when (type) {
|
fun mapMessageType(type: RustMessageType?) = when (type) {
|
||||||
is RustMessageType.Audio -> {
|
is RustMessageType.Audio -> {
|
||||||
AudioMessageType(type.content.body, type.content.source.map(), type.content.info?.map())
|
AudioMessageType(
|
||||||
|
body = type.content.body,
|
||||||
|
source = type.content.source.map(),
|
||||||
|
info = type.content.info?.map(),
|
||||||
|
details = type.content.audio?.map(),
|
||||||
|
isVoiceMessage = type.content.voice != null,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
is RustMessageType.File -> {
|
is RustMessageType.File -> {
|
||||||
FileMessageType(type.content.body, type.content.source.map(), type.content.info?.map())
|
FileMessageType(type.content.body, type.content.source.map(), type.content.info?.map())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue