Skip to content
Open
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 @@ -24,8 +28,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 @@ -422,14 +422,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
9 changes: 7 additions & 2 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ All notable changes to this project will be documented in this file.
### Features

### 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))
- The Matrix SDK crate now uses the 2024 edition of Rust.
([#5677](https://github.com/matrix-org/matrix-rust-sdk/pull/5677))

Expand Down Expand Up @@ -60,9 +65,9 @@ All notable changes to this project will be documented in this file.

- [**breaking**] `OAuth::login` now allows requesting additional scopes for the authorization code grant.
([#5395](https://github.com/matrix-org/matrix-rust-sdk/pull/5395))
- [**breaking**] `ThreadedEventsLoader::new` now takes optional `tokens` parameter to customise where the pagination
- [**breaking**] `ThreadedEventsLoader::new` now takes optional `tokens` parameter to customise where the pagination
begins ([#5678](https://github.com/matrix-org/matrix-rust-sdk/pull/5678).
- Make `PaginationTokens` `pub`, as well as its `previous` and `next` tokens so they can be assigned from other files
- Make `PaginationTokens` `pub`, as well as its `previous` and `next` tokens so they can be assigned from other files
([#5678](https://github.com/matrix-org/matrix-rust-sdk/pull/5678).

### Refactor
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 includes values between 0 and 1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: include

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
24 changes: 14 additions & 10 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ use ruma::{
message::{
AudioInfo, AudioMessageEventContent, FileInfo, FileMessageEventContent,
FormattedBody, ImageMessageEventContent, MessageType, RoomMessageEventContent,
UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock, VideoInfo,
VideoMessageEventContent,
UnstableAmplitude, UnstableAudioDetailsContentBlock, UnstableVoiceContentBlock,
VideoInfo, VideoMessageEventContent,
},
name::RoomNameEventContent,
pinned_events::RoomPinnedEventsEventContent,
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