diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 8cb46824427..1933952e3c9 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. ### Breaking changes: +- The `waveform` parameter in `Timeline::send_voice_message` format changed to a list of `f32` + between 0 and 1. + ([#5732](https://github.com/matrix-org/matrix-rust-sdk/pull/5732)) + - The `normalized_power_level` field has been removed from the `RoomMember` struct. ([#5635](https://github.com/matrix-org/matrix-rust-sdk/pull/5635)) @@ -30,8 +34,8 @@ All notable changes to this project will be documented in this file. ### Features: -- Add `LowPriority` and `NonLowPriority` variants to `RoomListEntriesDynamicFilterKind` for filtering - rooms based on their low priority status. These filters allow clients to show only low priority rooms +- Add `LowPriority` and `NonLowPriority` variants to `RoomListEntriesDynamicFilterKind` for filtering + rooms based on their low priority status. These filters allow clients to show only low priority rooms or exclude low priority rooms from the room list. ([#5508](https://github.com/matrix-org/matrix-rust-sdk/pull/5508)) - Add `room_version` and `privileged_creators_role` to `RoomInfo` ([#5449](https://github.com/matrix-org/matrix-rust-sdk/pull/5449)). diff --git a/bindings/matrix-sdk-ffi/src/ruma.rs b/bindings/matrix-sdk-ffi/src/ruma.rs index b44414abd3d..bd167f90669 100644 --- a/bindings/matrix-sdk-ffi/src/ruma.rs +++ b/bindings/matrix-sdk-ffi/src/ruma.rs @@ -736,7 +736,7 @@ impl TryFrom<&AudioInfo> for BaseAudioInfo { let size = UInt::try_from(value.size.ok_or(MediaInfoError::MissingField)?) .map_err(|_| MediaInfoError::InvalidField)?; - Ok(BaseAudioInfo { duration: Some(duration), size: Some(size) }) + Ok(BaseAudioInfo { duration: Some(duration), size: Some(size), waveform: None }) } } diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 5687bbced86..93e51467c47 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -424,14 +424,12 @@ impl Timeline { self: Arc, params: UploadParameters, audio_info: AudioInfo, - waveform: Vec, + waveform: Vec, ) -> Result, RoomError> { - let attachment_info = AttachmentInfo::Voice { - audio_info: BaseAudioInfo::try_from(&audio_info) - .map_err(|_| RoomError::InvalidAttachmentData)?, - waveform: Some(waveform), - }; - self.send_attachment(params, attachment_info, audio_info.mimetype, None) + let mut info = + BaseAudioInfo::try_from(&audio_info).map_err(|_| RoomError::InvalidAttachmentData)?; + info.waveform = Some(waveform); + self.send_attachment(params, AttachmentInfo::Voice(info), audio_info.mimetype, None) } pub fn send_file( diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index b46512f5938..4d933acfa81 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -17,6 +17,10 @@ All notable changes to this project will be documented in this file. ### Refactor +- [**breaking**]: The `waveform` field was moved from `AttachmentInfo::Voice` to `BaseAudioInfo`, + allowing to set it for any audio message. Its format also changed, and it is now a list of `f32` + between 0 and 1. + ([#5732](https://github.com/matrix-org/matrix-rust-sdk/pull/5732)) - [**breaking**] The `caption` and `formatted_caption` fields and methods of `AttachmentConfig`, `GalleryConfig` and `GalleryItemInfo` have been merged into a single field that uses `TextMessageEventContent`. diff --git a/crates/matrix-sdk/src/attachment.rs b/crates/matrix-sdk/src/attachment.rs index 2aa4a2e13f8..67c2e0fe817 100644 --- a/crates/matrix-sdk/src/attachment.rs +++ b/crates/matrix-sdk/src/attachment.rs @@ -66,6 +66,10 @@ pub struct BaseAudioInfo { pub duration: Option, /// The file size of the audio clip in bytes. pub size: Option, + /// The waveform of the audio clip. + /// + /// Must only include values between 0 and 1. + pub waveform: Option>, } /// Base metadata about a file. @@ -87,12 +91,7 @@ pub enum AttachmentInfo { /// The metadata of a file. File(BaseFileInfo), /// The metadata of a voice message - Voice { - /// The audio info - audio_info: BaseAudioInfo, - /// The waveform of the voice message - waveform: Option>, - }, + Voice(BaseAudioInfo), } impl From for ImageInfo { @@ -128,14 +127,12 @@ impl From for VideoInfo { impl From for AudioInfo { fn from(info: AttachmentInfo) -> Self { match info { - AttachmentInfo::Audio(info) => assign!(AudioInfo::new(), { - duration: info.duration, - size: info.size, - }), - AttachmentInfo::Voice { audio_info, .. } => assign!(AudioInfo::new(), { - duration: audio_info.duration, - size: audio_info.size, - }), + AttachmentInfo::Audio(info) | AttachmentInfo::Voice(info) => { + assign!(AudioInfo::new(), { + duration: info.duration, + size: info.size, + }) + } _ => AudioInfo::new(), } } diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index b98ef991316..66c885b9434 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -116,7 +116,7 @@ use ruma::{ message::{ AudioInfo, AudioMessageEventContent, FileInfo, FileMessageEventContent, ImageMessageEventContent, MessageType, RoomMessageEventContent, - TextMessageEventContent, UnstableAudioDetailsContentBlock, + TextMessageEventContent, UnstableAmplitude, UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock, VideoInfo, VideoMessageEventContent, }, name::RoomNameEventContent, @@ -324,14 +324,18 @@ macro_rules! make_media_type { filename }); - if let Some(AttachmentInfo::Voice { audio_info, waveform: Some(waveform_vec) }) = - &$info - { - if let Some(duration) = audio_info.duration { - let waveform = waveform_vec.iter().map(|v| (*v).into()).collect(); - content.audio = - Some(UnstableAudioDetailsContentBlock::new(duration, waveform)); - } + if let Some(AttachmentInfo::Audio(audio_info) | AttachmentInfo::Voice(audio_info)) = &$info && + let Some(duration) = audio_info.duration && let Some(waveform_vec) = &audio_info.waveform { + let waveform = waveform_vec + .iter() + .map(|v| ((*v).clamp(0.0, 1.0) * UnstableAmplitude::MAX as f32) as u16) + .map(Into::into) + .collect(); + content.audio = + Some(UnstableAudioDetailsContentBlock::new(duration, waveform)); + } + + if matches!($info, Some(AttachmentInfo::Voice(_))) { content.voice = Some(UnstableVoiceContentBlock::new()); }