diff --git a/src/ignored_user_list.rs b/src/ignored_user_list.rs index 4bad50d7..216408d1 100644 --- a/src/ignored_user_list.rs +++ b/src/ignored_user_list.rs @@ -101,7 +101,7 @@ mod raw { #[cfg(test)] mod tests { - use std::{collections::HashMap, convert::TryFrom}; + use std::convert::TryFrom; use ruma_identifiers::UserId; diff --git a/src/room.rs b/src/room.rs index 30f67d25..df9288cb 100644 --- a/src/room.rs +++ b/src/room.rs @@ -7,25 +7,25 @@ use std::collections::HashMap; use js_int::UInt; use serde::{Deserialize, Serialize}; -// pub mod aliases; -// pub mod avatar; +pub mod aliases; +pub mod avatar; // pub mod canonical_alias; // pub mod create; // pub mod encrypted; -// pub mod encryption; -// pub mod guest_access; -// pub mod history_visibility; -// pub mod join_rules; +pub mod encryption; +pub mod guest_access; +pub mod history_visibility; +pub mod join_rules; // pub mod member; // pub mod message; // pub mod name; -// pub mod pinned_events; +pub mod pinned_events; // pub mod power_levels; pub mod redaction; // pub mod server_acl; -// pub mod third_party_invite; -// pub mod tombstone; -// pub mod topic; +pub mod third_party_invite; +pub mod tombstone; +pub mod topic; /// Metadata about an image. #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] diff --git a/src/room/aliases.rs b/src/room/aliases.rs index d7abeb45..203cf642 100644 --- a/src/room/aliases.rs +++ b/src/room/aliases.rs @@ -1,17 +1,16 @@ //! Types for the *m.room.aliases* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::RoomAliasId; -use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// Informs the room about what room aliases it has been given. - pub struct AliasesEvent(AliasesEventContent) {} -} - -/// The payload of an `AliasesEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct AliasesEventContent { - /// A list of room aliases. - pub aliases: Vec, + AliasesEvent { + kind: StateEvent, + event_type: RoomAliases, + content: { + /// A list of room aliases. + pub aliases: Vec, + }, + } } diff --git a/src/room/avatar.rs b/src/room/avatar.rs index b00fa7f8..c45738f9 100644 --- a/src/room/avatar.rs +++ b/src/room/avatar.rs @@ -1,25 +1,24 @@ //! Types for the *m.room.avatar* event. -use js_int::UInt; -use serde::{Deserialize, Serialize}; +use ruma_events_macros::ruma_event; use super::ImageInfo; -state_event! { +ruma_event! { /// A picture that is associated with the room. /// /// This can be displayed alongside the room information. - pub struct AvatarEvent(AvatarEventContent) {} -} + AvatarEvent { + kind: StateEvent, + event_type: RoomAvatar, + content: { + /// Information about the avatar image. + #[serde(skip_serializing_if = "Option::is_none")] + pub info: Option, -/// The payload of an `AvatarEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct AvatarEventContent { - /// Information about the avatar image. - #[serde(skip_serializing_if = "Option::is_none")] - pub info: Option, - - /// Information about the avatar thumbnail image. - /// URL of the avatar image. - pub url: String, + /// Information about the avatar thumbnail image. + /// URL of the avatar image. + pub url: String, + }, + } } diff --git a/src/room/encryption.rs b/src/room/encryption.rs index 2adcaa2c..4d4102b8 100644 --- a/src/room/encryption.rs +++ b/src/room/encryption.rs @@ -1,30 +1,30 @@ //! Types for the *m.room.encryption* event. use js_int::UInt; -use serde::{Deserialize, Serialize}; +use ruma_events_macros::ruma_event; use crate::Algorithm; -state_event! { +ruma_event! { /// Defines how messages sent in this room should be encrypted. - pub struct EncryptionEvent(EncryptionEventContent) {} -} - -/// The payload of an *m.room.encryption* event. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct EncryptionEventContent { - /// The encryption algorithm to be used to encrypt messages sent in this room. - /// - /// Must be `m.megolm.v1.aes-sha2`. - pub algorithm: Algorithm, - - /// How long the session should be used before changing it. - /// - /// 604800000 (a week) is the recommended default. - pub rotation_period_ms: Option, - - /// How many messages should be sent before changing the session. - /// - /// 100 is the recommended default. - pub rotation_period_msgs: Option, + EncryptionEvent { + kind: StateEvent, + event_type: RoomEncryption, + content: { + /// The encryption algorithm to be used to encrypt messages sent in this room. + /// + /// Must be `m.megolm.v1.aes-sha2`. + pub algorithm: Algorithm, + + /// How long the session should be used before changing it. + /// + /// 604800000 (a week) is the recommended default. + pub rotation_period_ms: Option, + + /// How many messages should be sent before changing the session. + /// + /// 100 is the recommended default. + pub rotation_period_msgs: Option, + }, + } } diff --git a/src/room/guest_access.rs b/src/room/guest_access.rs index 05cf9ac5..394c4a68 100644 --- a/src/room/guest_access.rs +++ b/src/room/guest_access.rs @@ -1,21 +1,21 @@ //! Types for the *m.room.guest_access* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// Controls whether guest users are allowed to join rooms. /// /// This event controls whether guest users are allowed to join rooms. If this event is absent, /// servers should act as if it is present and has the value `GuestAccess::Forbidden`. - pub struct GuestAccessEvent(GuestAccessEventContent) {} -} - -/// The payload of a `GuestAccessEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct GuestAccessEventContent { - /// A policy for guest user access to a room. - pub guest_access: GuestAccess, + GuestAccessEvent { + kind: StateEvent, + event_type: RoomGuestAccess, + content: { + /// A policy for guest user access to a room. + pub guest_access: GuestAccess, + }, + } } /// A policy for guest user access to a room. diff --git a/src/room/history_visibility.rs b/src/room/history_visibility.rs index 93aca95c..f37d0ae0 100644 --- a/src/room/history_visibility.rs +++ b/src/room/history_visibility.rs @@ -1,19 +1,19 @@ //! Types for the *m.room.history_visibility* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// This event controls whether a member of a room can see the events that happened in a room /// from before they joined. - pub struct HistoryVisibilityEvent(HistoryVisibilityEventContent) {} -} - -/// The payload of a `HistoryVisibilityEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct HistoryVisibilityEventContent { - /// Who can see the room history. - pub history_visibility: HistoryVisibility, + HistoryVisibilityEvent { + kind: StateEvent, + event_type: RoomHistoryVisibility, + content: { + /// Who can see the room history. + pub history_visibility: HistoryVisibility, + }, + } } /// Who can see a room's history. diff --git a/src/room/join_rules.rs b/src/room/join_rules.rs index a736a72b..4cd6764c 100644 --- a/src/room/join_rules.rs +++ b/src/room/join_rules.rs @@ -1,18 +1,18 @@ //! Types for the *m.room.join_rules* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// Describes how users are allowed to join the room. - pub struct JoinRulesEvent(JoinRulesEventContent) {} -} - -/// The payload of a `JoinRulesEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct JoinRulesEventContent { - /// The type of rules used for users wishing to join this room. - pub join_rule: JoinRule, + JoinRulesEvent { + kind: StateEvent, + event_type: RoomJoinRules, + content: { + /// The type of rules used for users wishing to join this room. + pub join_rule: JoinRule, + }, + } } /// The rule used for users wishing to join this room. diff --git a/src/room/member.rs b/src/room/member.rs index 141121a7..c83f6575 100644 --- a/src/room/member.rs +++ b/src/room/member.rs @@ -1,11 +1,12 @@ //! Types for the *m.room.member* event. use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::UserId; use ruma_signatures::Signatures; use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// The current membership state of a user in the room. /// /// Adjusts the membership state for a user in a room. It is preferable to use the membership @@ -31,32 +32,32 @@ state_event! { /// The membership for a given user can change over time. Previous membership can be retrieved /// from the `prev_content` object on an event. If not present, the user's previous membership /// must be assumed as leave. - pub struct MemberEvent(MemberEventContent) {} -} + MemberEvent { + kind: StateEvent, + event_type: RoomMember, + content: { + /// The avatar URL for this user, if any. This is added by the homeserver. + #[serde(skip_serializing_if = "Option::is_none")] + pub avatar_url: Option, -/// The payload of a `MemberEvent`. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct MemberEventContent { - /// The avatar URL for this user, if any. This is added by the homeserver. - #[serde(skip_serializing_if = "Option::is_none")] - pub avatar_url: Option, + /// The display name for this user, if any. This is added by the homeserver. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, - /// The display name for this user, if any. This is added by the homeserver. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, + /// Flag indicating if the room containing this event was created + /// with the intention of being a direct chat. + #[serde(skip_serializing_if = "Option::is_none")] + pub is_direct: Option, - /// Flag indicating if the room containing this event was created - /// with the intention of being a direct chat. - #[serde(skip_serializing_if = "Option::is_none")] - pub is_direct: Option, + /// The membership state of this user. + pub membership: MembershipState, - /// The membership state of this user. - pub membership: MembershipState, - - /// If this member event is the successor to a third party invitation, this field will contain - /// information about that invitation. - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_invite: Option, + /// If this member event is the successor to a third party invitation, this field will + /// contain information about that invitation. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_invite: Option, + }, + } } /// The membership state of a user. diff --git a/src/room/pinned_events.rs b/src/room/pinned_events.rs index c36b6352..7f81a410 100644 --- a/src/room/pinned_events.rs +++ b/src/room/pinned_events.rs @@ -1,19 +1,18 @@ //! Types for the *m.room.pinned_events* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::EventId; -use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// Used to "pin" particular events in a room for other participants to review later. - pub struct PinnedEventsEvent(PinnedEventsContent) {} -} - -/// The payload of a `NameEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct PinnedEventsContent { - /// An ordered list of event IDs to pin. - pub pinned: Vec, + PinnedEventsEvent { + kind: StateEvent, + event_type: RoomPinnedEvents, + content: { + /// An ordered list of event IDs to pin. + pub pinned: Vec, + }, + } } #[cfg(test)] @@ -22,16 +21,16 @@ mod tests { use js_int::UInt; use ruma_identifiers::{EventId, RoomId, UserId}; - use serde_json::{from_str, to_string}; + use serde_json::to_string; use crate::{ - room::pinned_events::{PinnedEventsContent, PinnedEventsEvent}, - Event, EventType, RoomEvent, StateEvent, + room::pinned_events::{PinnedEventsEvent, PinnedEventsEventContent}, + Event, RoomEvent, StateEvent, }; #[test] fn serialization_deserialization() { - let mut content: PinnedEventsContent = PinnedEventsContent { pinned: Vec::new() }; + let mut content: PinnedEventsEventContent = PinnedEventsEventContent { pinned: Vec::new() }; content.pinned.push(EventId::new("example.com").unwrap()); content.pinned.push(EventId::new("example.com").unwrap()); @@ -39,7 +38,6 @@ mod tests { let event = PinnedEventsEvent { content: content.clone(), event_id: EventId::new("example.com").unwrap(), - event_type: EventType::RoomPinnedEvents, origin_server_ts: UInt::try_from(1_432_804_485_886u64).unwrap(), prev_content: None, room_id: Some(RoomId::new("example.com").unwrap()), @@ -49,7 +47,7 @@ mod tests { }; let serialized_event = to_string(&event).unwrap(); - let parsed_event: PinnedEventsEvent = from_str(&serialized_event).unwrap(); + let parsed_event = PinnedEventsEvent::from_str(&serialized_event).unwrap(); assert_eq!(parsed_event.event_id(), event.event_id()); assert_eq!(parsed_event.room_id(), event.room_id()); diff --git a/src/room/third_party_invite.rs b/src/room/third_party_invite.rs index 675ab44b..8e107689 100644 --- a/src/room/third_party_invite.rs +++ b/src/room/third_party_invite.rs @@ -1,32 +1,32 @@ //! Types for the *m.room.third_party_invite* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use serde::{Deserialize, Serialize}; -state_event! { +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. - pub struct ThirdPartyInviteEvent(ThirdPartyInviteEventContent) {} -} + /// 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: RoomThirdPartyInvite, + content: { + /// A user-readable string which represents the user who has been invited. + pub display_name: String, -/// The payload of a `ThirdPartyInviteEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -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>, + /// Keys with which the token may be signed. + #[serde(skip_serializing_if = "Option::is_none")] + pub public_keys: Option>, + }, + } } /// A public key for signing a third party invite token. diff --git a/src/room/tombstone.rs b/src/room/tombstone.rs index a1a1c7c4..ce323877 100644 --- a/src/room/tombstone.rs +++ b/src/room/tombstone.rs @@ -1,21 +1,20 @@ //! Types for the *m.room.tombstone* event. -use js_int::UInt; +use ruma_events_macros::ruma_event; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; -state_event! { +ruma_event! { /// A state event signifying that a room has been upgraded to a different room version, and that /// clients should go there. - pub struct TombstoneEvent(TombstoneEventContent) {} -} + TombstoneEvent { + kind: StateEvent, + event_type: RoomTombstone, + content: { + /// A server-defined message. + pub body: String, -/// The payload of an *m.room.tombstone* event. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -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, + }, + } } diff --git a/src/room/topic.rs b/src/room/topic.rs index 39475408..02ffc3a2 100644 --- a/src/room/topic.rs +++ b/src/room/topic.rs @@ -1,16 +1,15 @@ //! Types for the *m.room.topic* event. -use js_int::UInt; -use serde::{Deserialize, Serialize}; +use ruma_events_macros::ruma_event; -state_event! { +ruma_event! { /// A topic is a short message detailing what is currently being discussed in the room. - pub struct TopicEvent(TopicEventContent) {} -} - -/// The payload of a `TopicEvent`. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] -pub struct TopicEventContent { - /// The topic text. - pub topic: String, + TopicEvent { + kind: StateEvent, + event_type: RoomTopic, + content: { + /// The topic text. + pub topic: String, + }, + } }