events: Use stable field prefix for extensible events

Only transitional room messages will be sent while unstable
This commit is contained in:
Kévin Commaille 2022-03-25 10:54:40 +01:00 committed by Kévin Commaille
parent 26556259c8
commit 4acfc8d591
12 changed files with 80 additions and 100 deletions

View File

@ -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.

View File

@ -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].

View File

@ -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<ImageContent>,
/// 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].

View File

@ -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<MilliSecondsSinceUnixEpoch>,
/// Information about related messages.

View File

@ -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<VideoContent>,
/// 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.

View File

@ -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.

View File

@ -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: <strong>my_mix.mp3</strong>", "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,
}
},

View File

@ -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: <strong>my_file.txt</strong>", "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: <strong>my_file.txt</strong>", "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",

View File

@ -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: <strong>my_house.jpg</strong>", "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,
}

View File

@ -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",

View File

@ -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: <strong>my_lava_lamp.webm</strong>", "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,
}

View File

@ -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,