use std::time::Duration;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::{
audio::Amplitude, file::FileContentBlock, message::TextContentBlock, room::message::Relation,
};
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "org.matrix.msc3245.voice.v2", kind = MessageLike, without_relation)]
pub struct VoiceEventContent {
#[serde(rename = "org.matrix.msc1767.text")]
pub text: TextContentBlock,
#[serde(rename = "org.matrix.msc1767.file")]
pub file: FileContentBlock,
#[serde(rename = "org.matrix.msc1767.audio_details")]
pub audio_details: VoiceAudioDetailsContentBlock,
#[cfg(feature = "unstable-msc3955")]
#[serde(
default,
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
#[serde(
flatten,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)]
pub relates_to: Option<Relation<VoiceEventContentWithoutRelation>>,
}
impl VoiceEventContent {
pub fn new(
text: TextContentBlock,
file: FileContentBlock,
audio_details: VoiceAudioDetailsContentBlock,
) -> Self {
Self {
text,
file,
audio_details,
#[cfg(feature = "unstable-msc3955")]
automated: false,
relates_to: None,
}
}
pub fn with_plain_text(
plain_text: impl Into<String>,
file: FileContentBlock,
audio_details: VoiceAudioDetailsContentBlock,
) -> Self {
Self {
text: TextContentBlock::plain(plain_text),
file,
audio_details,
#[cfg(feature = "unstable-msc3955")]
automated: false,
relates_to: None,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct VoiceAudioDetailsContentBlock {
#[serde(with = "ruma_common::serde::duration::secs")]
pub duration: Duration,
#[serde(rename = "org.matrix.msc3246.waveform")]
pub waveform: Vec<Amplitude>,
}
impl VoiceAudioDetailsContentBlock {
pub fn new(duration: Duration, waveform: Vec<Amplitude>) -> Self {
Self { duration, waveform }
}
}