1use std::time::Duration;
6
7use ruma_macros::EventContent;
8use serde::{Deserialize, Serialize};
9
10use super::{
11 audio::Amplitude, file::FileContentBlock, message::TextContentBlock, room::message::Relation,
12};
13
14#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
23#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
24#[ruma_event(type = "org.matrix.msc3245.voice.v2", kind = MessageLike, without_relation)]
25pub struct VoiceEventContent {
26 #[serde(rename = "org.matrix.msc1767.text")]
28 pub text: TextContentBlock,
29
30 #[serde(rename = "org.matrix.msc1767.file")]
32 pub file: FileContentBlock,
33
34 #[serde(rename = "org.matrix.msc1767.audio_details")]
36 pub audio_details: VoiceAudioDetailsContentBlock,
37
38 #[cfg(feature = "unstable-msc3955")]
40 #[serde(
41 default,
42 skip_serializing_if = "ruma_common::serde::is_default",
43 rename = "org.matrix.msc1767.automated"
44 )]
45 pub automated: bool,
46
47 #[serde(
49 flatten,
50 skip_serializing_if = "Option::is_none",
51 deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
52 )]
53 pub relates_to: Option<Relation<VoiceEventContentWithoutRelation>>,
54}
55
56impl VoiceEventContent {
57 pub fn new(
60 text: TextContentBlock,
61 file: FileContentBlock,
62 audio_details: VoiceAudioDetailsContentBlock,
63 ) -> Self {
64 Self {
65 text,
66 file,
67 audio_details,
68 #[cfg(feature = "unstable-msc3955")]
69 automated: false,
70 relates_to: None,
71 }
72 }
73
74 pub fn with_plain_text(
77 plain_text: impl Into<String>,
78 file: FileContentBlock,
79 audio_details: VoiceAudioDetailsContentBlock,
80 ) -> Self {
81 Self {
82 text: TextContentBlock::plain(plain_text),
83 file,
84 audio_details,
85 #[cfg(feature = "unstable-msc3955")]
86 automated: false,
87 relates_to: None,
88 }
89 }
90}
91
92#[derive(Clone, Debug, Serialize, Deserialize)]
94#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
95pub struct VoiceAudioDetailsContentBlock {
96 #[serde(with = "ruma_common::serde::duration::secs")]
98 pub duration: Duration,
99
100 #[serde(rename = "org.matrix.msc3246.waveform")]
102 pub waveform: Vec<Amplitude>,
103}
104
105impl VoiceAudioDetailsContentBlock {
106 pub fn new(duration: Duration, waveform: Vec<Amplitude>) -> Self {
109 Self { duration, waveform }
110 }
111}