Convert m.room.{aliases ,avatar ,encryption ,guest_access,

history_visibility, join_rules, member, pinned_events,
third_party_invite, tombstone, topic} to the new API.
This commit is contained in:
Jimmy Cuadra 2019-06-20 22:10:36 -07:00
parent 22c15277a7
commit 4212c9f619
13 changed files with 167 additions and 172 deletions

View File

@ -101,7 +101,7 @@ mod raw {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{collections::HashMap, convert::TryFrom}; use std::convert::TryFrom;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;

View File

@ -7,25 +7,25 @@ use std::collections::HashMap;
use js_int::UInt; use js_int::UInt;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// pub mod aliases; pub mod aliases;
// pub mod avatar; pub mod avatar;
// pub mod canonical_alias; // pub mod canonical_alias;
// pub mod create; // pub mod create;
// pub mod encrypted; // pub mod encrypted;
// pub mod encryption; pub mod encryption;
// pub mod guest_access; pub mod guest_access;
// pub mod history_visibility; pub mod history_visibility;
// pub mod join_rules; pub mod join_rules;
// pub mod member; // pub mod member;
// pub mod message; // pub mod message;
// pub mod name; // pub mod name;
// pub mod pinned_events; pub mod pinned_events;
// pub mod power_levels; // pub mod power_levels;
pub mod redaction; pub mod redaction;
// pub mod server_acl; // pub mod server_acl;
// pub mod third_party_invite; pub mod third_party_invite;
// pub mod tombstone; pub mod tombstone;
// pub mod topic; pub mod topic;
/// Metadata about an image. /// Metadata about an image.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]

View File

@ -1,17 +1,16 @@
//! Types for the *m.room.aliases* event. //! Types for the *m.room.aliases* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use ruma_identifiers::RoomAliasId; use ruma_identifiers::RoomAliasId;
use serde::{Deserialize, Serialize};
state_event! { ruma_event! {
/// Informs the room about what room aliases it has been given. /// Informs the room about what room aliases it has been given.
pub struct AliasesEvent(AliasesEventContent) {} AliasesEvent {
} kind: StateEvent,
event_type: RoomAliases,
/// The payload of an `AliasesEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AliasesEventContent {
/// A list of room aliases. /// A list of room aliases.
pub aliases: Vec<RoomAliasId>, pub aliases: Vec<RoomAliasId>,
},
}
} }

View File

@ -1,20 +1,17 @@
//! Types for the *m.room.avatar* event. //! Types for the *m.room.avatar* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize};
use super::ImageInfo; use super::ImageInfo;
state_event! { ruma_event! {
/// A picture that is associated with the room. /// A picture that is associated with the room.
/// ///
/// This can be displayed alongside the room information. /// This can be displayed alongside the room information.
pub struct AvatarEvent(AvatarEventContent) {} AvatarEvent {
} kind: StateEvent,
event_type: RoomAvatar,
/// The payload of an `AvatarEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AvatarEventContent {
/// Information about the avatar image. /// Information about the avatar image.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<ImageInfo>, pub info: Option<ImageInfo>,
@ -22,4 +19,6 @@ pub struct AvatarEventContent {
/// Information about the avatar thumbnail image. /// Information about the avatar thumbnail image.
/// URL of the avatar image. /// URL of the avatar image.
pub url: String, pub url: String,
},
}
} }

View File

@ -1,18 +1,16 @@
//! Types for the *m.room.encryption* event. //! Types for the *m.room.encryption* event.
use js_int::UInt; use js_int::UInt;
use serde::{Deserialize, Serialize}; use ruma_events_macros::ruma_event;
use crate::Algorithm; use crate::Algorithm;
state_event! { ruma_event! {
/// Defines how messages sent in this room should be encrypted. /// Defines how messages sent in this room should be encrypted.
pub struct EncryptionEvent(EncryptionEventContent) {} EncryptionEvent {
} kind: StateEvent,
event_type: RoomEncryption,
/// The payload of an *m.room.encryption* event. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct EncryptionEventContent {
/// The encryption algorithm to be used to encrypt messages sent in this room. /// The encryption algorithm to be used to encrypt messages sent in this room.
/// ///
/// Must be `m.megolm.v1.aes-sha2`. /// Must be `m.megolm.v1.aes-sha2`.
@ -27,4 +25,6 @@ pub struct EncryptionEventContent {
/// ///
/// 100 is the recommended default. /// 100 is the recommended default.
pub rotation_period_msgs: Option<UInt>, pub rotation_period_msgs: Option<UInt>,
},
}
} }

View File

@ -1,21 +1,21 @@
//! Types for the *m.room.guest_access* event. //! Types for the *m.room.guest_access* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
state_event! { ruma_event! {
/// Controls whether guest users are allowed to join rooms. /// 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, /// 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`. /// servers should act as if it is present and has the value `GuestAccess::Forbidden`.
pub struct GuestAccessEvent(GuestAccessEventContent) {} GuestAccessEvent {
} kind: StateEvent,
event_type: RoomGuestAccess,
/// The payload of a `GuestAccessEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct GuestAccessEventContent {
/// A policy for guest user access to a room. /// A policy for guest user access to a room.
pub guest_access: GuestAccess, pub guest_access: GuestAccess,
},
}
} }
/// A policy for guest user access to a room. /// A policy for guest user access to a room.

View File

@ -1,19 +1,19 @@
//! Types for the *m.room.history_visibility* event. //! Types for the *m.room.history_visibility* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; 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 /// This event controls whether a member of a room can see the events that happened in a room
/// from before they joined. /// from before they joined.
pub struct HistoryVisibilityEvent(HistoryVisibilityEventContent) {} HistoryVisibilityEvent {
} kind: StateEvent,
event_type: RoomHistoryVisibility,
/// The payload of a `HistoryVisibilityEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct HistoryVisibilityEventContent {
/// Who can see the room history. /// Who can see the room history.
pub history_visibility: HistoryVisibility, pub history_visibility: HistoryVisibility,
},
}
} }
/// Who can see a room's history. /// Who can see a room's history.

View File

@ -1,18 +1,18 @@
//! Types for the *m.room.join_rules* event. //! Types for the *m.room.join_rules* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
state_event! { ruma_event! {
/// Describes how users are allowed to join the room. /// Describes how users are allowed to join the room.
pub struct JoinRulesEvent(JoinRulesEventContent) {} JoinRulesEvent {
} kind: StateEvent,
event_type: RoomJoinRules,
/// The payload of a `JoinRulesEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct JoinRulesEventContent {
/// The type of rules used for users wishing to join this room. /// The type of rules used for users wishing to join this room.
pub join_rule: JoinRule, pub join_rule: JoinRule,
},
}
} }
/// The rule used for users wishing to join this room. /// The rule used for users wishing to join this room.

View File

@ -1,11 +1,12 @@
//! Types for the *m.room.member* event. //! Types for the *m.room.member* event.
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::ruma_event;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use ruma_signatures::Signatures; use ruma_signatures::Signatures;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
state_event! { ruma_event! {
/// The current membership state of a user in the room. /// 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 /// Adjusts the membership state for a user in a room. It is preferable to use the membership
@ -31,12 +32,10 @@ state_event! {
/// The membership for a given user can change over time. Previous membership can be retrieved /// 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 /// from the `prev_content` object on an event. If not present, the user's previous membership
/// must be assumed as leave. /// must be assumed as leave.
pub struct MemberEvent(MemberEventContent) {} MemberEvent {
} kind: StateEvent,
event_type: RoomMember,
/// The payload of a `MemberEvent`. content: {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MemberEventContent {
/// The avatar URL for this user, if any. This is added by the homeserver. /// The avatar URL for this user, if any. This is added by the homeserver.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>, pub avatar_url: Option<String>,
@ -53,10 +52,12 @@ pub struct MemberEventContent {
/// The membership state of this user. /// The membership state of this user.
pub membership: MembershipState, pub membership: MembershipState,
/// If this member event is the successor to a third party invitation, this field will contain /// If this member event is the successor to a third party invitation, this field will
/// information about that invitation. /// contain information about that invitation.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub third_party_invite: Option<ThirdPartyInvite>, pub third_party_invite: Option<ThirdPartyInvite>,
},
}
} }
/// The membership state of a user. /// The membership state of a user.

View File

@ -1,19 +1,18 @@
//! Types for the *m.room.pinned_events* event. //! Types for the *m.room.pinned_events* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use ruma_identifiers::EventId; 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. /// Used to "pin" particular events in a room for other participants to review later.
pub struct PinnedEventsEvent(PinnedEventsContent) {} PinnedEventsEvent {
} kind: StateEvent,
event_type: RoomPinnedEvents,
/// The payload of a `NameEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct PinnedEventsContent {
/// 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)]
@ -22,16 +21,16 @@ mod tests {
use js_int::UInt; use js_int::UInt;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use serde_json::{from_str, to_string}; use serde_json::to_string;
use crate::{ use crate::{
room::pinned_events::{PinnedEventsContent, PinnedEventsEvent}, room::pinned_events::{PinnedEventsEvent, PinnedEventsEventContent},
Event, EventType, RoomEvent, StateEvent, Event, RoomEvent, StateEvent,
}; };
#[test] #[test]
fn serialization_deserialization() { 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());
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 { let event = PinnedEventsEvent {
content: content.clone(), content: content.clone(),
event_id: EventId::new("example.com").unwrap(), event_id: EventId::new("example.com").unwrap(),
event_type: EventType::RoomPinnedEvents,
origin_server_ts: UInt::try_from(1_432_804_485_886u64).unwrap(), origin_server_ts: UInt::try_from(1_432_804_485_886u64).unwrap(),
prev_content: None, prev_content: None,
room_id: Some(RoomId::new("example.com").unwrap()), room_id: Some(RoomId::new("example.com").unwrap()),
@ -49,7 +47,7 @@ mod tests {
}; };
let serialized_event = to_string(&event).unwrap(); 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.event_id(), event.event_id());
assert_eq!(parsed_event.room_id(), event.room_id()); assert_eq!(parsed_event.room_id(), event.room_id());

View File

@ -1,20 +1,18 @@
//! Types for the *m.room.third_party_invite* event. //! Types for the *m.room.third_party_invite* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize}; 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. /// 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. Any /// event contains a token and a public key whose private key must be used to sign the token.
/// 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.
pub struct ThirdPartyInviteEvent(ThirdPartyInviteEventContent) {} ThirdPartyInviteEvent {
} kind: StateEvent,
event_type: RoomThirdPartyInvite,
/// The payload of a `ThirdPartyInviteEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ThirdPartyInviteEventContent {
/// 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,
@ -27,6 +25,8 @@ pub struct ThirdPartyInviteEventContent {
/// 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,21 +1,20 @@
//! Types for the *m.room.tombstone* event. //! Types for the *m.room.tombstone* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use ruma_identifiers::RoomId; 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 /// 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.
pub struct TombstoneEvent(TombstoneEventContent) {} TombstoneEvent {
} kind: StateEvent,
event_type: RoomTombstone,
/// The payload of an *m.room.tombstone* event. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TombstoneEventContent {
/// 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,16 +1,15 @@
//! Types for the *m.room.topic* event. //! Types for the *m.room.topic* event.
use js_int::UInt; use ruma_events_macros::ruma_event;
use serde::{Deserialize, Serialize};
state_event! { 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.
pub struct TopicEvent(TopicEventContent) {} TopicEvent {
} kind: StateEvent,
event_type: RoomTopic,
/// The payload of a `TopicEvent`. content: {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TopicEventContent {
/// The topic text. /// The topic text.
pub topic: String, pub topic: String,
},
}
} }