Convert remaining state structs from ruma_event! to derive(StateEventContent)

This commit is contained in:
Jonas Platte 2020-06-04 11:24:33 +02:00
parent 74f680f8ed
commit b95b7db0d4
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
7 changed files with 145 additions and 169 deletions

View File

@ -1,27 +1,23 @@
//! Types for the *m.room.message.feedback* event. //! Types for the *m.room.message.feedback* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, MessageEventContent};
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum::{Display, EnumString}; use strum::{Display, EnumString};
ruma_event! {
/// An acknowledgement of a message. /// An acknowledgement of a message.
/// ///
/// N.B.: Usage of this event is discouraged in favor of the receipts module. Most clients will /// N.B.: Usage of this event is discouraged in favor of the receipts module. Most clients will
/// not recognize this event. /// not recognize this event.
FeedbackEvent { #[derive(Clone, Debug, Serialize, FromRaw, MessageEventContent)]
kind: RoomEvent, #[ruma_event(type = "m.room.message.feedback")]
event_type: "m.room.message.feedback", pub struct FeedbackEventContent {
content: {
/// The event that this feedback is related to. /// The event that this feedback is related to.
pub target_event_id: EventId, pub target_event_id: EventId,
/// The type of feedback. /// The type of feedback.
#[serde(rename = "type")] #[serde(rename = "type")]
pub feedback_type: FeedbackType, pub feedback_type: FeedbackType,
},
}
} }
/// A type of feedback. /// A type of feedback.

View File

@ -1,18 +1,15 @@
//! Types for the *m.room.pinned_events* event. //! Types for the *m.room.pinned_events* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use serde::Serialize;
ruma_event! {
/// Used to "pin" particular events in a room for other participants to review later. /// Used to "pin" particular events in a room for other participants to review later.
PinnedEventsEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.pinned_events")]
event_type: "m.room.pinned_events", pub struct PinnedEventsEventContent {
content: {
/// An ordered list of event IDs to pin. /// An ordered list of event IDs to pin.
pub pinned: Vec<EventId>, pub pinned: Vec<EventId>,
},
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -3,18 +3,16 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use js_int::Int; use js_int::Int;
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::EventType; use crate::EventType;
ruma_event! {
/// Defines the power levels (privileges) of users in the room. /// Defines the power levels (privileges) of users in the room.
PowerLevelsEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.power_levels")]
event_type: "m.room.power_levels", pub struct PowerLevelsEventContent {
content: {
/// The level required to ban a user. /// The level required to ban a user.
#[serde( #[serde(
default = "default_power_level", default = "default_power_level",
@ -75,8 +73,6 @@ ruma_event! {
/// This is a mapping from `key` to power level for that notifications key. /// This is a mapping from `key` to power level for that notifications key.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")] #[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub notifications: NotificationPowerLevels, pub notifications: NotificationPowerLevels,
},
}
} }
impl Default for PowerLevelsEventContent { impl Default for PowerLevelsEventContent {

View File

@ -1,13 +1,12 @@
//! Types for the *m.room.server_acl* event. //! Types for the *m.room.server_acl* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use serde::Serialize;
ruma_event! {
/// An event to indicate which servers are permitted to participate in the room. /// An event to indicate which servers are permitted to participate in the room.
ServerAclEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.server_acl")]
event_type: "m.room.server_acl", pub struct ServerAclEventContent {
content: {
/// True to allow server names that are IP address literals. False to deny. /// True to allow server names that are IP address literals. False to deny.
/// ///
/// This is strongly recommended to be set to false as servers running with IP literal /// This is strongly recommended to be set to false as servers running with IP literal
@ -36,8 +35,6 @@ ruma_event! {
#[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub deny: Vec<String>, pub deny: Vec<String>,
} }
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -1,18 +1,16 @@
//! Types for the *m.room.third_party_invite* event. //! Types for the *m.room.third_party_invite* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
ruma_event! {
/// An invitation to a room issued to a third party identifier, rather than a matrix user ID. /// An invitation to a room issued to a third party identifier, rather than a matrix user ID.
/// ///
/// Acts as an *m.room.member* invite event, where there isn't a target user_id to invite. This /// Acts as an *m.room.member* invite event, where there isn't a target user_id to invite. This
/// event contains a token and a public key whose private key must be used to sign the token. /// event contains a token and a public key whose private key must be used to sign the token.
/// Any user who can present that signature may use this invitation to join the target room. /// Any user who can present that signature may use this invitation to join the target room.
ThirdPartyInviteEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.third_party_invite")]
event_type: "m.room.third_party_invite", pub struct ThirdPartyInviteEventContent {
content: {
/// A user-readable string which represents the user who has been invited. /// A user-readable string which represents the user who has been invited.
pub display_name: String, pub display_name: String,
@ -25,8 +23,6 @@ ruma_event! {
/// Keys with which the token may be signed. /// Keys with which the token may be signed.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub public_keys: Option<Vec<PublicKey>>, pub public_keys: Option<Vec<PublicKey>>,
},
}
} }
/// A public key for signing a third party invite token. /// A public key for signing a third party invite token.

View File

@ -1,20 +1,17 @@
//! Types for the *m.room.tombstone* event. //! Types for the *m.room.tombstone* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
use serde::Serialize;
ruma_event! {
/// A state event signifying that a room has been upgraded to a different room version, and that /// A state event signifying that a room has been upgraded to a different room version, and that
/// clients should go there. /// clients should go there.
TombstoneEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.tombstone")]
event_type: "m.room.tombstone", pub struct TombstoneEventContent {
content: {
/// A server-defined message. /// A server-defined message.
pub body: String, pub body: String,
/// The new room the client should be visiting. /// The new room the client should be visiting.
pub replacement_room: RoomId, pub replacement_room: RoomId,
},
}
} }

View File

@ -1,15 +1,12 @@
//! Types for the *m.room.topic* event. //! Types for the *m.room.topic* event.
use ruma_events_macros::ruma_event; use ruma_events_macros::{FromRaw, StateEventContent};
use serde::Serialize;
ruma_event! {
/// A topic is a short message detailing what is currently being discussed in the room. /// A topic is a short message detailing what is currently being discussed in the room.
TopicEvent { #[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
kind: StateEvent, #[ruma_event(type = "m.room.topic")]
event_type: "m.room.topic", pub struct TopicEventContent {
content: {
/// The topic text. /// The topic text.
pub topic: String, pub topic: String,
},
}
} }