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:
parent
22c15277a7
commit
4212c9f619
@ -101,7 +101,7 @@ mod raw {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::HashMap, convert::TryFrom};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
|
20
src/room.rs
20
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)]
|
||||
|
@ -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<RoomAliasId>,
|
||||
AliasesEvent {
|
||||
kind: StateEvent,
|
||||
event_type: RoomAliases,
|
||||
content: {
|
||||
/// A list of room aliases.
|
||||
pub aliases: Vec<RoomAliasId>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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<ImageInfo>,
|
||||
|
||||
/// 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<ImageInfo>,
|
||||
|
||||
/// 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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<UInt>,
|
||||
|
||||
/// How many messages should be sent before changing the session.
|
||||
///
|
||||
/// 100 is the recommended default.
|
||||
pub rotation_period_msgs: Option<UInt>,
|
||||
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<UInt>,
|
||||
|
||||
/// How many messages should be sent before changing the session.
|
||||
///
|
||||
/// 100 is the recommended default.
|
||||
pub rotation_period_msgs: Option<UInt>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
/// The display name for this user, if any. This is added by the homeserver.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub displayname: Option<String>,
|
||||
|
||||
/// The display name for this user, if any. This is added by the homeserver.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub displayname: Option<String>,
|
||||
/// 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<bool>,
|
||||
|
||||
/// 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<bool>,
|
||||
/// 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<ThirdPartyInvite>,
|
||||
/// 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.
|
||||
|
@ -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<EventId>,
|
||||
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());
|
||||
|
@ -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<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.
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user