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: {
#[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,
},
}
}
/// 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: {
#[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,18 +3,16 @@
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: {
#[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",
@ -75,8 +73,6 @@ ruma_event! {
/// 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,13 +1,12 @@
//! 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: {
#[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
@ -36,8 +35,6 @@ ruma_event! {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub deny: Vec<String>,
}
}
}
#[cfg(test)]
mod tests {

View File

@ -1,18 +1,16 @@
//! 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: {
#[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,
@ -25,8 +23,6 @@ ruma_event! {
/// 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: {
#[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,
},
}
}

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: {
#[derive(Clone, Debug, Serialize, FromRaw, StateEventContent)]
#[ruma_event(type = "m.room.topic")]
pub struct TopicEventContent {
/// The topic text.
pub topic: String,
},
}
}