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

View File

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

View File

@ -3,80 +3,76 @@
use std::collections::BTreeMap;
use js_int::Int;
use ruma_events_macros::ruma_event;
use ruma_events_macros::{FromRaw, StateEventContent};
use ruma_identifiers::UserId;
use serde::{Deserialize, Serialize};
use crate::EventType;
ruma_event! {
/// Defines the power levels (privileges) of users in the room.
PowerLevelsEvent {
kind: StateEvent,
event_type: "m.room.power_levels",
content: {
/// The level required to ban a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub ban: Int,
/// Defines the power levels (privileges) of users in the room.
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
#[ruma_event(type = "m.room.power_levels")]
pub struct PowerLevelsEventContent {
/// The level required to ban a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub ban: Int,
/// The level required to send specific event types.
///
/// This is a mapping from event type to power level required.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub events: BTreeMap<EventType, Int>,
/// The level required to send specific event types.
///
/// This is a mapping from event type to power level required.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub events: BTreeMap<EventType, Int>,
/// The default level required to send message events.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub events_default: Int,
/// The default level required to send message events.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub events_default: Int,
/// The level required to invite a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub invite: Int,
/// The level required to invite a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub invite: Int,
/// The level required to kick a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub kick: Int,
/// The level required to kick a user.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub kick: Int,
/// The level required to redact an event.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub redact: Int,
/// The level required to redact an event.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub redact: Int,
/// The default level required to send state events.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub state_default: Int,
/// The default level required to send state events.
#[serde(
default = "default_power_level",
skip_serializing_if = "is_default_power_level"
)]
pub state_default: Int,
/// The power levels for specific users.
///
/// This is a mapping from `user_id` to power level for that user.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub users: BTreeMap<UserId, Int>,
/// The power levels for specific users.
///
/// This is a mapping from `user_id` to power level for that user.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub users: BTreeMap<UserId, Int>,
/// The default power level for every user in the room.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub users_default: Int,
/// The default power level for every user in the room.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub users_default: Int,
/// The power level requirements for specific notification types.
///
/// This is a mapping from `key` to power level for that notifications key.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub notifications: NotificationPowerLevels,
},
}
/// The power level requirements for specific notification types.
///
/// This is a mapping from `key` to power level for that notifications key.
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
pub notifications: NotificationPowerLevels,
}
impl Default for PowerLevelsEventContent {

View File

@ -1,42 +1,39 @@
//! 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.
ServerAclEvent {
kind: StateEvent,
event_type: "m.room.server_acl",
content: {
/// 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
/// names are strongly discouraged in order to require legitimate homeservers to be
/// backed by a valid registered domain name.
#[serde(
default = "ruma_serde::default_true",
skip_serializing_if = "ruma_serde::is_true"
)]
pub allow_ip_literals: bool,
/// An event to indicate which servers are permitted to participate in the room.
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
#[ruma_event(type = "m.room.server_acl")]
pub struct ServerAclEventContent {
/// 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
/// names are strongly discouraged in order to require legitimate homeservers to be
/// backed by a valid registered domain name.
#[serde(
default = "ruma_serde::default_true",
skip_serializing_if = "ruma_serde::is_true"
)]
pub allow_ip_literals: bool,
/// The server names to allow in the room, excluding any port information. Wildcards may
/// be used to cover a wider range of hosts, where `*` matches zero or more characters
/// and `?` matches exactly one character.
///
/// **This defaults to an empty list when not provided, effectively disallowing every
/// server.**
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub allow: Vec<String>,
/// The server names to allow in the room, excluding any port information. Wildcards may
/// be used to cover a wider range of hosts, where `*` matches zero or more characters
/// and `?` matches exactly one character.
///
/// **This defaults to an empty list when not provided, effectively disallowing every
/// server.**
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub allow: Vec<String>,
/// The server names to disallow in the room, excluding any port information. Wildcards may
/// be used to cover a wider range of hosts, where * matches zero or more characters and ?
/// matches exactly one character.
///
/// This defaults to an empty list when not provided.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub deny: Vec<String>,
}
}
/// The server names to disallow in the room, excluding any port information. Wildcards may
/// be used to cover a wider range of hosts, where * matches zero or more characters and ?
/// matches exactly one character.
///
/// This defaults to an empty list when not provided.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub deny: Vec<String>,
}
#[cfg(test)]

View File

@ -1,32 +1,28 @@
//! 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};
ruma_event! {
/// 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
/// 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.
ThirdPartyInviteEvent {
kind: StateEvent,
event_type: "m.room.third_party_invite",
content: {
/// A user-readable string which represents the user who has been invited.
pub display_name: String,
/// 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
/// 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.
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
#[ruma_event(type = "m.room.third_party_invite")]
pub struct ThirdPartyInviteEventContent {
/// A user-readable string which represents the user who has been invited.
pub display_name: String,
/// A URL which can be fetched to validate whether the key has been revoked.
pub key_validity_url: String,
/// A URL which can be fetched to validate whether the key has been revoked.
pub key_validity_url: String,
/// A Base64-encoded Ed25519 key with which the token must be signed.
pub public_key: String,
/// A Base64-encoded Ed25519 key with which the token must be signed.
pub public_key: String,
/// Keys with which the token may be signed.
#[serde(skip_serializing_if = "Option::is_none")]
pub public_keys: Option<Vec<PublicKey>>,
},
}
/// Keys with which the token may be signed.
#[serde(skip_serializing_if = "Option::is_none")]
pub public_keys: Option<Vec<PublicKey>>,
}
/// A public key for signing a third party invite token.

View File

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

View File

@ -1,15 +1,12 @@
//! 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.
TopicEvent {
kind: StateEvent,
event_type: "m.room.topic",
content: {
/// The topic text.
pub topic: String,
},
}
/// A topic is a short message detailing what is currently being discussed in the room.
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
#[ruma_event(type = "m.room.topic")]
pub struct TopicEventContent {
/// The topic text.
pub topic: String,
}