events: Rename & hide event enum Custom variant
This commit is contained in:
parent
ec4b719546
commit
349a57ffc7
@ -254,8 +254,8 @@ fn expand_conversion_impl(
|
||||
},
|
||||
)*
|
||||
#redaction
|
||||
#ident::Custom(event) => {
|
||||
Self::Custom(#ruma_events::#sync_struct::from(event))
|
||||
#ident::_Custom(event) => {
|
||||
Self::_Custom(#ruma_events::#sync_struct::from(event))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -297,8 +297,8 @@ fn expand_conversion_impl(
|
||||
},
|
||||
)*
|
||||
#redaction
|
||||
Self::Custom(event) => {
|
||||
#full::Custom(event.into_full_event(room_id))
|
||||
Self::_Custom(event) => {
|
||||
#full::_Custom(event.into_full_event(room_id))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -386,7 +386,8 @@ fn expand_content_enum(
|
||||
#variant_decls(#content),
|
||||
)*
|
||||
/// Content of an event not defined by the Matrix specification.
|
||||
Custom(#ruma_events::custom::CustomEventContent),
|
||||
#[doc(hidden)]
|
||||
_Custom(#ruma_events::custom::CustomEventContent),
|
||||
}
|
||||
};
|
||||
|
||||
@ -403,7 +404,7 @@ fn expand_content_enum(
|
||||
fn event_type(&self) -> &::std::primitive::str {
|
||||
match self {
|
||||
#( #variant_arms(content) => content.event_type(), )*
|
||||
Self::Custom(content) => content.event_type(),
|
||||
Self::_Custom(content) => content.event_type(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,7 +422,7 @@ fn expand_content_enum(
|
||||
ev_type => {
|
||||
let content =
|
||||
#ruma_events::custom::CustomEventContent::from_parts(ev_type, input)?;
|
||||
::std::result::Result::Ok(Self::Custom(content))
|
||||
::std::result::Result::Ok(Self::_Custom(content))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -449,7 +450,8 @@ fn expand_content_enum(
|
||||
#variant_decls(#redacted_content),
|
||||
)*
|
||||
/// Content of a redacted event not defined by the Matrix specification.
|
||||
Custom(#ruma_events::custom::RedactedCustomEventContent),
|
||||
#[doc(hidden)]
|
||||
_Custom(#ruma_events::custom::RedactedCustomEventContent),
|
||||
}
|
||||
|
||||
impl #ruma_events::RedactContent for #ident {
|
||||
@ -468,8 +470,8 @@ fn expand_content_enum(
|
||||
)
|
||||
},
|
||||
)*
|
||||
Self::Custom(content) => {
|
||||
#redacted_ident::Custom(
|
||||
Self::_Custom(content) => {
|
||||
#redacted_ident::_Custom(
|
||||
#ruma_events::RedactContent::redact(content, version)
|
||||
)
|
||||
},
|
||||
@ -557,9 +559,9 @@ fn expand_redact(
|
||||
})
|
||||
}
|
||||
)*
|
||||
Self::Custom(event) => {
|
||||
Self::_Custom(event) => {
|
||||
let content = #ruma_events::RedactContent::redact(event.content, version);
|
||||
#redacted_enum::Custom(#redacted_type {
|
||||
#redacted_enum::_Custom(#redacted_type {
|
||||
content,
|
||||
#fields
|
||||
})
|
||||
@ -661,7 +663,8 @@ fn generate_custom_variant(
|
||||
(
|
||||
quote! {
|
||||
/// A redacted event not defined by the Matrix specification
|
||||
Custom(
|
||||
#[doc(hidden)]
|
||||
_Custom(
|
||||
#ruma_events::#event_struct<#ruma_events::custom::RedactedCustomEventContent>,
|
||||
),
|
||||
},
|
||||
@ -672,7 +675,7 @@ fn generate_custom_variant(
|
||||
>>(json.get())
|
||||
.map_err(D::Error::custom)?;
|
||||
|
||||
Ok(Self::Custom(event))
|
||||
Ok(Self::_Custom(event))
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -680,7 +683,8 @@ fn generate_custom_variant(
|
||||
(
|
||||
quote! {
|
||||
/// An event not defined by the Matrix specification
|
||||
Custom(#ruma_events::#event_struct<#ruma_events::custom::CustomEventContent>),
|
||||
#[doc(hidden)]
|
||||
_Custom(#ruma_events::#event_struct<#ruma_events::custom::CustomEventContent>),
|
||||
},
|
||||
quote! {
|
||||
event => {
|
||||
@ -690,7 +694,7 @@ fn generate_custom_variant(
|
||||
>(json.get())
|
||||
.map_err(D::Error::custom)?;
|
||||
|
||||
Ok(Self::Custom(event))
|
||||
Ok(Self::_Custom(event))
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -745,7 +749,7 @@ fn accessor_methods(
|
||||
match self {
|
||||
#( #self_variants(event) =>
|
||||
#ruma_events::EventContent::event_type(&event.content), )*
|
||||
Self::Custom(event) =>
|
||||
Self::_Custom(event) =>
|
||||
#ruma_events::EventContent::event_type(&event.content),
|
||||
}
|
||||
}
|
||||
@ -756,7 +760,7 @@ fn accessor_methods(
|
||||
pub fn content(&self) -> #content_enum {
|
||||
match self {
|
||||
#( #self_variants(event) => #content_variants(event.content.clone()), )*
|
||||
Self::Custom(event) => #content_enum::Custom(event.content.clone()),
|
||||
Self::_Custom(event) => #content_enum::_Custom(event.content.clone()),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -771,8 +775,8 @@ fn accessor_methods(
|
||||
event.prev_content.as_ref().map(|c| #content_variants(c.clone()))
|
||||
},
|
||||
)*
|
||||
Self::Custom(event) => {
|
||||
event.prev_content.as_ref().map(|c| #content_enum::Custom(c.clone()))
|
||||
Self::_Custom(event) => {
|
||||
event.prev_content.as_ref().map(|c| #content_enum::_Custom(c.clone()))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -955,7 +959,7 @@ fn generate_accessor(
|
||||
pub fn #ident(&self) -> &#field_type {
|
||||
match self {
|
||||
#( #variants(event) => &event.#ident, )*
|
||||
Self::Custom(event) => &event.#ident,
|
||||
Self::_Custom(event) => &event.#ident,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ Breaking changes:
|
||||
* Additionally, fix the name of the QR code one (`QrScanShowV1` to `QrCodeScanV1`)
|
||||
* Remove `room::power_level::NotificationPowerLevels`, now found in `ruma_common::power_levels`
|
||||
(or `ruma::power_levels`)
|
||||
* Remove `Custom` variant from event enums. If you were using this, please get in touch.
|
||||
|
||||
# 0.22.2
|
||||
|
||||
|
@ -3,12 +3,10 @@ use maplit::btreemap;
|
||||
use matches::assert_matches;
|
||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||
use ruma_events::{
|
||||
custom::CustomEventContent, AnyMessageEvent, AnyStateEvent, AnyStateEventContent,
|
||||
AnySyncMessageEvent, AnySyncRoomEvent, MessageEvent, StateEvent, SyncMessageEvent,
|
||||
SyncStateEvent, Unsigned,
|
||||
custom::CustomEventContent, AnyStateEvent, AnySyncRoomEvent, AnySyncStateEvent, MessageEvent,
|
||||
StateEvent, Unsigned,
|
||||
};
|
||||
use ruma_identifiers::{event_id, room_id, user_id};
|
||||
use ruma_serde::Raw;
|
||||
use serde_json::{
|
||||
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
||||
};
|
||||
@ -36,7 +34,7 @@ fn custom_state_event() -> JsonValue {
|
||||
|
||||
#[test]
|
||||
fn serialize_custom_message_event() {
|
||||
let aliases_event = AnyMessageEvent::Custom(MessageEvent {
|
||||
let aliases_event = MessageEvent {
|
||||
content: CustomEventContent {
|
||||
data: btreemap! {
|
||||
"body".into() => " * edited message".into(),
|
||||
@ -57,7 +55,7 @@ fn serialize_custom_message_event() {
|
||||
room_id: room_id!("!room:room.com"),
|
||||
sender: user_id!("@carl:example.com"),
|
||||
unsigned: Unsigned::default(),
|
||||
});
|
||||
};
|
||||
|
||||
let actual = to_json_value(&aliases_event).unwrap();
|
||||
let expected = json!({
|
||||
@ -85,7 +83,7 @@ fn serialize_custom_message_event() {
|
||||
|
||||
#[test]
|
||||
fn serialize_custom_state_event() {
|
||||
let aliases_event = AnyStateEvent::Custom(StateEvent {
|
||||
let aliases_event = StateEvent {
|
||||
content: CustomEventContent {
|
||||
data: btreemap! {
|
||||
"custom".into() => 10.into()
|
||||
@ -99,7 +97,7 @@ fn serialize_custom_state_event() {
|
||||
sender: user_id!("@carl:example.com"),
|
||||
state_key: "".into(),
|
||||
unsigned: Unsigned::default(),
|
||||
});
|
||||
};
|
||||
|
||||
let actual = to_json_value(&aliases_event).unwrap();
|
||||
let expected = json!({
|
||||
@ -120,74 +118,13 @@ fn serialize_custom_state_event() {
|
||||
#[test]
|
||||
fn deserialize_custom_state_event() {
|
||||
let json_data = custom_state_event();
|
||||
|
||||
let expected_content = btreemap! {
|
||||
"m.relates_to".into() => json!({
|
||||
"event_id": "$MDitXXXXXX",
|
||||
"key": "👍",
|
||||
"rel_type": "m.annotation"
|
||||
}),
|
||||
};
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<Raw<AnyStateEvent>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap(),
|
||||
AnyStateEvent::Custom(StateEvent {
|
||||
content: CustomEventContent {
|
||||
data, event_type,
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
sender,
|
||||
room_id,
|
||||
prev_content: None,
|
||||
state_key,
|
||||
unsigned,
|
||||
}) if data == expected_content && event_type == "m.reaction"
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& room_id == room_id!("!room:room.com")
|
||||
&& state_key.is_empty()
|
||||
&& !unsigned.is_empty()
|
||||
);
|
||||
assert_matches!(from_json_value::<AnyStateEvent>(json_data), Ok(_));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_custom_state_sync_event() {
|
||||
let json_data = custom_state_event();
|
||||
|
||||
let expected_content = btreemap! {
|
||||
"m.relates_to".into() => json!({
|
||||
"event_id": "$MDitXXXXXX",
|
||||
"key": "👍",
|
||||
"rel_type": "m.annotation"
|
||||
}),
|
||||
};
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<SyncStateEvent<AnyStateEventContent>>(json_data)
|
||||
.unwrap(),
|
||||
SyncStateEvent {
|
||||
content: AnyStateEventContent::Custom(CustomEventContent {
|
||||
data,
|
||||
event_type,
|
||||
}),
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
sender,
|
||||
prev_content: None,
|
||||
state_key,
|
||||
unsigned,
|
||||
} if data == expected_content && event_type == "m.reaction"
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& state_key.is_empty()
|
||||
&& !unsigned.is_empty()
|
||||
);
|
||||
assert_matches!(from_json_value::<AnySyncStateEvent>(json_data), Ok(_));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -206,23 +143,8 @@ fn deserialize_custom_message_sync_event() {
|
||||
}
|
||||
});
|
||||
|
||||
let expected_content = btreemap! {
|
||||
"body".into() => "👍".into(),
|
||||
};
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(json_data)
|
||||
.unwrap(),
|
||||
AnySyncRoomEvent::Message(AnySyncMessageEvent::Custom(SyncMessageEvent {
|
||||
content: CustomEventContent { data, event_type },
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
sender,
|
||||
unsigned,
|
||||
})) if data == expected_content && event_type == "m.ruma_custom"
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& !unsigned.is_empty()
|
||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||
Ok(AnySyncRoomEvent::Message(_))
|
||||
);
|
||||
}
|
||||
|
@ -248,23 +248,11 @@ fn redacted_custom_event_serialize() {
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<Raw<AnySyncRoomEvent>>(redacted.clone())
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap(),
|
||||
AnySyncRoomEvent::RedactedState(AnyRedactedSyncStateEvent::Custom(RedactedSyncStateEvent {
|
||||
content: RedactedCustomEventContent {
|
||||
event_type,
|
||||
},
|
||||
event_id, state_key, unsigned, ..
|
||||
})) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& unsigned.redacted_because.is_some()
|
||||
&& state_key == "hello there"
|
||||
&& event_type == "m.made.up"
|
||||
from_json_value::<AnySyncRoomEvent>(redacted.clone()),
|
||||
Ok(AnySyncRoomEvent::RedactedState(_))
|
||||
);
|
||||
|
||||
let x =
|
||||
from_json_value::<Raw<AnyRedactedSyncStateEvent>>(redacted).unwrap().deserialize().unwrap();
|
||||
let x = from_json_value::<AnyRedactedSyncStateEvent>(redacted).unwrap();
|
||||
assert_eq!(x.event_id(), &event_id!("$h29iv0s8:example.com"))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user