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)]
mod tests {
use std::{collections::HashMap, convert::TryFrom};
use std::convert::TryFrom;
use ruma_identifiers::UserId;

View File

@ -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)]

View File

@ -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 {
AliasesEvent {
kind: StateEvent,
event_type: RoomAliases,
content: {
/// A list of room aliases.
pub aliases: Vec<RoomAliasId>,
},
}
}

View File

@ -1,20 +1,17 @@
//! 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) {}
}
/// The payload of an `AvatarEvent`.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AvatarEventContent {
AvatarEvent {
kind: StateEvent,
event_type: RoomAvatar,
content: {
/// Information about the avatar image.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<ImageInfo>,
@ -22,4 +19,6 @@ pub struct AvatarEventContent {
/// Information about the avatar thumbnail image.
/// URL of the avatar image.
pub url: String,
},
}
}

View File

@ -1,18 +1,16 @@
//! 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 {
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`.
@ -27,4 +25,6 @@ pub struct EncryptionEventContent {
///
/// 100 is the recommended default.
pub rotation_period_msgs: Option<UInt>,
},
}
}

View File

@ -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 {
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.

View File

@ -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 {
HistoryVisibilityEvent {
kind: StateEvent,
event_type: RoomHistoryVisibility,
content: {
/// Who can see the room history.
pub history_visibility: HistoryVisibility,
},
}
}
/// Who can see a room's history.

View File

@ -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 {
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.

View File

@ -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,12 +32,10 @@ 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) {}
}
/// The payload of a `MemberEvent`.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct 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<String>,
@ -53,10 +52,12 @@ pub struct MemberEventContent {
/// 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.
/// 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<ThirdPartyInvite>,
},
}
}
/// The membership state of a user.

View File

@ -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 {
PinnedEventsEvent {
kind: StateEvent,
event_type: RoomPinnedEvents,
content: {
/// An ordered list of event IDs to pin.
pub pinned: Vec<EventId>,
},
}
}
#[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());

View File

@ -1,20 +1,18 @@
//! 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) {}
}
/// The payload of a `ThirdPartyInviteEvent`.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct 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,
@ -27,6 +25,8 @@ pub struct ThirdPartyInviteEventContent {
/// 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,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) {}
}
/// The payload of an *m.room.tombstone* event.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TombstoneEventContent {
TombstoneEvent {
kind: StateEvent,
event_type: RoomTombstone,
content: {
/// A server-defined message.
pub body: String,
/// The new room the client should be visiting.
pub replacement_room: RoomId,
},
}
}

View File

@ -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 {
TopicEvent {
kind: StateEvent,
event_type: RoomTopic,
content: {
/// The topic text.
pub topic: String,
},
}
}