From 4acfc8d591d2f176e65068c282a94414eee95109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 25 Mar 2022 10:54:40 +0100 Subject: [PATCH] events: Use stable field prefix for extensible events Only transitional room messages will be sent while unstable --- crates/ruma-common/src/events/audio.rs | 4 +-- crates/ruma-common/src/events/file.rs | 2 +- crates/ruma-common/src/events/image.rs | 18 ++++-------- crates/ruma-common/src/events/location.rs | 10 ++----- crates/ruma-common/src/events/video.rs | 16 +++-------- crates/ruma-common/src/events/voice.rs | 6 ++-- crates/ruma-common/tests/events/audio.rs | 24 ++++++++-------- crates/ruma-common/tests/events/file.rs | 12 ++++---- crates/ruma-common/tests/events/image.rs | 32 ++++++++++----------- crates/ruma-common/tests/events/location.rs | 12 ++++---- crates/ruma-common/tests/events/video.rs | 32 ++++++++++----------- crates/ruma-common/tests/events/voice.rs | 12 ++++---- 12 files changed, 80 insertions(+), 100 deletions(-) diff --git a/crates/ruma-common/src/events/audio.rs b/crates/ruma-common/src/events/audio.rs index f62744c5..68e1fd56 100644 --- a/crates/ruma-common/src/events/audio.rs +++ b/crates/ruma-common/src/events/audio.rs @@ -25,11 +25,11 @@ pub struct AudioEventContent { pub message: MessageContent, /// The file content of the message. - #[serde(rename = "org.matrix.msc1767.file")] + #[serde(rename = "m.file")] pub file: FileContent, /// The audio content of the message. - #[serde(rename = "org.matrix.msc1767.audio")] + #[serde(rename = "m.audio")] pub audio: AudioContent, /// Information about related messages. diff --git a/crates/ruma-common/src/events/file.rs b/crates/ruma-common/src/events/file.rs index 1a1ac38b..123701dc 100644 --- a/crates/ruma-common/src/events/file.rs +++ b/crates/ruma-common/src/events/file.rs @@ -142,7 +142,7 @@ pub struct FileEventContent { pub message: MessageContent, /// The file content of the message. - #[serde(rename = "org.matrix.msc1767.file")] + #[serde(rename = "m.file")] pub file: FileContent, /// Information about related messages for [rich replies]. diff --git a/crates/ruma-common/src/events/image.rs b/crates/ruma-common/src/events/image.rs index 505bb79b..5dfb3cb8 100644 --- a/crates/ruma-common/src/events/image.rs +++ b/crates/ruma-common/src/events/image.rs @@ -23,27 +23,19 @@ pub struct ImageEventContent { pub message: MessageContent, /// The file content of the message. - #[serde(rename = "org.matrix.msc1767.file")] + #[serde(rename = "m.file")] pub file: FileContent, /// The image content of the message. - #[serde(rename = "org.matrix.msc1767.image")] + #[serde(rename = "m.image")] pub image: Box, /// The thumbnails of the message. - #[serde( - rename = "org.matrix.msc1767.thumbnail", - default, - skip_serializing_if = "Thumbnails::is_empty" - )] + #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Thumbnails::is_empty")] pub thumbnail: Thumbnails, - /// The thumbnails of the message. - #[serde( - rename = "org.matrix.msc1767.caption", - default, - skip_serializing_if = "Captions::is_empty" - )] + /// The captions of the message. + #[serde(rename = "m.caption", default, skip_serializing_if = "Captions::is_empty")] pub caption: Captions, /// Information about related messages for [rich replies]. diff --git a/crates/ruma-common/src/events/location.rs b/crates/ruma-common/src/events/location.rs index 15c995c1..a7141353 100644 --- a/crates/ruma-common/src/events/location.rs +++ b/crates/ruma-common/src/events/location.rs @@ -23,19 +23,15 @@ pub struct LocationEventContent { pub message: MessageContent, /// The location info of the message. - #[serde(rename = "org.matrix.msc3488.location")] + #[serde(rename = "m.location")] pub location: LocationContent, /// The asset this message refers to. - #[serde( - default, - rename = "org.matrix.msc3488.asset", - skip_serializing_if = "ruma_common::serde::is_default" - )] + #[serde(default, rename = "m.asset", skip_serializing_if = "ruma_common::serde::is_default")] pub asset: AssetContent, /// The timestamp this message refers to. - #[serde(rename = "org.matrix.msc3488.ts", skip_serializing_if = "Option::is_none")] + #[serde(rename = "m.ts", skip_serializing_if = "Option::is_none")] pub ts: Option, /// Information about related messages. diff --git a/crates/ruma-common/src/events/video.rs b/crates/ruma-common/src/events/video.rs index 2ba5dd3b..0b3cddff 100644 --- a/crates/ruma-common/src/events/video.rs +++ b/crates/ruma-common/src/events/video.rs @@ -25,27 +25,19 @@ pub struct VideoEventContent { pub message: MessageContent, /// The file content of the message. - #[serde(rename = "org.matrix.msc1767.file")] + #[serde(rename = "m.file")] pub file: FileContent, /// The video content of the message. - #[serde(rename = "org.matrix.msc1767.video")] + #[serde(rename = "m.video")] pub video: Box, /// The thumbnails of the message. - #[serde( - rename = "org.matrix.msc1767.thumbnail", - default, - skip_serializing_if = "Thumbnails::is_empty" - )] + #[serde(rename = "m.thumbnail", default, skip_serializing_if = "Thumbnails::is_empty")] pub thumbnail: Thumbnails, /// The captions of the message. - #[serde( - rename = "org.matrix.msc1767.caption", - default, - skip_serializing_if = "Captions::is_empty" - )] + #[serde(rename = "m.caption", default, skip_serializing_if = "Captions::is_empty")] pub caption: Captions, /// Information about related messages. diff --git a/crates/ruma-common/src/events/voice.rs b/crates/ruma-common/src/events/voice.rs index 0cb4b51b..7196cda3 100644 --- a/crates/ruma-common/src/events/voice.rs +++ b/crates/ruma-common/src/events/voice.rs @@ -19,15 +19,15 @@ pub struct VoiceEventContent { pub message: MessageContent, /// The file content of the message. - #[serde(rename = "org.matrix.msc1767.file")] + #[serde(rename = "m.file")] pub file: FileContent, /// The audio content of the message. - #[serde(rename = "org.matrix.msc1767.audio")] + #[serde(rename = "m.audio")] pub audio: AudioContent, /// The audio content of the message. - #[serde(rename = "org.matrix.msc3245.voice")] + #[serde(rename = "m.voice")] pub voice: VoiceContent, /// Information about related messages. diff --git a/crates/ruma-common/tests/events/audio.rs b/crates/ruma-common/tests/events/audio.rs index 5bbfe2f7..7c0778a8 100644 --- a/crates/ruma-common/tests/events/audio.rs +++ b/crates/ruma-common/tests/events/audio.rs @@ -73,10 +73,10 @@ fn plain_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_sound.ogg", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.audio": {} + "m.audio": {} }) ); } @@ -113,7 +113,7 @@ fn encrypted_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_sound.ogg", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -128,7 +128,7 @@ fn encrypted_content_serialization() { }, "v": "v2" }, - "org.matrix.msc1767.audio": {} + "m.audio": {} }) ); } @@ -181,13 +181,13 @@ fn event_serialization() { { "body": "Upload: my_mix.mp3", "mimetype": "text/html"}, { "body": "Upload: my_mix.mp3", "mimetype": "text/plain"}, ], - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_mix.mp3", "mimetype": "audio/mp3", "size": 897_774, }, - "org.matrix.msc1767.audio": { + "m.audio": { "duration": 123_000, }, "m.relates_to": { @@ -209,10 +209,10 @@ fn event_serialization() { fn plain_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_new_song.webm", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.audio": { + "m.audio": { "waveform": [ 13, 34, @@ -290,7 +290,7 @@ fn plain_content_deserialization() { fn encrypted_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -305,7 +305,7 @@ fn encrypted_content_deserialization() { }, "v": "v2" }, - "org.matrix.msc1767.audio": {}, + "m.audio": {}, }); assert_matches!( @@ -329,13 +329,13 @@ fn message_event_deserialization() { let json_data = json!({ "content": { "org.matrix.msc1767.text": "Upload: airplane_sound.opus", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "airplane_sound.opus", "mimetype": "audio/opus", "size": 123_774, }, - "org.matrix.msc1767.audio": { + "m.audio": { "duration": 5_300, } }, diff --git a/crates/ruma-common/tests/events/file.rs b/crates/ruma-common/tests/events/file.rs index 821a1ce9..0ff4885e 100644 --- a/crates/ruma-common/tests/events/file.rs +++ b/crates/ruma-common/tests/events/file.rs @@ -32,7 +32,7 @@ fn plain_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", } }) @@ -69,7 +69,7 @@ fn encrypted_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -128,7 +128,7 @@ fn file_event_serialization() { { "body": "Upload: my_file.txt", "mimetype": "text/html"}, { "body": "Upload: my_file.txt", "mimetype": "text/plain"}, ], - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_file.txt", "mimetype": "text/plain", @@ -153,7 +153,7 @@ fn file_event_serialization() { fn plain_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", } }); @@ -172,7 +172,7 @@ fn plain_content_deserialization() { fn encrypted_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -208,7 +208,7 @@ fn message_event_deserialization() { { "body": "Upload: my_file.txt", "mimetype": "text/html"}, { "body": "Upload: my_file.txt", "mimetype": "text/plain"}, ], - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_file.txt", "mimetype": "text/plain", diff --git a/crates/ruma-common/tests/events/image.rs b/crates/ruma-common/tests/events/image.rs index 41771e63..72c35da2 100644 --- a/crates/ruma-common/tests/events/image.rs +++ b/crates/ruma-common/tests/events/image.rs @@ -35,10 +35,10 @@ fn plain_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_image.jpg", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.image": {} + "m.image": {} }) ); } @@ -75,7 +75,7 @@ fn encrypted_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_image.jpg", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -90,7 +90,7 @@ fn encrypted_content_serialization() { }, "v": "v2" }, - "org.matrix.msc1767.image": {} + "m.image": {} }) ); } @@ -149,24 +149,24 @@ fn image_event_serialization() { { "body": "Upload: my_house.jpg", "mimetype": "text/html"}, { "body": "Upload: my_house.jpg", "mimetype": "text/plain"}, ], - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_house.jpg", "mimetype": "image/jpeg", "size": 897_774, }, - "org.matrix.msc1767.image": { + "m.image": { "width": 1920, "height": 1080, }, - "org.matrix.msc1767.thumbnail": [ + "m.thumbnail": [ { "url": "mxc://notareal.hs/thumbnail", "mimetype": "image/jpeg", "size": 334_593, } ], - "org.matrix.msc1767.caption": [ + "m.caption": [ { "body": "This is my house", "mimetype": "text/plain", @@ -191,13 +191,13 @@ fn image_event_serialization() { fn plain_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_cat.png", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.image": { + "m.image": { "width": 668, }, - "org.matrix.msc1767.caption": [ + "m.caption": [ { "body": "Look at my cat!", } @@ -222,7 +222,7 @@ fn plain_content_deserialization() { fn encrypted_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_file.txt", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -237,8 +237,8 @@ fn encrypted_content_deserialization() { }, "v": "v2" }, - "org.matrix.msc1767.image": {}, - "org.matrix.msc1767.thumbnail": [ + "m.image": {}, + "m.thumbnail": [ { "url": "mxc://notareal.hs/thumbnail", } @@ -265,13 +265,13 @@ fn message_event_deserialization() { let json_data = json!({ "content": { "org.matrix.msc1767.text": "Upload: my_gnome.webp", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_gnome.webp", "mimetype": "image/webp", "size": 123_774, }, - "org.matrix.msc1767.image": { + "m.image": { "width": 1300, "height": 837, } diff --git a/crates/ruma-common/tests/events/location.rs b/crates/ruma-common/tests/events/location.rs index a862844f..fde850f0 100644 --- a/crates/ruma-common/tests/events/location.rs +++ b/crates/ruma-common/tests/events/location.rs @@ -29,7 +29,7 @@ fn plain_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Alice was at geo:51.5008,0.1247;u=35", - "org.matrix.msc3488.location": { + "m.location": { "uri": "geo:51.5008,0.1247;u=35", }, }) @@ -81,12 +81,12 @@ fn event_serialization() { "mimetype": "text/plain", }, ], - "org.matrix.msc3488.location": { + "m.location": { "uri": "geo:51.5008,0.1247;u=35", "description": "Alice's whereabouts", "zoom_level": 4, }, - "org.matrix.msc3488.ts": 1_636_829_458, + "m.ts": 1_636_829_458, "m.relates_to": { "m.in_reply_to": { "event_id": "$replyevent:example.com", @@ -106,7 +106,7 @@ fn event_serialization() { fn plain_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Alice was at geo:51.5008,0.1247;u=35", - "org.matrix.msc3488.location": { + "m.location": { "uri": "geo:51.5008,0.1247;u=35", }, }); @@ -173,12 +173,12 @@ fn message_event_deserialization() { "org.matrix.msc1767.message": [ { "body": "Alice was at geo:51.5008,0.1247;u=35 as of Sat Nov 13 18:50:58 2021" }, ], - "org.matrix.msc3488.location": { + "m.location": { "uri": "geo:51.5008,0.1247;u=35", "description": "Alice's whereabouts", "zoom_level": 4, }, - "org.matrix.msc3488.ts": 1_636_829_458, + "m.ts": 1_636_829_458, "m.relates_to": { "m.in_reply_to": { "event_id": "$replyevent:example.com", diff --git a/crates/ruma-common/tests/events/video.rs b/crates/ruma-common/tests/events/video.rs index eba6f690..a9f72233 100644 --- a/crates/ruma-common/tests/events/video.rs +++ b/crates/ruma-common/tests/events/video.rs @@ -37,10 +37,10 @@ fn plain_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_video.webm", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.video": {} + "m.video": {} }) ); } @@ -77,7 +77,7 @@ fn encrypted_content_serialization() { to_json_value(&event_content).unwrap(), json!({ "org.matrix.msc1767.text": "Upload: my_video.webm", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -92,7 +92,7 @@ fn encrypted_content_serialization() { }, "v": "v2" }, - "org.matrix.msc1767.video": {} + "m.video": {} }) ); } @@ -158,25 +158,25 @@ fn event_serialization() { { "body": "Upload: my_lava_lamp.webm", "mimetype": "text/html"}, { "body": "Upload: my_lava_lamp.webm", "mimetype": "text/plain"}, ], - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_lava_lamp.webm", "mimetype": "video/webm", "size": 1_897_774, }, - "org.matrix.msc1767.video": { + "m.video": { "width": 1920, "height": 1080, "duration": 15_000, }, - "org.matrix.msc1767.thumbnail": [ + "m.thumbnail": [ { "url": "mxc://notareal.hs/thumbnail", "mimetype": "image/jpeg", "size": 334_593, } ], - "org.matrix.msc1767.caption": [ + "m.caption": [ { "body": "This is my awesome vintage lava lamp", "mimetype": "text/plain", @@ -201,13 +201,13 @@ fn event_serialization() { fn plain_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Video: my_cat.mp4", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", }, - "org.matrix.msc1767.video": { + "m.video": { "duration": 5_668, }, - "org.matrix.msc1767.caption": [ + "m.caption": [ { "body": "Look at my cat!", } @@ -233,7 +233,7 @@ fn plain_content_deserialization() { fn encrypted_content_deserialization() { let json_data = json!({ "org.matrix.msc1767.text": "Upload: my_cat.mp4", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "key": { "kty": "oct", @@ -248,8 +248,8 @@ fn encrypted_content_deserialization() { }, "v": "v2" }, - "org.matrix.msc1767.video": {}, - "org.matrix.msc1767.thumbnail": [ + "m.video": {}, + "m.thumbnail": [ { "url": "mxc://notareal.hs/thumbnail", } @@ -277,13 +277,13 @@ fn message_event_deserialization() { let json_data = json!({ "content": { "org.matrix.msc1767.text": "Upload: my_gnome.webm", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "my_gnome.webm", "mimetype": "video/webm", "size": 123_774, }, - "org.matrix.msc1767.video": { + "m.video": { "width": 1300, "height": 837, } diff --git a/crates/ruma-common/tests/events/voice.rs b/crates/ruma-common/tests/events/voice.rs index 90927b5d..4f2c4de1 100644 --- a/crates/ruma-common/tests/events/voice.rs +++ b/crates/ruma-common/tests/events/voice.rs @@ -60,16 +60,16 @@ fn event_serialization() { json!({ "content": { "org.matrix.msc1767.text": "Voice message", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "voice_message.ogg", "mimetype": "audio/opus", "size": 897_774, }, - "org.matrix.msc1767.audio": { + "m.audio": { "duration": 23_000, }, - "org.matrix.msc3245.voice": {}, + "m.voice": {}, "m.relates_to": { "m.in_reply_to": { "event_id": "$replyevent:example.com" @@ -90,16 +90,16 @@ fn message_event_deserialization() { let json_data = json!({ "content": { "org.matrix.msc1767.text": "Voice message", - "org.matrix.msc1767.file": { + "m.file": { "url": "mxc://notareal.hs/abcdef", "name": "voice_message.ogg", "mimetype": "audio/opus", "size": 123_774, }, - "org.matrix.msc1767.audio": { + "m.audio": { "duration": 5_300, }, - "org.matrix.msc3245.voice": {}, + "m.voice": {}, }, "event_id": "$event:notareal.hs", "origin_server_ts": 134_829_848,