events: Make fields of doc(hidden) struct private
This commit is contained in:
parent
61a033db58
commit
7626135faf
@ -828,11 +828,11 @@ pub struct KeyVerificationRequestEventContent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct CustomEventContent {
|
pub struct CustomEventContent {
|
||||||
/// A custom msgtype
|
/// A custom msgtype
|
||||||
pub msgtype: String,
|
msgtype: String,
|
||||||
|
|
||||||
/// Remaining event content
|
/// Remaining event content
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub data: JsonObject,
|
data: JsonObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_plain_quote_fallback(original_message: &MessageEvent) -> String {
|
fn get_plain_quote_fallback(original_message: &MessageEvent) -> String {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
@ -9,8 +11,8 @@ use ruma_events::{
|
|||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{
|
room::{
|
||||||
message::{
|
message::{
|
||||||
AudioMessageEventContent, CustomEventContent, MessageEvent, MessageEventContent,
|
AudioMessageEventContent, MessageEvent, MessageEventContent, MessageType, Relation,
|
||||||
MessageType, Relation, TextMessageEventContent,
|
TextMessageEventContent,
|
||||||
},
|
},
|
||||||
relationships::InReplyTo,
|
relationships::InReplyTo,
|
||||||
},
|
},
|
||||||
@ -86,18 +88,15 @@ fn content_serialization() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn custom_content_serialization() {
|
fn custom_msgtype_serialization() {
|
||||||
let json_data = json_object! {
|
let json_data = json_object! {
|
||||||
"custom_field".into() => json!("baba"),
|
"custom_field".into() => json!("baba"),
|
||||||
"another_one".into() => json!("abab"),
|
"another_one".into() => json!("abab"),
|
||||||
};
|
};
|
||||||
let custom_event_content = MessageType::_Custom(CustomEventContent {
|
let custom_msgtype = MessageType::new("my_custom_msgtype", json_data).unwrap();
|
||||||
msgtype: "my_custom_msgtype".into(),
|
|
||||||
data: json_data,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_value(&custom_event_content).unwrap(),
|
to_json_value(&custom_msgtype).unwrap(),
|
||||||
json!({
|
json!({
|
||||||
"msgtype": "my_custom_msgtype",
|
"msgtype": "my_custom_msgtype",
|
||||||
"custom_field": "baba",
|
"custom_field": "baba",
|
||||||
@ -119,17 +118,11 @@ fn custom_content_deserialization() {
|
|||||||
"another_one".into() => json!("abab"),
|
"another_one".into() => json!("abab"),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_matches!(
|
let custom_event =
|
||||||
from_json_value::<Raw<MessageType>>(json_data)
|
from_json_value::<Raw<MessageType>>(json_data).unwrap().deserialize().unwrap();
|
||||||
.unwrap()
|
|
||||||
.deserialize()
|
assert_eq!(custom_event.msgtype(), "my_custom_msgtype");
|
||||||
.unwrap(),
|
assert_eq!(custom_event.data(), Cow::Owned(expected_json_data));
|
||||||
MessageType::_Custom(CustomEventContent {
|
|
||||||
msgtype,
|
|
||||||
data
|
|
||||||
}) if msgtype == "my_custom_msgtype"
|
|
||||||
&& data == expected_json_data
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user