events: Update types according to changes in MSC3551
This commit is contained in:
parent
8477efb2ef
commit
2de1cecec6
@ -13,7 +13,7 @@ mod waveform_serde;
|
|||||||
|
|
||||||
use waveform_serde::WaveformSerDeHelper;
|
use waveform_serde::WaveformSerDeHelper;
|
||||||
|
|
||||||
use super::{file::FileContent, message::TextContentBlock, room::message::Relation};
|
use super::{file::FileContentBlock, message::TextContentBlock, room::message::Relation};
|
||||||
|
|
||||||
/// The payload for an extensible audio message.
|
/// The payload for an extensible audio message.
|
||||||
///
|
///
|
||||||
@ -31,8 +31,8 @@ pub struct AudioEventContent {
|
|||||||
pub text: TextContentBlock,
|
pub text: TextContentBlock,
|
||||||
|
|
||||||
/// The file content of the message.
|
/// The file content of the message.
|
||||||
#[serde(rename = "m.file")]
|
#[serde(rename = "org.matrix.msc1767.file")]
|
||||||
pub file: FileContent,
|
pub file: FileContentBlock,
|
||||||
|
|
||||||
/// The audio content of the message.
|
/// The audio content of the message.
|
||||||
#[serde(rename = "m.audio")]
|
#[serde(rename = "m.audio")]
|
||||||
@ -49,13 +49,13 @@ pub struct AudioEventContent {
|
|||||||
|
|
||||||
impl AudioEventContent {
|
impl AudioEventContent {
|
||||||
/// Creates a new `AudioEventContent` with the given text fallback and file.
|
/// Creates a new `AudioEventContent` with the given text fallback and file.
|
||||||
pub fn new(text: TextContentBlock, file: FileContent) -> Self {
|
pub fn new(text: TextContentBlock, file: FileContentBlock) -> Self {
|
||||||
Self { text, file, audio: Default::default(), relates_to: None }
|
Self { text, file, audio: Default::default(), relates_to: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `AudioEventContent` with the given plain text fallback representation and
|
/// Creates a new `AudioEventContent` with the given plain text fallback representation and
|
||||||
/// file.
|
/// file.
|
||||||
pub fn plain(text_fallback: impl Into<String>, file: FileContent) -> Self {
|
pub fn plain(text_fallback: impl Into<String>, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text_fallback),
|
text: TextContentBlock::plain(text_fallback),
|
||||||
file,
|
file,
|
||||||
|
@ -52,7 +52,8 @@ event_enum! {
|
|||||||
#[ruma_enum(alias = "m.encrypted")]
|
#[ruma_enum(alias = "m.encrypted")]
|
||||||
"org.matrix.msc1767.encrypted" => super::encrypted,
|
"org.matrix.msc1767.encrypted" => super::encrypted,
|
||||||
#[cfg(feature = "unstable-msc3551")]
|
#[cfg(feature = "unstable-msc3551")]
|
||||||
"m.file" => super::file,
|
#[ruma_enum(alias = "m.file")]
|
||||||
|
"org.matrix.msc1767.file" => super::file,
|
||||||
#[cfg(feature = "unstable-msc3552")]
|
#[cfg(feature = "unstable-msc3552")]
|
||||||
"m.image" => super::image,
|
"m.image" => super::image,
|
||||||
"m.key.verification.ready" => super::key::verification::ready,
|
"m.key.verification.ready" => super::key::verification::ready,
|
||||||
|
@ -23,15 +23,28 @@ use crate::{serde::Base64, OwnedMxcUri};
|
|||||||
/// [`message`]: super::message
|
/// [`message`]: super::message
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.file", kind = MessageLike, without_relation)]
|
#[ruma_event(type = "org.matrix.msc1767.file", kind = MessageLike, without_relation)]
|
||||||
pub struct FileEventContent {
|
pub struct FileEventContent {
|
||||||
/// The text representation of the message.
|
/// The text representation of the message.
|
||||||
#[serde(rename = "org.matrix.msc1767.text")]
|
#[serde(rename = "org.matrix.msc1767.text")]
|
||||||
pub text: TextContentBlock,
|
pub text: TextContentBlock,
|
||||||
|
|
||||||
/// The file content of the message.
|
/// The file content of the message.
|
||||||
#[serde(rename = "m.file")]
|
#[serde(rename = "org.matrix.msc1767.file")]
|
||||||
pub file: FileContent,
|
pub file: FileContentBlock,
|
||||||
|
|
||||||
|
/// The caption of the message, if any.
|
||||||
|
#[serde(rename = "org.matrix.msc1767.caption", skip_serializing_if = "Option::is_none")]
|
||||||
|
pub caption: Option<CaptionContentBlock>,
|
||||||
|
|
||||||
|
/// Whether this message is automated.
|
||||||
|
#[cfg(feature = "unstable-msc3955")]
|
||||||
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "crate::serde::is_default",
|
||||||
|
rename = "org.matrix.msc1767.automated"
|
||||||
|
)]
|
||||||
|
pub automated: bool,
|
||||||
|
|
||||||
/// Information about related messages.
|
/// Information about related messages.
|
||||||
#[serde(
|
#[serde(
|
||||||
@ -45,24 +58,30 @@ pub struct FileEventContent {
|
|||||||
impl FileEventContent {
|
impl FileEventContent {
|
||||||
/// Creates a new non-encrypted `FileEventContent` with the given fallback representation, url
|
/// Creates a new non-encrypted `FileEventContent` with the given fallback representation, url
|
||||||
/// and file info.
|
/// and file info.
|
||||||
pub fn plain(
|
pub fn plain(text: TextContentBlock, url: OwnedMxcUri, name: String) -> Self {
|
||||||
text: TextContentBlock,
|
Self {
|
||||||
url: OwnedMxcUri,
|
text,
|
||||||
info: Option<Box<FileContentInfo>>,
|
file: FileContentBlock::plain(url, name),
|
||||||
) -> Self {
|
caption: None,
|
||||||
Self { text, file: FileContent::plain(url, info), relates_to: None }
|
#[cfg(feature = "unstable-msc3955")]
|
||||||
|
automated: false,
|
||||||
|
relates_to: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new non-encrypted `FileEventContent` with the given plain text fallback
|
/// Creates a new non-encrypted `FileEventContent` with the given plain text fallback
|
||||||
/// representation, url and file info.
|
/// representation, url and file info.
|
||||||
pub fn plain_with_text(
|
pub fn plain_with_plain_text(
|
||||||
text: impl Into<String>,
|
plain_text: impl Into<String>,
|
||||||
url: OwnedMxcUri,
|
url: OwnedMxcUri,
|
||||||
info: Option<Box<FileContentInfo>>,
|
name: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text),
|
text: TextContentBlock::plain(plain_text),
|
||||||
file: FileContent::plain(url, info),
|
file: FileContentBlock::plain(url, name),
|
||||||
|
caption: None,
|
||||||
|
#[cfg(feature = "unstable-msc3955")]
|
||||||
|
automated: false,
|
||||||
relates_to: None,
|
relates_to: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,74 +91,47 @@ impl FileEventContent {
|
|||||||
pub fn encrypted(
|
pub fn encrypted(
|
||||||
text: TextContentBlock,
|
text: TextContentBlock,
|
||||||
url: OwnedMxcUri,
|
url: OwnedMxcUri,
|
||||||
|
name: String,
|
||||||
encryption_info: EncryptedContent,
|
encryption_info: EncryptedContent,
|
||||||
info: Option<Box<FileContentInfo>>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { text, file: FileContent::encrypted(url, encryption_info, info), relates_to: None }
|
Self {
|
||||||
|
text,
|
||||||
|
file: FileContentBlock::encrypted(url, name, encryption_info),
|
||||||
|
caption: None,
|
||||||
|
#[cfg(feature = "unstable-msc3955")]
|
||||||
|
automated: false,
|
||||||
|
relates_to: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new encrypted `FileEventContent` with the given plain text fallback
|
/// Creates a new encrypted `FileEventContent` with the given plain text fallback
|
||||||
/// representation, url, encryption info and file info.
|
/// representation, url, encryption info and file info.
|
||||||
pub fn encrypted_with_text(
|
pub fn encrypted_with_plain_text(
|
||||||
text: impl Into<String>,
|
plain_text: impl Into<String>,
|
||||||
url: OwnedMxcUri,
|
url: OwnedMxcUri,
|
||||||
|
name: String,
|
||||||
encryption_info: EncryptedContent,
|
encryption_info: EncryptedContent,
|
||||||
info: Option<Box<FileContentInfo>>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text),
|
text: TextContentBlock::plain(plain_text),
|
||||||
file: FileContent::encrypted(url, encryption_info, info),
|
file: FileContentBlock::encrypted(url, name, encryption_info),
|
||||||
|
caption: None,
|
||||||
|
#[cfg(feature = "unstable-msc3955")]
|
||||||
|
automated: false,
|
||||||
relates_to: None,
|
relates_to: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// File content.
|
/// A block for file content.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct FileContent {
|
pub struct FileContentBlock {
|
||||||
/// The URL to the file.
|
/// The URL to the file.
|
||||||
pub url: OwnedMxcUri,
|
pub url: OwnedMxcUri,
|
||||||
|
|
||||||
/// Information about the uploaded file.
|
|
||||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub info: Option<Box<FileContentInfo>>,
|
|
||||||
|
|
||||||
/// Information on the encrypted file.
|
|
||||||
///
|
|
||||||
/// Required if the file is encrypted.
|
|
||||||
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
|
||||||
pub encryption_info: Option<Box<EncryptedContent>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileContent {
|
|
||||||
/// Creates a new non-encrypted `FileContent` with the given url and file info.
|
|
||||||
pub fn plain(url: OwnedMxcUri, info: Option<Box<FileContentInfo>>) -> Self {
|
|
||||||
Self { url, info, encryption_info: None }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new encrypted `FileContent` with the given url, encryption info and file info.
|
|
||||||
pub fn encrypted(
|
|
||||||
url: OwnedMxcUri,
|
|
||||||
encryption_info: EncryptedContent,
|
|
||||||
info: Option<Box<FileContentInfo>>,
|
|
||||||
) -> Self {
|
|
||||||
Self { url, info, encryption_info: Some(Box::new(encryption_info)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the file is encrypted.
|
|
||||||
pub fn is_encrypted(&self) -> bool {
|
|
||||||
self.encryption_info.is_some()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information about a file content.
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
pub struct FileContentInfo {
|
|
||||||
/// The original filename of the uploaded file.
|
/// The original filename of the uploaded file.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub name: String,
|
||||||
pub name: Option<String>,
|
|
||||||
|
|
||||||
/// The mimetype of the file, e.g. "application/msword".
|
/// The mimetype of the file, e.g. "application/msword".
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -148,12 +140,34 @@ pub struct FileContentInfo {
|
|||||||
/// The size of the file in bytes.
|
/// The size of the file in bytes.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub size: Option<UInt>,
|
pub size: Option<UInt>,
|
||||||
|
|
||||||
|
/// Information on the encrypted file.
|
||||||
|
///
|
||||||
|
/// Required if the file is encrypted.
|
||||||
|
#[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub encryption_info: Option<Box<EncryptedContent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileContentInfo {
|
impl FileContentBlock {
|
||||||
/// Creates an empty `FileContentInfo`.
|
/// Creates a new non-encrypted `FileContentBlock` with the given url and name.
|
||||||
pub fn new() -> Self {
|
pub fn plain(url: OwnedMxcUri, name: String) -> Self {
|
||||||
Self::default()
|
Self { url, name, mimetype: None, size: None, encryption_info: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new encrypted `FileContentBlock` with the given url, name and encryption info.
|
||||||
|
pub fn encrypted(url: OwnedMxcUri, name: String, encryption_info: EncryptedContent) -> Self {
|
||||||
|
Self {
|
||||||
|
url,
|
||||||
|
name,
|
||||||
|
mimetype: None,
|
||||||
|
size: None,
|
||||||
|
encryption_info: Some(Box::new(encryption_info)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the file is encrypted.
|
||||||
|
pub fn is_encrypted(&self) -> bool {
|
||||||
|
self.encryption_info.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,3 +232,44 @@ impl From<&EncryptedFile> for EncryptedContent {
|
|||||||
Self { key: key.to_owned(), iv: iv.to_owned(), hashes: hashes.to_owned(), v: v.to_owned() }
|
Self { key: key.to_owned(), iv: iv.to_owned(), hashes: hashes.to_owned(), v: v.to_owned() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A block for caption content.
|
||||||
|
///
|
||||||
|
/// A caption is usually a text message that should be displayed next to some media content.
|
||||||
|
///
|
||||||
|
/// To construct a `CaptionContentBlock` with a custom [`TextContentBlock`], convert it with
|
||||||
|
/// `CaptionContentBlock::from()` / `.into()`.
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct CaptionContentBlock {
|
||||||
|
/// The text message of the caption.
|
||||||
|
#[serde(rename = "org.matrix.msc1767.text")]
|
||||||
|
pub text: TextContentBlock,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CaptionContentBlock {
|
||||||
|
/// A convenience constructor to create a plain text caption content block.
|
||||||
|
pub fn plain(body: impl Into<String>) -> Self {
|
||||||
|
Self { text: TextContentBlock::plain(body) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A convenience constructor to create an HTML caption content block.
|
||||||
|
pub fn html(body: impl Into<String>, html_body: impl Into<String>) -> Self {
|
||||||
|
Self { text: TextContentBlock::html(body, html_body) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A convenience constructor to create a caption content block from Markdown.
|
||||||
|
///
|
||||||
|
/// The content includes an HTML message if some Markdown formatting was detected, otherwise
|
||||||
|
/// only a plain text message is included.
|
||||||
|
#[cfg(feature = "markdown")]
|
||||||
|
pub fn markdown(body: impl AsRef<str> + Into<String>) -> Self {
|
||||||
|
Self { text: TextContentBlock::markdown(body) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TextContentBlock> for CaptionContentBlock {
|
||||||
|
fn from(text: TextContentBlock) -> Self {
|
||||||
|
Self { text }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@ use ruma_macros::EventContent;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
file::{EncryptedContent, FileContent},
|
file::{EncryptedContent, FileContentBlock},
|
||||||
message::TextContentBlock,
|
message::TextContentBlock,
|
||||||
room::message::Relation,
|
room::message::Relation,
|
||||||
};
|
};
|
||||||
@ -29,8 +29,8 @@ pub struct ImageEventContent {
|
|||||||
pub text: TextContentBlock,
|
pub text: TextContentBlock,
|
||||||
|
|
||||||
/// The file content of the message.
|
/// The file content of the message.
|
||||||
#[serde(rename = "m.file")]
|
#[serde(rename = "org.matrix.msc1767.file")]
|
||||||
pub file: FileContent,
|
pub file: FileContentBlock,
|
||||||
|
|
||||||
/// The image content of the message.
|
/// The image content of the message.
|
||||||
#[serde(rename = "m.image")]
|
#[serde(rename = "m.image")]
|
||||||
@ -56,7 +56,7 @@ pub struct ImageEventContent {
|
|||||||
impl ImageEventContent {
|
impl ImageEventContent {
|
||||||
/// Creates a new `ImageEventContent` with the given fallback representation and
|
/// Creates a new `ImageEventContent` with the given fallback representation and
|
||||||
/// file.
|
/// file.
|
||||||
pub fn new(text: TextContentBlock, file: FileContent) -> Self {
|
pub fn new(text: TextContentBlock, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text,
|
text,
|
||||||
file,
|
file,
|
||||||
@ -69,7 +69,7 @@ impl ImageEventContent {
|
|||||||
|
|
||||||
/// Creates a new `ImageEventContent` with the given plain text fallback representation and
|
/// Creates a new `ImageEventContent` with the given plain text fallback representation and
|
||||||
/// file.
|
/// file.
|
||||||
pub fn plain(text_fallback: impl Into<String>, file: FileContent) -> Self {
|
pub fn plain(text_fallback: impl Into<String>, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text_fallback),
|
text: TextContentBlock::plain(text_fallback),
|
||||||
file,
|
file,
|
||||||
|
@ -9,7 +9,8 @@ use ruma_macros::EventContent;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
file::FileContent, image::ThumbnailContent, message::TextContentBlock, room::message::Relation,
|
file::FileContentBlock, image::ThumbnailContent, message::TextContentBlock,
|
||||||
|
room::message::Relation,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The payload for an extensible video message.
|
/// The payload for an extensible video message.
|
||||||
@ -28,8 +29,8 @@ pub struct VideoEventContent {
|
|||||||
pub text: TextContentBlock,
|
pub text: TextContentBlock,
|
||||||
|
|
||||||
/// The file content of the message.
|
/// The file content of the message.
|
||||||
#[serde(rename = "m.file")]
|
#[serde(rename = "org.matrix.msc1767.file")]
|
||||||
pub file: FileContent,
|
pub file: FileContentBlock,
|
||||||
|
|
||||||
/// The video content of the message.
|
/// The video content of the message.
|
||||||
#[serde(rename = "m.video")]
|
#[serde(rename = "m.video")]
|
||||||
@ -54,7 +55,7 @@ pub struct VideoEventContent {
|
|||||||
|
|
||||||
impl VideoEventContent {
|
impl VideoEventContent {
|
||||||
/// Creates a new `VideoEventContent` with the given fallback representation and file.
|
/// Creates a new `VideoEventContent` with the given fallback representation and file.
|
||||||
pub fn new(text: TextContentBlock, file: FileContent) -> Self {
|
pub fn new(text: TextContentBlock, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text,
|
text,
|
||||||
file,
|
file,
|
||||||
@ -67,7 +68,7 @@ impl VideoEventContent {
|
|||||||
|
|
||||||
/// Creates a new `VideoEventContent` with the given plain text fallback representation and
|
/// Creates a new `VideoEventContent` with the given plain text fallback representation and
|
||||||
/// file.
|
/// file.
|
||||||
pub fn plain(text: impl Into<String>, file: FileContent) -> Self {
|
pub fn plain(text: impl Into<String>, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text),
|
text: TextContentBlock::plain(text),
|
||||||
file,
|
file,
|
||||||
|
@ -6,7 +6,7 @@ use ruma_macros::EventContent;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
audio::AudioContent, file::FileContent, message::TextContentBlock, room::message::Relation,
|
audio::AudioContent, file::FileContentBlock, message::TextContentBlock, room::message::Relation,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The payload for an extensible voice message.
|
/// The payload for an extensible voice message.
|
||||||
@ -26,8 +26,8 @@ pub struct VoiceEventContent {
|
|||||||
pub text: TextContentBlock,
|
pub text: TextContentBlock,
|
||||||
|
|
||||||
/// The file content of the message.
|
/// The file content of the message.
|
||||||
#[serde(rename = "m.file")]
|
#[serde(rename = "org.matrix.msc1767.file")]
|
||||||
pub file: FileContent,
|
pub file: FileContentBlock,
|
||||||
|
|
||||||
/// The audio content of the message.
|
/// The audio content of the message.
|
||||||
#[serde(rename = "m.audio")]
|
#[serde(rename = "m.audio")]
|
||||||
@ -48,13 +48,13 @@ pub struct VoiceEventContent {
|
|||||||
|
|
||||||
impl VoiceEventContent {
|
impl VoiceEventContent {
|
||||||
/// Creates a new `VoiceEventContent` with the given fallback representation and file.
|
/// Creates a new `VoiceEventContent` with the given fallback representation and file.
|
||||||
pub fn new(text: TextContentBlock, file: FileContent) -> Self {
|
pub fn new(text: TextContentBlock, file: FileContentBlock) -> Self {
|
||||||
Self { text, file, audio: Default::default(), voice: Default::default(), relates_to: None }
|
Self { text, file, audio: Default::default(), voice: Default::default(), relates_to: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `VoiceEventContent` with the given plain text fallback representation and
|
/// Creates a new `VoiceEventContent` with the given plain text fallback representation and
|
||||||
/// file.
|
/// file.
|
||||||
pub fn plain(text: impl Into<String>, file: FileContent) -> Self {
|
pub fn plain(text: impl Into<String>, file: FileContentBlock) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: TextContentBlock::plain(text),
|
text: TextContentBlock::plain(text),
|
||||||
file,
|
file,
|
||||||
|
@ -9,7 +9,7 @@ use ruma_common::{
|
|||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
audio::{Amplitude, AudioContent, AudioEventContent, Waveform, WaveformError},
|
audio::{Amplitude, AudioContent, AudioEventContent, Waveform, WaveformError},
|
||||||
file::{EncryptedContentInit, FileContent, FileContentInfo},
|
file::{EncryptedContentInit, FileContentBlock},
|
||||||
message::TextContentBlock,
|
message::TextContentBlock,
|
||||||
relation::InReplyTo,
|
relation::InReplyTo,
|
||||||
room::{message::Relation, JsonWebKeyInit},
|
room::{message::Relation, JsonWebKeyInit},
|
||||||
@ -57,7 +57,10 @@ fn waveform_deserialization_clamp_amplitude() {
|
|||||||
fn plain_content_serialization() {
|
fn plain_content_serialization() {
|
||||||
let event_content = AudioEventContent::plain(
|
let event_content = AudioEventContent::plain(
|
||||||
"Upload: my_sound.ogg",
|
"Upload: my_sound.ogg",
|
||||||
FileContent::plain(mxc_uri!("mxc://notareal.hs/abcdef").to_owned(), None),
|
FileContentBlock::plain(
|
||||||
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_sound.ogg".to_owned(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -66,8 +69,9 @@ fn plain_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_sound.ogg" },
|
{ "body": "Upload: my_sound.ogg" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_sound.ogg",
|
||||||
},
|
},
|
||||||
"m.audio": {}
|
"m.audio": {}
|
||||||
})
|
})
|
||||||
@ -78,8 +82,9 @@ fn plain_content_serialization() {
|
|||||||
fn encrypted_content_serialization() {
|
fn encrypted_content_serialization() {
|
||||||
let event_content = AudioEventContent::plain(
|
let event_content = AudioEventContent::plain(
|
||||||
"Upload: my_sound.ogg",
|
"Upload: my_sound.ogg",
|
||||||
FileContent::encrypted(
|
FileContentBlock::encrypted(
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_sound.ogg".to_owned(),
|
||||||
EncryptedContentInit {
|
EncryptedContentInit {
|
||||||
key: JsonWebKeyInit {
|
key: JsonWebKeyInit {
|
||||||
kty: "oct".to_owned(),
|
kty: "oct".to_owned(),
|
||||||
@ -98,7 +103,6 @@ fn encrypted_content_serialization() {
|
|||||||
v: "v2".to_owned(),
|
v: "v2".to_owned(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
None,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -108,8 +112,9 @@ fn encrypted_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_sound.ogg" },
|
{ "body": "Upload: my_sound.ogg" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_sound.ogg",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -121,7 +126,7 @@ fn encrypted_content_serialization() {
|
|||||||
"hashes": {
|
"hashes": {
|
||||||
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
|
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
|
||||||
},
|
},
|
||||||
"v": "v2"
|
"v": "v2",
|
||||||
},
|
},
|
||||||
"m.audio": {}
|
"m.audio": {}
|
||||||
})
|
})
|
||||||
@ -136,16 +141,15 @@ fn event_serialization() {
|
|||||||
"Upload: my_mix.mp3",
|
"Upload: my_mix.mp3",
|
||||||
"Upload: <strong>my_mix.mp3</strong>",
|
"Upload: <strong>my_mix.mp3</strong>",
|
||||||
),
|
),
|
||||||
FileContent::plain(
|
assign!(
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
FileContentBlock::plain(
|
||||||
Some(Box::new(assign!(
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
FileContentInfo::new(),
|
"my_mix.mp3".to_owned()
|
||||||
{
|
),
|
||||||
name: Some("my_mix.mp3".to_owned()),
|
{
|
||||||
mimetype: Some("audio/mp3".to_owned()),
|
mimetype: Some("audio/mp3".to_owned()),
|
||||||
size: Some(uint!(897_774)),
|
size: Some(uint!(897_774)),
|
||||||
}
|
}
|
||||||
))),
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
@ -168,7 +172,7 @@ fn event_serialization() {
|
|||||||
{ "mimetype": "text/html", "body": "Upload: <strong>my_mix.mp3</strong>" },
|
{ "mimetype": "text/html", "body": "Upload: <strong>my_mix.mp3</strong>" },
|
||||||
{ "body": "Upload: my_mix.mp3"},
|
{ "body": "Upload: my_mix.mp3"},
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_mix.mp3",
|
"name": "my_mix.mp3",
|
||||||
"mimetype": "audio/mp3",
|
"mimetype": "audio/mp3",
|
||||||
@ -192,8 +196,9 @@ fn plain_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_new_song.webm" },
|
{ "body": "Upload: my_new_song.webm" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_new_song.webm",
|
||||||
},
|
},
|
||||||
"m.audio": {
|
"m.audio": {
|
||||||
"waveform": [
|
"waveform": [
|
||||||
@ -257,6 +262,7 @@ fn plain_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_new_song.webm"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_new_song.webm"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_new_song.webm");
|
||||||
let waveform = content.audio.waveform.unwrap();
|
let waveform = content.audio.waveform.unwrap();
|
||||||
assert_eq!(waveform.amplitudes().len(), 52);
|
assert_eq!(waveform.amplitudes().len(), 52);
|
||||||
}
|
}
|
||||||
@ -267,8 +273,9 @@ fn encrypted_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_file.txt",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -289,6 +296,7 @@ fn encrypted_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_file.txt");
|
||||||
assert!(content.file.encryption_info.is_some());
|
assert!(content.file.encryption_info.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +307,7 @@ fn message_event_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: airplane_sound.opus" },
|
{ "body": "Upload: airplane_sound.opus" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "airplane_sound.opus",
|
"name": "airplane_sound.opus",
|
||||||
"mimetype": "audio/opus",
|
"mimetype": "audio/opus",
|
||||||
@ -331,10 +339,9 @@ fn message_event_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: airplane_sound.opus"));
|
assert_eq!(content.text.find_plain(), Some("Upload: airplane_sound.opus"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
let info = content.file.info.unwrap();
|
assert_eq!(content.file.name, "airplane_sound.opus");
|
||||||
assert_eq!(info.name.as_deref(), Some("airplane_sound.opus"));
|
assert_eq!(content.file.mimetype.as_deref(), Some("audio/opus"));
|
||||||
assert_eq!(info.mimetype.as_deref(), Some("audio/opus"));
|
assert_eq!(content.file.size, Some(uint!(123_774)));
|
||||||
assert_eq!(info.size, Some(uint!(123_774)));
|
|
||||||
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
||||||
assert_matches!(content.audio.waveform, None);
|
assert_matches!(content.audio.waveform, None);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#![cfg(feature = "unstable-msc3551")]
|
#![cfg(feature = "unstable-msc3551")]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use assign::assign;
|
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
file::{EncryptedContentInit, FileContentInfo, FileEventContent},
|
file::{EncryptedContentInit, FileEventContent},
|
||||||
message::TextContentBlock,
|
message::TextContentBlock,
|
||||||
relation::InReplyTo,
|
relation::InReplyTo,
|
||||||
room::{message::Relation, JsonWebKeyInit},
|
room::{message::Relation, JsonWebKeyInit},
|
||||||
@ -20,10 +19,10 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_content_serialization() {
|
fn plain_content_serialization() {
|
||||||
let event_content = FileEventContent::plain_with_text(
|
let event_content = FileEventContent::plain_with_plain_text(
|
||||||
"Upload: my_file.txt",
|
"Upload: my_file.txt",
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
None,
|
"my_file.txt".to_owned(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -32,8 +31,9 @@ fn plain_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_file.txt",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -41,9 +41,10 @@ fn plain_content_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypted_content_serialization() {
|
fn encrypted_content_serialization() {
|
||||||
let event_content = FileEventContent::encrypted_with_text(
|
let event_content = FileEventContent::encrypted_with_plain_text(
|
||||||
"Upload: my_file.txt",
|
"Upload: my_file.txt",
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_file.txt".to_owned(),
|
||||||
EncryptedContentInit {
|
EncryptedContentInit {
|
||||||
key: JsonWebKeyInit {
|
key: JsonWebKeyInit {
|
||||||
kty: "oct".to_owned(),
|
kty: "oct".to_owned(),
|
||||||
@ -62,7 +63,6 @@ fn encrypted_content_serialization() {
|
|||||||
v: "v2".to_owned(),
|
v: "v2".to_owned(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -71,8 +71,9 @@ fn encrypted_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_file.txt",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -84,7 +85,7 @@ fn encrypted_content_serialization() {
|
|||||||
"hashes": {
|
"hashes": {
|
||||||
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
|
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
|
||||||
},
|
},
|
||||||
"v": "v2"
|
"v": "v2",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -92,28 +93,16 @@ fn encrypted_content_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn file_event_serialization() {
|
fn file_event_serialization() {
|
||||||
let content = assign!(
|
let mut content = FileEventContent::plain(
|
||||||
FileEventContent::plain(
|
TextContentBlock::html("Upload: my_file.txt", "Upload: <strong>my_file.txt</strong>"),
|
||||||
TextContentBlock::html(
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
"Upload: my_file.txt",
|
"my_file.txt".to_owned(),
|
||||||
"Upload: <strong>my_file.txt</strong>",
|
);
|
||||||
),
|
content.file.mimetype = Some("text/plain".to_owned());
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
content.file.size = Some(uint!(774));
|
||||||
Some(Box::new(assign!(
|
content.relates_to = Some(Relation::Reply {
|
||||||
FileContentInfo::new(),
|
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
||||||
{
|
});
|
||||||
name: Some("my_file.txt".to_owned()),
|
|
||||||
mimetype: Some("text/plain".to_owned()),
|
|
||||||
size: Some(uint!(774)),
|
|
||||||
}
|
|
||||||
))),
|
|
||||||
),
|
|
||||||
{
|
|
||||||
relates_to: Some(Relation::Reply {
|
|
||||||
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&content).unwrap(),
|
to_json_value(&content).unwrap(),
|
||||||
@ -122,7 +111,7 @@ fn file_event_serialization() {
|
|||||||
{ "mimetype": "text/html", "body": "Upload: <strong>my_file.txt</strong>" },
|
{ "mimetype": "text/html", "body": "Upload: <strong>my_file.txt</strong>" },
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_file.txt",
|
"name": "my_file.txt",
|
||||||
"mimetype": "text/plain",
|
"mimetype": "text/plain",
|
||||||
@ -143,8 +132,9 @@ fn plain_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_file.txt",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -152,6 +142,7 @@ fn plain_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_file.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -160,8 +151,9 @@ fn encrypted_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_file.txt" },
|
{ "body": "Upload: my_file.txt" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -181,6 +173,7 @@ fn encrypted_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "");
|
||||||
assert!(content.file.encryption_info.is_some());
|
assert!(content.file.encryption_info.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +185,7 @@ fn message_event_deserialization() {
|
|||||||
{ "body": "Upload: <strong>my_file.txt</strong>", "mimetype": "text/html"},
|
{ "body": "Upload: <strong>my_file.txt</strong>", "mimetype": "text/html"},
|
||||||
{ "body": "Upload: my_file.txt", "mimetype": "text/plain"},
|
{ "body": "Upload: my_file.txt", "mimetype": "text/plain"},
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_file.txt",
|
"name": "my_file.txt",
|
||||||
"mimetype": "text/plain",
|
"mimetype": "text/plain",
|
||||||
@ -203,7 +196,7 @@ fn message_event_deserialization() {
|
|||||||
"origin_server_ts": 134_829_848,
|
"origin_server_ts": 134_829_848,
|
||||||
"room_id": "!roomid:notareal.hs",
|
"room_id": "!roomid:notareal.hs",
|
||||||
"sender": "@user:notareal.hs",
|
"sender": "@user:notareal.hs",
|
||||||
"type": "m.file",
|
"type": "org.matrix.msc1767.file",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
let message_event = assert_matches!(
|
||||||
@ -215,10 +208,9 @@ fn message_event_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_file.txt"));
|
||||||
assert_eq!(content.text.find_html(), Some("Upload: <strong>my_file.txt</strong>"));
|
assert_eq!(content.text.find_html(), Some("Upload: <strong>my_file.txt</strong>"));
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
let info = content.file.info.unwrap();
|
assert_eq!(content.file.name, "my_file.txt");
|
||||||
assert_eq!(info.name.as_deref(), Some("my_file.txt"));
|
assert_eq!(content.file.mimetype.as_deref(), Some("text/plain"));
|
||||||
assert_eq!(info.mimetype.as_deref(), Some("text/plain"));
|
assert_eq!(content.file.size, Some(uint!(774)));
|
||||||
assert_eq!(info.size, Some(uint!(774)));
|
|
||||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||||
|
@ -6,7 +6,7 @@ use js_int::uint;
|
|||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
file::{EncryptedContentInit, FileContent, FileContentInfo},
|
file::{EncryptedContentInit, FileContentBlock},
|
||||||
image::{
|
image::{
|
||||||
ImageContent, ImageEventContent, ThumbnailContent, ThumbnailFileContent,
|
ImageContent, ImageEventContent, ThumbnailContent, ThumbnailFileContent,
|
||||||
ThumbnailFileContentInfo,
|
ThumbnailFileContentInfo,
|
||||||
@ -26,7 +26,10 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
|||||||
fn plain_content_serialization() {
|
fn plain_content_serialization() {
|
||||||
let event_content = ImageEventContent::plain(
|
let event_content = ImageEventContent::plain(
|
||||||
"Upload: my_image.jpg",
|
"Upload: my_image.jpg",
|
||||||
FileContent::plain(mxc_uri!("mxc://notareal.hs/abcdef").to_owned(), None),
|
FileContentBlock::plain(
|
||||||
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_image.jpg".to_owned(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -35,8 +38,9 @@ fn plain_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_image.jpg" },
|
{ "body": "Upload: my_image.jpg" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_image.jpg",
|
||||||
},
|
},
|
||||||
"m.image": {}
|
"m.image": {}
|
||||||
})
|
})
|
||||||
@ -47,8 +51,9 @@ fn plain_content_serialization() {
|
|||||||
fn encrypted_content_serialization() {
|
fn encrypted_content_serialization() {
|
||||||
let event_content = ImageEventContent::plain(
|
let event_content = ImageEventContent::plain(
|
||||||
"Upload: my_image.jpg",
|
"Upload: my_image.jpg",
|
||||||
FileContent::encrypted(
|
FileContentBlock::encrypted(
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_image.jpg".to_owned(),
|
||||||
EncryptedContentInit {
|
EncryptedContentInit {
|
||||||
key: JsonWebKeyInit {
|
key: JsonWebKeyInit {
|
||||||
kty: "oct".to_owned(),
|
kty: "oct".to_owned(),
|
||||||
@ -67,7 +72,6 @@ fn encrypted_content_serialization() {
|
|||||||
v: "v2".to_owned(),
|
v: "v2".to_owned(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
None,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -77,8 +81,9 @@ fn encrypted_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_image.jpg" },
|
{ "body": "Upload: my_image.jpg" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_image.jpg",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -99,43 +104,32 @@ fn encrypted_content_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn image_event_serialization() {
|
fn image_event_serialization() {
|
||||||
let content = assign!(
|
let mut content = ImageEventContent::new(
|
||||||
ImageEventContent::new(
|
TextContentBlock::html("Upload: my_house.jpg", "Upload: <strong>my_house.jpg</strong>"),
|
||||||
TextContentBlock::html(
|
FileContentBlock::plain(
|
||||||
"Upload: my_house.jpg",
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
"Upload: <strong>my_house.jpg</strong>",
|
"my_house.jpg".to_owned(),
|
||||||
),
|
|
||||||
FileContent::plain(
|
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
|
||||||
Some(Box::new(assign!(
|
|
||||||
FileContentInfo::new(),
|
|
||||||
{
|
|
||||||
name: Some("my_house.jpg".to_owned()),
|
|
||||||
mimetype: Some("image/jpeg".to_owned()),
|
|
||||||
size: Some(uint!(897_774)),
|
|
||||||
}
|
|
||||||
))),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
{
|
|
||||||
image: Box::new(ImageContent::with_size(uint!(1920), uint!(1080))),
|
|
||||||
thumbnail: vec![ThumbnailContent::new(
|
|
||||||
ThumbnailFileContent::plain(
|
|
||||||
mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(),
|
|
||||||
Some(Box::new(assign!(ThumbnailFileContentInfo::new(), {
|
|
||||||
mimetype: Some("image/jpeg".to_owned()),
|
|
||||||
size: Some(uint!(334_593)),
|
|
||||||
})))
|
|
||||||
),
|
|
||||||
None
|
|
||||||
)],
|
|
||||||
caption: TextContentBlock::plain("This is my house"),
|
|
||||||
relates_to: Some(Relation::Reply {
|
|
||||||
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
content.file.mimetype = Some("image/jpeg".to_owned());
|
||||||
|
content.file.size = Some(uint!(897_774));
|
||||||
|
content.image = Box::new(ImageContent::with_size(uint!(1920), uint!(1080)));
|
||||||
|
content.thumbnail = vec![ThumbnailContent::new(
|
||||||
|
ThumbnailFileContent::plain(
|
||||||
|
mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(),
|
||||||
|
Some(Box::new(assign!(ThumbnailFileContentInfo::new(), {
|
||||||
|
mimetype: Some("image/jpeg".to_owned()),
|
||||||
|
size: Some(uint!(334_593)),
|
||||||
|
}))),
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)];
|
||||||
|
content.caption = TextContentBlock::plain("This is my house");
|
||||||
|
content.relates_to = Some(Relation::Reply {
|
||||||
|
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
||||||
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&content).unwrap(),
|
to_json_value(&content).unwrap(),
|
||||||
json!({
|
json!({
|
||||||
@ -143,7 +137,7 @@ fn image_event_serialization() {
|
|||||||
{ "mimetype": "text/html", "body": "Upload: <strong>my_house.jpg</strong>" },
|
{ "mimetype": "text/html", "body": "Upload: <strong>my_house.jpg</strong>" },
|
||||||
{ "body": "Upload: my_house.jpg" },
|
{ "body": "Upload: my_house.jpg" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_house.jpg",
|
"name": "my_house.jpg",
|
||||||
"mimetype": "image/jpeg",
|
"mimetype": "image/jpeg",
|
||||||
@ -180,8 +174,9 @@ fn plain_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_cat.png" },
|
{ "body": "Upload: my_cat.png" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_cat.png",
|
||||||
},
|
},
|
||||||
"m.image": {
|
"m.image": {
|
||||||
"width": 668,
|
"width": 668,
|
||||||
@ -197,6 +192,7 @@ fn plain_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_cat.png"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_cat.png"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_cat.png");
|
||||||
assert_matches!(content.file.encryption_info, None);
|
assert_matches!(content.file.encryption_info, None);
|
||||||
assert_eq!(content.image.width, Some(uint!(668)));
|
assert_eq!(content.image.width, Some(uint!(668)));
|
||||||
assert_eq!(content.image.height, None);
|
assert_eq!(content.image.height, None);
|
||||||
@ -211,8 +207,9 @@ fn encrypted_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_cat.png" },
|
{ "body": "Upload: my_cat.png" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_cat.png",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -238,6 +235,7 @@ fn encrypted_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_cat.png"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_cat.png"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_cat.png");
|
||||||
assert!(content.file.encryption_info.is_some());
|
assert!(content.file.encryption_info.is_some());
|
||||||
assert_eq!(content.image.width, None);
|
assert_eq!(content.image.width, None);
|
||||||
assert_eq!(content.image.height, None);
|
assert_eq!(content.image.height, None);
|
||||||
@ -253,7 +251,7 @@ fn message_event_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_gnome.webp" },
|
{ "body": "Upload: my_gnome.webp" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_gnome.webp",
|
"name": "my_gnome.webp",
|
||||||
"mimetype": "image/webp",
|
"mimetype": "image/webp",
|
||||||
@ -285,10 +283,9 @@ fn message_event_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_gnome.webp"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_gnome.webp"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
let info = content.file.info.unwrap();
|
assert_eq!(content.file.name, "my_gnome.webp");
|
||||||
assert_eq!(info.name.as_deref(), Some("my_gnome.webp"));
|
assert_eq!(content.file.mimetype.as_deref(), Some("image/webp"));
|
||||||
assert_eq!(info.mimetype.as_deref(), Some("image/webp"));
|
assert_eq!(content.file.size, Some(uint!(123_774)));
|
||||||
assert_eq!(info.size, Some(uint!(123_774)));
|
|
||||||
assert_eq!(content.image.width, Some(uint!(1300)));
|
assert_eq!(content.image.width, Some(uint!(1300)));
|
||||||
assert_eq!(content.image.height, Some(uint!(837)));
|
assert_eq!(content.image.height, Some(uint!(837)));
|
||||||
assert_eq!(content.thumbnail.len(), 0);
|
assert_eq!(content.thumbnail.len(), 0);
|
||||||
|
@ -8,7 +8,7 @@ use js_int::uint;
|
|||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
file::{EncryptedContentInit, FileContent, FileContentInfo},
|
file::{EncryptedContentInit, FileContentBlock},
|
||||||
image::{ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo},
|
image::{ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo},
|
||||||
message::TextContentBlock,
|
message::TextContentBlock,
|
||||||
relation::InReplyTo,
|
relation::InReplyTo,
|
||||||
@ -26,7 +26,10 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
|||||||
fn plain_content_serialization() {
|
fn plain_content_serialization() {
|
||||||
let event_content = VideoEventContent::plain(
|
let event_content = VideoEventContent::plain(
|
||||||
"Upload: my_video.webm",
|
"Upload: my_video.webm",
|
||||||
FileContent::plain(mxc_uri!("mxc://notareal.hs/abcdef").to_owned(), None),
|
FileContentBlock::plain(
|
||||||
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_video.webm".to_owned(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -35,8 +38,9 @@ fn plain_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{"body": "Upload: my_video.webm" },
|
{"body": "Upload: my_video.webm" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_video.webm",
|
||||||
},
|
},
|
||||||
"m.video": {}
|
"m.video": {}
|
||||||
})
|
})
|
||||||
@ -47,8 +51,9 @@ fn plain_content_serialization() {
|
|||||||
fn encrypted_content_serialization() {
|
fn encrypted_content_serialization() {
|
||||||
let event_content = VideoEventContent::plain(
|
let event_content = VideoEventContent::plain(
|
||||||
"Upload: my_video.webm",
|
"Upload: my_video.webm",
|
||||||
FileContent::encrypted(
|
FileContentBlock::encrypted(
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
|
"my_video.webm".to_owned(),
|
||||||
EncryptedContentInit {
|
EncryptedContentInit {
|
||||||
key: JsonWebKeyInit {
|
key: JsonWebKeyInit {
|
||||||
kty: "oct".to_owned(),
|
kty: "oct".to_owned(),
|
||||||
@ -67,7 +72,6 @@ fn encrypted_content_serialization() {
|
|||||||
v: "v2".to_owned(),
|
v: "v2".to_owned(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
None,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -77,8 +81,9 @@ fn encrypted_content_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_video.webm" },
|
{ "body": "Upload: my_video.webm" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_video.webm",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -99,50 +104,42 @@ fn encrypted_content_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn event_serialization() {
|
fn event_serialization() {
|
||||||
let content = assign!(
|
let mut content = VideoEventContent::new(
|
||||||
VideoEventContent::new(
|
TextContentBlock::html(
|
||||||
TextContentBlock::html(
|
"Upload: my_lava_lamp.webm",
|
||||||
"Upload: my_lava_lamp.webm",
|
"Upload: <strong>my_lava_lamp.webm</strong>",
|
||||||
"Upload: <strong>my_lava_lamp.webm</strong>",
|
),
|
||||||
),
|
FileContentBlock::plain(
|
||||||
FileContent::plain(
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
"my_lava_lamp.webm".to_owned(),
|
||||||
Some(Box::new(assign!(
|
|
||||||
FileContentInfo::new(),
|
|
||||||
{
|
|
||||||
name: Some("my_lava_lamp.webm".to_owned()),
|
|
||||||
mimetype: Some("video/webm".to_owned()),
|
|
||||||
size: Some(uint!(1_897_774)),
|
|
||||||
}
|
|
||||||
))),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
{
|
|
||||||
video: Box::new(assign!(
|
|
||||||
VideoContent::new(),
|
|
||||||
{
|
|
||||||
width: Some(uint!(1920)),
|
|
||||||
height: Some(uint!(1080)),
|
|
||||||
duration: Some(Duration::from_secs(15)),
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
thumbnail: vec![ThumbnailContent::new(
|
|
||||||
ThumbnailFileContent::plain(
|
|
||||||
mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(),
|
|
||||||
Some(Box::new(assign!(ThumbnailFileContentInfo::new(), {
|
|
||||||
mimetype: Some("image/jpeg".to_owned()),
|
|
||||||
size: Some(uint!(334_593)),
|
|
||||||
})))
|
|
||||||
),
|
|
||||||
None
|
|
||||||
)],
|
|
||||||
caption: TextContentBlock::plain("This is my awesome vintage lava lamp"),
|
|
||||||
relates_to: Some(Relation::Reply {
|
|
||||||
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
content.file.mimetype = Some("video/webm".to_owned());
|
||||||
|
content.file.size = Some(uint!(1_897_774));
|
||||||
|
content.video = Box::new(assign!(
|
||||||
|
VideoContent::new(),
|
||||||
|
{
|
||||||
|
width: Some(uint!(1920)),
|
||||||
|
height: Some(uint!(1080)),
|
||||||
|
duration: Some(Duration::from_secs(15)),
|
||||||
|
}
|
||||||
|
));
|
||||||
|
content.thumbnail = vec![ThumbnailContent::new(
|
||||||
|
ThumbnailFileContent::plain(
|
||||||
|
mxc_uri!("mxc://notareal.hs/thumbnail").to_owned(),
|
||||||
|
Some(Box::new(assign!(ThumbnailFileContentInfo::new(), {
|
||||||
|
mimetype: Some("image/jpeg".to_owned()),
|
||||||
|
size: Some(uint!(334_593)),
|
||||||
|
}))),
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)];
|
||||||
|
content.caption = TextContentBlock::plain("This is my awesome vintage lava lamp");
|
||||||
|
content.relates_to = Some(Relation::Reply {
|
||||||
|
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
||||||
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&content).unwrap(),
|
to_json_value(&content).unwrap(),
|
||||||
json!({
|
json!({
|
||||||
@ -150,7 +147,7 @@ fn event_serialization() {
|
|||||||
{ "mimetype": "text/html", "body": "Upload: <strong>my_lava_lamp.webm</strong>" },
|
{ "mimetype": "text/html", "body": "Upload: <strong>my_lava_lamp.webm</strong>" },
|
||||||
{ "body": "Upload: my_lava_lamp.webm" },
|
{ "body": "Upload: my_lava_lamp.webm" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_lava_lamp.webm",
|
"name": "my_lava_lamp.webm",
|
||||||
"mimetype": "video/webm",
|
"mimetype": "video/webm",
|
||||||
@ -188,8 +185,9 @@ fn plain_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Video: my_cat.mp4" },
|
{ "body": "Video: my_cat.mp4" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_cat.mp4",
|
||||||
},
|
},
|
||||||
"m.video": {
|
"m.video": {
|
||||||
"duration": 5_668,
|
"duration": 5_668,
|
||||||
@ -205,6 +203,7 @@ fn plain_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Video: my_cat.mp4"));
|
assert_eq!(content.text.find_plain(), Some("Video: my_cat.mp4"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_cat.mp4");
|
||||||
assert_matches!(content.file.encryption_info, None);
|
assert_matches!(content.file.encryption_info, None);
|
||||||
assert_eq!(content.video.width, None);
|
assert_eq!(content.video.width, None);
|
||||||
assert_eq!(content.video.height, None);
|
assert_eq!(content.video.height, None);
|
||||||
@ -220,8 +219,9 @@ fn encrypted_content_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Video: my_cat.mp4" },
|
{ "body": "Video: my_cat.mp4" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
|
"name": "my_cat.mp4",
|
||||||
"key": {
|
"key": {
|
||||||
"kty": "oct",
|
"kty": "oct",
|
||||||
"key_ops": ["encrypt", "decrypt"],
|
"key_ops": ["encrypt", "decrypt"],
|
||||||
@ -247,6 +247,7 @@ fn encrypted_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Video: my_cat.mp4"));
|
assert_eq!(content.text.find_plain(), Some("Video: my_cat.mp4"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_cat.mp4");
|
||||||
assert!(content.file.encryption_info.is_some());
|
assert!(content.file.encryption_info.is_some());
|
||||||
assert_eq!(content.video.width, None);
|
assert_eq!(content.video.width, None);
|
||||||
assert_eq!(content.video.height, None);
|
assert_eq!(content.video.height, None);
|
||||||
@ -263,7 +264,7 @@ fn message_event_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Upload: my_gnome.webm" },
|
{ "body": "Upload: my_gnome.webm" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "my_gnome.webm",
|
"name": "my_gnome.webm",
|
||||||
"mimetype": "video/webm",
|
"mimetype": "video/webm",
|
||||||
@ -295,13 +296,11 @@ fn message_event_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Upload: my_gnome.webm"));
|
assert_eq!(content.text.find_plain(), Some("Upload: my_gnome.webm"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "my_gnome.webm");
|
||||||
|
assert_eq!(content.file.mimetype.as_deref(), Some("video/webm"));
|
||||||
|
assert_eq!(content.file.size, Some(uint!(123_774)));
|
||||||
assert_eq!(content.video.width, Some(uint!(1300)));
|
assert_eq!(content.video.width, Some(uint!(1300)));
|
||||||
assert_eq!(content.video.height, Some(uint!(837)));
|
assert_eq!(content.video.height, Some(uint!(837)));
|
||||||
assert_eq!(content.video.duration, None);
|
assert_eq!(content.video.duration, None);
|
||||||
assert_eq!(content.thumbnail.len(), 0);
|
assert_eq!(content.thumbnail.len(), 0);
|
||||||
|
|
||||||
let info = content.file.info.unwrap();
|
|
||||||
assert_eq!(info.name.as_deref(), Some("my_gnome.webm"));
|
|
||||||
assert_eq!(info.mimetype.as_deref(), Some("video/webm"));
|
|
||||||
assert_eq!(info.size, Some(uint!(123_774)));
|
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,8 @@ use js_int::uint;
|
|||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
audio::AudioContent,
|
audio::AudioContent, file::FileContentBlock, relation::InReplyTo, room::message::Relation,
|
||||||
file::{FileContent, FileContentInfo},
|
voice::VoiceEventContent, AnyMessageLikeEvent, MessageLikeEvent,
|
||||||
relation::InReplyTo,
|
|
||||||
room::message::Relation,
|
|
||||||
voice::VoiceEventContent,
|
|
||||||
AnyMessageLikeEvent, MessageLikeEvent,
|
|
||||||
},
|
},
|
||||||
mxc_uri,
|
mxc_uri,
|
||||||
serde::CanBeEmpty,
|
serde::CanBeEmpty,
|
||||||
@ -23,33 +19,25 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn event_serialization() {
|
fn event_serialization() {
|
||||||
let content = assign!(
|
let mut content = VoiceEventContent::plain(
|
||||||
VoiceEventContent::plain(
|
"Voice message",
|
||||||
"Voice message",
|
FileContentBlock::plain(
|
||||||
FileContent::plain(
|
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
||||||
mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
|
"voice_message.ogg".to_owned(),
|
||||||
Some(Box::new(assign!(
|
|
||||||
FileContentInfo::new(),
|
|
||||||
{
|
|
||||||
name: Some("voice_message.ogg".to_owned()),
|
|
||||||
mimetype: Some("audio/opus".to_owned()),
|
|
||||||
size: Some(uint!(897_774)),
|
|
||||||
}
|
|
||||||
))),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
content.file.mimetype = Some("audio/opus".to_owned());
|
||||||
|
content.file.size = Some(uint!(897_774));
|
||||||
|
content.audio = assign!(
|
||||||
|
AudioContent::new(),
|
||||||
{
|
{
|
||||||
audio: assign!(
|
duration: Some(Duration::from_secs(23))
|
||||||
AudioContent::new(),
|
|
||||||
{
|
|
||||||
duration: Some(Duration::from_secs(23))
|
|
||||||
}
|
|
||||||
),
|
|
||||||
relates_to: Some(Relation::Reply {
|
|
||||||
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
content.relates_to = Some(Relation::Reply {
|
||||||
|
in_reply_to: InReplyTo::new(event_id!("$replyevent:example.com").to_owned()),
|
||||||
|
});
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&content).unwrap(),
|
to_json_value(&content).unwrap(),
|
||||||
@ -57,7 +45,7 @@ fn event_serialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Voice message" },
|
{ "body": "Voice message" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "voice_message.ogg",
|
"name": "voice_message.ogg",
|
||||||
"mimetype": "audio/opus",
|
"mimetype": "audio/opus",
|
||||||
@ -83,7 +71,7 @@ fn message_event_deserialization() {
|
|||||||
"org.matrix.msc1767.text": [
|
"org.matrix.msc1767.text": [
|
||||||
{ "body": "Voice message" },
|
{ "body": "Voice message" },
|
||||||
],
|
],
|
||||||
"m.file": {
|
"org.matrix.msc1767.file": {
|
||||||
"url": "mxc://notareal.hs/abcdef",
|
"url": "mxc://notareal.hs/abcdef",
|
||||||
"name": "voice_message.ogg",
|
"name": "voice_message.ogg",
|
||||||
"mimetype": "audio/opus",
|
"mimetype": "audio/opus",
|
||||||
@ -115,11 +103,9 @@ fn message_event_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("Voice message"));
|
assert_eq!(content.text.find_plain(), Some("Voice message"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||||
|
assert_eq!(content.file.name, "voice_message.ogg");
|
||||||
|
assert_eq!(content.file.mimetype.as_deref(), Some("audio/opus"));
|
||||||
|
assert_eq!(content.file.size, Some(uint!(123_774)));
|
||||||
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
||||||
assert_matches!(content.audio.waveform, None);
|
assert_matches!(content.audio.waveform, None);
|
||||||
|
|
||||||
let info = content.file.info.unwrap();
|
|
||||||
assert_eq!(info.name.as_deref(), Some("voice_message.ogg"));
|
|
||||||
assert_eq!(info.mimetype.as_deref(), Some("audio/opus"));
|
|
||||||
assert_eq!(info.size, Some(uint!(123_774)));
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user