Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)).
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/ruma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand Down
12 changes: 5 additions & 7 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,12 @@ impl Timeline {
self: Arc<Self>,
params: UploadParameters,
audio_info: AudioInfo,
waveform: Vec<u16>,
waveform: Vec<f32>,
) -> Result<Arc<SendAttachmentJoinHandle>, 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(
Expand Down
4 changes: 4 additions & 0 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
25 changes: 11 additions & 14 deletions crates/matrix-sdk/src/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pub struct BaseAudioInfo {
pub duration: Option<Duration>,
/// The file size of the audio clip in bytes.
pub size: Option<UInt>,
/// The waveform of the audio clip.
///
/// Must only include values between 0 and 1.
pub waveform: Option<Vec<f32>>,
}

/// Base metadata about a file.
Expand All @@ -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<Vec<u16>>,
},
Voice(BaseAudioInfo),
}

impl From<AttachmentInfo> for ImageInfo {
Expand Down Expand Up @@ -128,14 +127,12 @@ impl From<AttachmentInfo> for VideoInfo {
impl From<AttachmentInfo> 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(),
}
}
Expand Down
22 changes: 13 additions & 9 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ use ruma::{
message::{
AudioInfo, AudioMessageEventContent, FileInfo, FileMessageEventContent,
ImageMessageEventContent, MessageType, RoomMessageEventContent,
TextMessageEventContent, UnstableAudioDetailsContentBlock,
TextMessageEventContent, UnstableAmplitude, UnstableAudioDetailsContentBlock,
UnstableVoiceContentBlock, VideoInfo, VideoMessageEventContent,
},
name::RoomNameEventContent,
Expand Down Expand Up @@ -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());
}

Expand Down
Loading