events: Replace String with MxcUri for media URLs

This commit is contained in:
Kévin Commaille 2021-04-04 09:41:28 +02:00 committed by Kévin Commaille
parent 71b358ccd6
commit c6ab610451
13 changed files with 78 additions and 59 deletions

View File

@ -25,6 +25,21 @@ Breaking changes:
* Remove the implementations of `From<EventType>` and `From<key::verification::cancel::CancelCode>` * Remove the implementations of `From<EventType>` and `From<key::verification::cancel::CancelCode>`
for `String`. Use the `Display` or `ToString` implementations for those types instead. for `String`. Use the `Display` or `ToString` implementations for those types instead.
* Remove `PduStub`, `RoomV1PduStub` and `RoomV3PduStub` types * Remove `PduStub`, `RoomV1PduStub` and `RoomV3PduStub` types
* Use `ruma_identifiers::MxcUri` instead of `String` for `avatar_url`, `thumbnail_url` or `url`
fields in the following types:
```rust
presence::PresenceEventContent,
room::{
avatar::{AvatarEventContent, ImageInfo},
member::MemberEventContent,
message::{
AudioMessageEventContent, FileMessageEventContent, ImageMessageEventContent,
VideoMessageEventContent
}
EncryptedFile, ImageInfo,
},
sticker::StickerEventContent
```
Improvements: Improvements:

View File

@ -5,7 +5,7 @@
use js_int::UInt; use js_int::UInt;
use ruma_common::presence::PresenceState; use ruma_common::presence::PresenceState;
use ruma_events_macros::{Event, EventContent}; use ruma_events_macros::{Event, EventContent};
use ruma_identifiers::UserId; use ruma_identifiers::{MxcUri, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Presence event. /// Presence event.
@ -31,7 +31,7 @@ pub struct PresenceEventContent {
feature = "compat", feature = "compat",
serde(default, deserialize_with = "ruma_serde::empty_string_as_none") serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
)] )]
pub avatar_url: Option<String>, pub avatar_url: Option<MxcUri>,
/// Whether or not the user is currently active. /// Whether or not the user is currently active.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -58,7 +58,7 @@ mod tests {
use js_int::uint; use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::presence::PresenceState; use ruma_common::presence::PresenceState;
use ruma_identifiers::user_id; use ruma_identifiers::{mxc_uri, user_id};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::{PresenceEvent, PresenceEventContent}; use super::{PresenceEvent, PresenceEventContent};
@ -67,7 +67,7 @@ mod tests {
fn serialization() { fn serialization() {
let event = PresenceEvent { let event = PresenceEvent {
content: PresenceEventContent { content: PresenceEventContent {
avatar_url: Some("mxc://localhost:wefuiwegh8742w".into()), avatar_url: Some(mxc_uri!("mxc://localhost/wefuiwegh8742w")),
currently_active: Some(false), currently_active: Some(false),
displayname: None, displayname: None,
last_active_ago: Some(uint!(2_478_593)), last_active_ago: Some(uint!(2_478_593)),
@ -79,7 +79,7 @@ mod tests {
let json = json!({ let json = json!({
"content": { "content": {
"avatar_url": "mxc://localhost:wefuiwegh8742w", "avatar_url": "mxc://localhost/wefuiwegh8742w",
"currently_active": false, "currently_active": false,
"last_active_ago": 2_478_593, "last_active_ago": 2_478_593,
"presence": "online", "presence": "online",
@ -96,7 +96,7 @@ mod tests {
fn deserialization() { fn deserialization() {
let json = json!({ let json = json!({
"content": { "content": {
"avatar_url": "mxc://localhost:wefuiwegh8742w", "avatar_url": "mxc://localhost/wefuiwegh8742w",
"currently_active": false, "currently_active": false,
"last_active_ago": 2_478_593, "last_active_ago": 2_478_593,
"presence": "online", "presence": "online",
@ -118,7 +118,7 @@ mod tests {
status_msg: Some(status_msg), status_msg: Some(status_msg),
}, },
sender, sender,
} if avatar_url == "mxc://localhost:wefuiwegh8742w" } if avatar_url.to_string() == "mxc://localhost/wefuiwegh8742w"
&& status_msg == "Making cupcakes" && status_msg == "Making cupcakes"
&& sender == "@example:localhost" && sender == "@example:localhost"
&& last_active_ago == uint!(2_478_593) && last_active_ago == uint!(2_478_593)

View File

@ -5,6 +5,7 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_identifiers::MxcUri;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod aliases; pub mod aliases;
@ -53,7 +54,7 @@ pub struct ImageInfo {
/// The URL to the thumbnail of the image. Only present if the thumbnail is unencrypted. /// The URL to the thumbnail of the image. Only present if the thumbnail is unencrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>, pub thumbnail_url: Option<MxcUri>,
/// Information on the encrypted thumbnail image. Only present if the thumbnail is encrypted. /// Information on the encrypted thumbnail image. Only present if the thumbnail is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -93,7 +94,7 @@ pub struct ThumbnailInfo {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EncryptedFile { pub struct EncryptedFile {
/// The URL to the file. /// The URL to the file.
pub url: String, pub url: MxcUri,
/// A [JSON Web Key](https://tools.ietf.org/html/rfc7517#appendix-A.3) object. /// A [JSON Web Key](https://tools.ietf.org/html/rfc7517#appendix-A.3) object.
pub key: JsonWebKey, pub key: JsonWebKey,

View File

@ -2,6 +2,7 @@
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::StateEventContent; use ruma_events_macros::StateEventContent;
use ruma_identifiers::MxcUri;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::ThumbnailInfo; use super::ThumbnailInfo;
@ -24,17 +25,17 @@ pub struct AvatarEventContent {
/// URL of the avatar image. /// URL of the avatar image.
#[cfg(not(feature = "unstable-pre-spec"))] #[cfg(not(feature = "unstable-pre-spec"))]
pub url: String, pub url: MxcUri,
/// URL of the avatar image. /// URL of the avatar image.
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
pub url: Option<String>, pub url: Option<MxcUri>,
} }
impl AvatarEventContent { impl AvatarEventContent {
/// Create an `AvatarEventContent` from the given image URL. /// Create an `AvatarEventContent` from the given image URL.
#[cfg(not(feature = "unstable-pre-spec"))] #[cfg(not(feature = "unstable-pre-spec"))]
pub fn new(url: String) -> Self { pub fn new(url: MxcUri) -> Self {
Self { info: None, url } Self { info: None, url }
} }
@ -70,7 +71,7 @@ pub struct ImageInfo {
/// The URL to the thumbnail of the image. /// The URL to the thumbnail of the image.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>, pub thumbnail_url: Option<MxcUri>,
/// The [BlurHash](https://blurha.sh) for this image. /// The [BlurHash](https://blurha.sh) for this image.
/// ///

View File

@ -3,7 +3,7 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_events_macros::StateEventContent; use ruma_events_macros::StateEventContent;
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId, UserId}; use ruma_identifiers::{MxcUri, ServerNameBox, ServerSigningKeyId, UserId};
use ruma_serde::StringEnum; use ruma_serde::StringEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -46,7 +46,7 @@ pub struct MemberEventContent {
feature = "compat", feature = "compat",
serde(default, deserialize_with = "ruma_serde::empty_string_as_none") serde(default, deserialize_with = "ruma_serde::empty_string_as_none")
)] )]
pub avatar_url: Option<String>, pub avatar_url: Option<MxcUri>,
/// The display name for this user, if any. This is added by the homeserver. /// The display name for this user, if any. This is added by the homeserver.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -409,7 +409,7 @@ mod tests {
state_key, state_key,
unsigned, unsigned,
prev_content: None, prev_content: None,
} if avatar_url == "mxc://example.org/SEsfnsuifSDFSSEF" } if avatar_url.to_string() == "mxc://example.org/SEsfnsuifSDFSSEF"
&& displayname == "Alice Margatroid" && displayname == "Alice Margatroid"
&& third_party_displayname == "alice" && third_party_displayname == "alice"
&& mxid == "@alice:example.org" && mxid == "@alice:example.org"
@ -495,7 +495,7 @@ mod tests {
&& sender == "@alice:example.org" && sender == "@alice:example.org"
&& state_key == "@alice:example.org" && state_key == "@alice:example.org"
&& unsigned.is_empty() && unsigned.is_empty()
&& avatar_url == "mxc://example.org/SEsfnsuifSDFSSEF" && avatar_url.to_string() == "mxc://example.org/SEsfnsuifSDFSSEF"
&& displayname == "Alice Margatroid" && displayname == "Alice Margatroid"
&& third_party_displayname == "alice" && third_party_displayname == "alice"
&& mxid == "@alice:example.org" && mxid == "@alice:example.org"

View File

@ -4,6 +4,7 @@ use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::MessageEventContent; use ruma_events_macros::MessageEventContent;
use ruma_identifiers::MxcUri;
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use ruma_identifiers::{DeviceIdBox, UserId}; use ruma_identifiers::{DeviceIdBox, UserId};
use ruma_serde::StringEnum; use ruma_serde::StringEnum;
@ -206,7 +207,7 @@ pub struct AudioMessageEventContent {
/// The URL to the audio clip. Required if the file is unencrypted. The URL (typically /// The URL to the audio clip. Required if the file is unencrypted. The URL (typically
/// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the audio clip. /// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the audio clip.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<MxcUri>,
/// Required if the audio clip is encrypted. Information on the encrypted audio clip. /// Required if the audio clip is encrypted. Information on the encrypted audio clip.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -260,7 +261,7 @@ pub struct FileMessageEventContent {
/// The URL to the file. Required if the file is unencrypted. The URL (typically /// The URL to the file. Required if the file is unencrypted. The URL (typically
/// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the file. /// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the file.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<MxcUri>,
/// Required if file is encrypted. Information on the encrypted file. /// Required if file is encrypted. Information on the encrypted file.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -284,7 +285,7 @@ pub struct FileInfo {
/// The URL to the thumbnail of the file. Only present if the thumbnail is unencrypted. /// The URL to the thumbnail of the file. Only present if the thumbnail is unencrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>, pub thumbnail_url: Option<MxcUri>,
/// Information on the encrypted thumbnail file. Only present if the thumbnail is encrypted. /// Information on the encrypted thumbnail file. Only present if the thumbnail is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -307,7 +308,7 @@ pub struct ImageMessageEventContent {
/// The URL to the image. Required if the file is unencrypted. The URL (typically /// The URL to the image. Required if the file is unencrypted. The URL (typically
/// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the image. /// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the image.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<MxcUri>,
/// Required if image is encrypted. Information on the encrypted image. /// Required if image is encrypted. Information on the encrypted image.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -340,7 +341,7 @@ pub struct LocationInfo {
/// The URL to a thumbnail of the location being represented. Only present if the thumbnail is /// The URL to a thumbnail of the location being represented. Only present if the thumbnail is
/// unencrypted. /// unencrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>, pub thumbnail_url: Option<MxcUri>,
/// Information on an encrypted thumbnail of the location being represented. Only present if /// Information on an encrypted thumbnail of the location being represented. Only present if
/// the thumbnail is encrypted. /// the thumbnail is encrypted.
@ -517,7 +518,7 @@ pub struct VideoMessageEventContent {
/// The URL to the video clip. Required if the file is unencrypted. The URL (typically /// The URL to the video clip. Required if the file is unencrypted. The URL (typically
/// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the video clip. /// [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to the video clip.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<MxcUri>,
/// Required if video clip is encrypted. Information on the encrypted video clip. /// Required if video clip is encrypted. Information on the encrypted video clip.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -556,7 +557,7 @@ pub struct VideoInfo {
/// The URL (typically [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to /// The URL (typically [MXC URI](https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri)) to
/// an image thumbnail of the video clip. Only present if the thumbnail is unencrypted. /// an image thumbnail of the video clip. Only present if the thumbnail is unencrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>, pub thumbnail_url: Option<MxcUri>,
/// Information on the encrypted thumbnail file. Only present if the thumbnail is encrypted. /// Information on the encrypted thumbnail file. Only present if the thumbnail is encrypted.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View File

@ -1,6 +1,7 @@
//! Types for the *m.sticker* event. //! Types for the *m.sticker* event.
use ruma_events_macros::MessageEventContent; use ruma_events_macros::MessageEventContent;
use ruma_identifiers::MxcUri;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{room::ImageInfo, MessageEvent}; use crate::{room::ImageInfo, MessageEvent};
@ -21,5 +22,5 @@ pub struct StickerEventContent {
pub info: ImageInfo, pub info: ImageInfo,
/// The URL to the sticker image. This must be a valid `mxc://` URI. /// The URL to the sticker image. This must be a valid `mxc://` URI.
pub url: String, pub url: MxcUri,
} }

View File

@ -2,7 +2,7 @@ use std::time::{Duration, UNIX_EPOCH};
use js_int::UInt; use js_int::UInt;
use matches::assert_matches; use matches::assert_matches;
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use ruma_events::{ use ruma_events::{
@ -82,12 +82,12 @@ fn serialize_message_event() {
mimetype: Some("image/png".into()), mimetype: Some("image/png".into()),
size: UInt::new(82595), size: UInt::new(82595),
})), })),
thumbnail_url: Some("mxc://matrix.org".into()), thumbnail_url: Some(mxc_uri!("mxc://matrix.org/mnrsnsRRS787TSts")),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
blurhash: None, blurhash: None,
}, },
url: "http://www.matrix.org".into(), url: mxc_uri!("mxc://matrix.org/arsrns98rsRSR"),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
@ -110,10 +110,10 @@ fn serialize_message_event() {
"size": 82595, "size": 82595,
"w": 800 "w": 800
}, },
"thumbnail_url": "mxc://matrix.org", "thumbnail_url": "mxc://matrix.org/mnrsnsRRS787TSts",
"w": 1011 "w": 1011
}, },
"url": "http://www.matrix.org" "url": "mxc://matrix.org/arsrns98rsRSR"
}, },
"event_id": "$h29iv0s8:example.com", "event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1, "origin_server_ts": 1,

View File

@ -8,7 +8,7 @@ use ruma_events::{
sticker::StickerEventContent, sticker::StickerEventContent,
AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned, AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned,
}; };
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -28,12 +28,12 @@ fn message_serialize_sticker() {
mimetype: Some("image/png".into()), mimetype: Some("image/png".into()),
size: UInt::new(82595), size: UInt::new(82595),
})), })),
thumbnail_url: Some("mxc://matrix.org".into()), thumbnail_url: Some(mxc_uri!("mxc://matrix.org/irsns989Rrsn")),
thumbnail_file: None, thumbnail_file: None,
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
blurhash: None, blurhash: None,
}, },
url: "http://www.matrix.org".into(), url: mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"),
}), }),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
@ -56,10 +56,10 @@ fn message_serialize_sticker() {
"size": 82595, "size": 82595,
"w": 800 "w": 800
}, },
"thumbnail_url": "mxc://matrix.org", "thumbnail_url": "mxc://matrix.org/irsns989Rrsn",
"w": 1011 "w": 1011
}, },
"url": "http://www.matrix.org" "url": "mxc://matrix.org/rnsldl8srs98IRrs"
}, },
"event_id": "$h29iv0s8:example.com", "event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1, "origin_server_ts": 1,
@ -163,10 +163,10 @@ fn deserialize_message_sticker() {
"size": 82595, "size": 82595,
"w": 800 "w": 800
}, },
"thumbnail_url": "mxc://matrix.org", "thumbnail_url": "mxc://matrix.org/irnsNRS2879",
"w": 1011 "w": 1011
}, },
"url": "http://www.matrix.org" "url": "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"
}, },
"event_id": "$h29iv0s8:example.com", "event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1, "origin_server_ts": 1,
@ -210,7 +210,7 @@ fn deserialize_message_sticker() {
&& width == UInt::new(1011) && width == UInt::new(1011)
&& mimetype == "image/png" && mimetype == "image/png"
&& size == UInt::new(84242) && size == UInt::new(84242)
&& thumbnail_url == "mxc://matrix.org" && thumbnail_url.to_string() == "mxc://matrix.org/irnsNRS2879"
&& matches!( && matches!(
thumbnail_info.as_ref(), thumbnail_info.as_ref(),
ThumbnailInfo { ThumbnailInfo {
@ -223,7 +223,7 @@ fn deserialize_message_sticker() {
&& *thumb_mimetype == Some("image/png".into()) && *thumb_mimetype == Some("image/png".into())
&& *thumb_size == UInt::new(82595) && *thumb_size == UInt::new(82595)
) )
&& url == "http://www.matrix.org" && url.to_string() == "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"
&& unsigned.is_empty() && unsigned.is_empty()
); );
} }

View File

@ -329,7 +329,7 @@ fn redact_method_properly_redacts() {
"content": { "content": {
"body": "test", "body": "test",
"msgtype": "m.audio", "msgtype": "m.audio",
"url": "http://example.com/audio.mp3", "url": "mxc://example.com/AuDi0",
} }
}); });

View File

@ -19,7 +19,7 @@ use ruma_events::{
}; };
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use ruma_identifiers::DeviceIdBox; use ruma_identifiers::DeviceIdBox;
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -29,7 +29,7 @@ fn serialization() {
content: MessageEventContent::new(MessageType::Audio(AudioMessageEventContent { content: MessageEventContent::new(MessageType::Audio(AudioMessageEventContent {
body: "test".into(), body: "test".into(),
info: None, info: None,
url: Some("http://example.com/audio.mp3".into()), url: Some(mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd")),
file: None, file: None,
})), })),
event_id: event_id!("$143273582443PhrSn:example.org"), event_id: event_id!("$143273582443PhrSn:example.org"),
@ -50,7 +50,7 @@ fn serialization() {
"content": { "content": {
"body": "test", "body": "test",
"msgtype": "m.audio", "msgtype": "m.audio",
"url": "http://example.com/audio.mp3", "url": "mxc://example.org/ffed755USFFxlgbQYZGtryd",
} }
}) })
); );
@ -62,7 +62,7 @@ fn content_serialization() {
MessageEventContent::new(MessageType::Audio(AudioMessageEventContent { MessageEventContent::new(MessageType::Audio(AudioMessageEventContent {
body: "test".into(), body: "test".into(),
info: None, info: None,
url: Some("http://example.com/audio.mp3".into()), url: Some(mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd")),
file: None, file: None,
})); }));
@ -71,7 +71,7 @@ fn content_serialization() {
json!({ json!({
"body": "test", "body": "test",
"msgtype": "m.audio", "msgtype": "m.audio",
"url": "http://example.com/audio.mp3" "url": "mxc://example.org/ffed755USFFxlgbQYZGtryd"
}) })
); );
} }
@ -321,7 +321,7 @@ fn content_deserialization() {
let json_data = json!({ let json_data = json!({
"body": "test", "body": "test",
"msgtype": "m.audio", "msgtype": "m.audio",
"url": "http://example.com/audio.mp3" "url": "mxc://example.org/ffed755USFFxlgbQYZGtryd"
}); });
assert_matches!( assert_matches!(
@ -337,7 +337,7 @@ fn content_deserialization() {
file: None, file: None,
}), }),
.. ..
} if body == "test" && url == "http://example.com/audio.mp3" } if body == "test" && url.to_string() == "mxc://example.org/ffed755USFFxlgbQYZGtryd"
); );
} }

View File

@ -11,7 +11,7 @@ use ruma_events::{
AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, RawExt, StateEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, RawExt, StateEvent,
SyncStateEvent, Unsigned, SyncStateEvent, Unsigned,
}; };
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_alias_id, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
@ -173,10 +173,10 @@ fn deserialize_avatar_without_prev_content() {
"size": 82595, "size": 82595,
"w": 800 "w": 800
}, },
"thumbnail_url": "mxc://matrix.org", "thumbnail_url": "mxc://matrix.org/98irRSS23srs",
"w": 1011 "w": 1011
}, },
"url": "http://www.matrix.org" "url": "mxc://matrix.org/rnsldl8srs98IRrs"
}, },
"event_id": "$h29iv0s8:example.com", "event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1, "origin_server_ts": 1,
@ -186,7 +186,7 @@ fn deserialize_avatar_without_prev_content() {
"type": "m.room.avatar" "type": "m.room.avatar"
}); });
let expected_url = "http://www.matrix.org"; let expected_url = "mxc://matrix.org/rnsldl8srs98IRrs";
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
let expected_url = Some(expected_url.to_owned()); let expected_url = Some(expected_url.to_owned());
@ -240,10 +240,10 @@ fn deserialize_avatar_without_prev_content() {
&& *thumb_height == UInt::new(334) && *thumb_height == UInt::new(334)
&& *thumb_mimetype == Some("image/png".into()) && *thumb_mimetype == Some("image/png".into())
&& *thumb_size == UInt::new(82595) && *thumb_size == UInt::new(82595)
&& *thumbnail_url == "mxc://matrix.org" && *thumbnail_url == mxc_uri!("mxc://matrix.org/98irRSS23srs")
) )
) )
&& url == expected_url && url.to_string() == expected_url
&& unsigned.is_empty() && unsigned.is_empty()
); );
} }

View File

@ -3,7 +3,7 @@ use ruma_events::{
room::{join_rules::JoinRule, topic::TopicEventContent}, room::{join_rules::JoinRule, topic::TopicEventContent},
AnyStateEventContent, AnyStrippedStateEvent, StrippedStateEvent, AnyStateEventContent, AnyStrippedStateEvent, StrippedStateEvent,
}; };
use ruma_identifiers::user_id; use ruma_identifiers::{mxc_uri, user_id};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test] #[test]
@ -80,7 +80,7 @@ fn deserialize_stripped_state_events() {
"mimetype": "image/jpeg", "mimetype": "image/jpeg",
"size": 32 "size": 32
}, },
"thumbnail_url": "https://example.com/image-thumbnail.jpg" "thumbnail_url": "mxc://example.com/THumbNa1l"
}, },
"thumbnail_info": { "thumbnail_info": {
"h": 16, "h": 16,
@ -88,8 +88,8 @@ fn deserialize_stripped_state_events() {
"mimetype": "image/jpeg", "mimetype": "image/jpeg",
"size": 32 "size": 32
}, },
"thumbnail_url": "https://example.com/image-thumbnail.jpg", "thumbnail_url": "mxc://example.com/THumbNa1l",
"url": "https://example.com/image.jpg" "url": "mxc://example.com/iMag3"
} }
}); });
@ -117,10 +117,10 @@ fn deserialize_stripped_state_events() {
match event { match event {
AnyStrippedStateEvent::RoomAvatar(event) => { AnyStrippedStateEvent::RoomAvatar(event) => {
let image_info = event.content.info.unwrap(); let image_info = event.content.info.unwrap();
let expected_url = "https://example.com/image.jpg"; let expected_url = mxc_uri!("mxc://example.com/iMag3");
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
let expected_url = Some(expected_url.to_owned()); let expected_url = Some(expected_url);
assert_eq!(image_info.height.unwrap(), uint!(128)); assert_eq!(image_info.height.unwrap(), uint!(128));
assert_eq!(image_info.width.unwrap(), uint!(128)); assert_eq!(image_info.width.unwrap(), uint!(128));