Remove support for room events from ruma_event!

This commit is contained in:
Jonas Platte 2020-06-10 00:24:17 +02:00
parent a7a16ccfcc
commit b33e57c589
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 2 additions and 43 deletions

View File

@ -45,15 +45,8 @@ impl From<RumaEventInput> for RumaEvent {
let content_name = format_ident!("{}Content", name, span = Span::call_site()); let content_name = format_ident!("{}Content", name, span = Span::call_site());
let event_type = input.event_type; let event_type = input.event_type;
let mut fields = match kind { let mut fields =
EventKind::Event => { populate_event_fields(content_name.clone(), input.fields.unwrap_or_else(Vec::new));
populate_event_fields(content_name.clone(), input.fields.unwrap_or_else(Vec::new))
}
EventKind::RoomEvent => populate_room_event_fields(
content_name.clone(),
input.fields.unwrap_or_else(Vec::new),
),
};
fields.sort_unstable_by_key(|field| field.ident.clone().unwrap()); fields.sort_unstable_by_key(|field| field.ident.clone().unwrap());
@ -116,35 +109,6 @@ fn populate_event_fields(content_name: Ident, mut fields: Vec<Field>) -> Vec<Fie
fields fields
} }
/// Fills in the event's struct definition with fields common to all room events.
fn populate_room_event_fields(content_name: Ident, fields: Vec<Field>) -> Vec<Field> {
let mut fields = populate_event_fields(content_name, fields);
let punctuated_fields: Punctuated<ParsableNamedField, Token![,]> = parse_quote! {
/// The unique identifier for the event.
pub event_id: ruma_identifiers::EventId,
/// Time on originating homeserver when this event was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
pub origin_server_ts: std::time::SystemTime,
/// The unique identifier for the room associated with this event.
#[serde(skip_serializing_if = "Option::is_none")]
pub room_id: Option<ruma_identifiers::RoomId>,
/// The unique identifier for the user who sent this event.
pub sender: ruma_identifiers::UserId,
/// Additional key-value pairs not signed by the homeserver.
#[serde(default, skip_serializing_if = "ruma_events::UnsignedData::is_empty")]
pub unsigned: ruma_events::UnsignedData,
};
fields.extend(punctuated_fields.into_iter().map(|p| p.field));
fields
}
/// A wrapper around `syn::Field` that makes it possible to parse `Punctuated<Field, Token![,]>` /// A wrapper around `syn::Field` that makes it possible to parse `Punctuated<Field, Token![,]>`
/// from a `TokenStream`. /// from a `TokenStream`.
/// ///

View File

@ -80,8 +80,6 @@ impl Parse for RumaEventInput {
Expr::Path(expr_path) => { Expr::Path(expr_path) => {
if expr_path.path.is_ident("Event") { if expr_path.path.is_ident("Event") {
EventKind::Event EventKind::Event
} else if expr_path.path.is_ident("RoomEvent") {
EventKind::RoomEvent
} else { } else {
panic!("value of field `kind` must be one of `Event` or `RoomEvent`"); panic!("value of field `kind` must be one of `Event` or `RoomEvent`");
} }
@ -135,9 +133,6 @@ impl Parse for RumaEventInput {
pub enum EventKind { pub enum EventKind {
/// A basic event. /// A basic event.
Event, Event,
/// A room event.
RoomEvent,
} }
/// Information for generating the type used for the event's `content` field. /// Information for generating the type used for the event's `content` field.