Convert Event, RoomEvent and StateEvent into traits.

This commit is contained in:
Jimmy Cuadra 2016-10-02 03:46:16 -07:00
parent f3acdfd141
commit 8392852741
24 changed files with 339 additions and 217 deletions

View File

@ -1,10 +1,11 @@
//! Types for the *m.call.answer* event. //! Types for the *m.call.answer* event.
use RoomEvent;
use super::SessionDescription; use super::SessionDescription;
/// This event is sent by the callee when they wish to answer the call. room_event! {
pub type AnswerEvent = RoomEvent<AnswerEventContent, ()>; /// This event is sent by the callee when they wish to answer the call.
pub struct AnswerEvent(AnswerEventContent) {}
}
/// The payload of an `AnswerEvent`. /// The payload of an `AnswerEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,10 +1,11 @@
//! Types for the *m.call.candidates* event. //! Types for the *m.call.candidates* event.
use RoomEvent; room_event! {
/// This event is sent by callers after sending an invite and by the callee after answering.
/// This event is sent by callers after sending an invite and by the callee after answering. /// Its purpose is to give the other party additional ICE candidates to try using to
/// Its purpose is to give the other party additional ICE candidates to try using to communicate. /// communicate.
pub type CandidatesEvent = RoomEvent<CandidatesEventContent, ()>; pub struct CandidatesEvent(CandidatesEventContent) {}
}
/// The payload of a `CandidatesEvent`. /// The payload of a `CandidatesEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,10 +1,10 @@
//! Types for the *m.call.hangup* event. //! Types for the *m.call.hangup* event.
use RoomEvent; room_event! {
/// Sent by either party to signal their termination of the call. This can be sent either once
/// Sent by either party to signal their termination of the call. This can be sent either once the /// the call has has been established or before to abort the call.
/// call has has been established or before to abort the call. pub struct HangupEvent(HangupEventContent) {}
pub type HangupEvent = RoomEvent<HangupEventContent, ()>; }
/// The payload of a `HangupEvent`. /// The payload of a `HangupEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,10 +1,11 @@
//! Types for the *m.call.invite* event. //! Types for the *m.call.invite* event.
use RoomEvent;
use super::SessionDescription; use super::SessionDescription;
/// This event is sent by the caller when they wish to establish a call. room_event! {
pub type InviteEvent = RoomEvent<InviteEventContent, ()>; /// This event is sent by the caller when they wish to establish a call.
pub struct InviteEvent(InviteEventContent) {}
}
/// The payload of an `InviteEvent`. /// The payload of an `InviteEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -9,7 +9,7 @@ extern crate serde;
extern crate serde_json; extern crate serde_json;
#[macro_use] extern crate serde_derive; #[macro_use] extern crate serde_derive;
use std::fmt::{Display, Formatter, Error as FmtError}; use std::fmt::{Debug, Display, Formatter, Error as FmtError};
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Deserializer, Error as SerdeError, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Error as SerdeError, Serialize, Serializer};
@ -81,93 +81,55 @@ pub enum EventType {
} }
/// A basic event. /// A basic event.
#[derive(Debug, Deserialize, Serialize)] pub trait Event: Debug + Deserialize + Serialize {
pub struct Event<C, E> where C: Deserialize + Serialize, E: Deserialize + Serialize { /// The event-type-specific payload this event carries.
/// Data specific to the event type. type Content;
pub content: C,
/// The event's content.
fn content(&self) -> &Self::Content;
/// The type of the event. /// The type of the event.
#[serde(rename="type")] fn event_type(&self) -> &EventType;
pub event_type: EventType,
/// Extra top-level key-value pairs specific to this event type, but that are not under the
/// `content` field.
pub extra_content: E,
} }
/// An event within the context of a room. /// An event within the context of a room.
#[derive(Debug, Deserialize, Serialize)] pub trait RoomEvent: Debug + Deserialize + Event + Serialize {
pub struct RoomEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + Serialize {
/// Data specific to the event type.
pub content: C,
/// The unique identifier for the event. /// The unique identifier for the event.
pub event_id: EventId, fn event_id(&self) -> &EventId;
/// Extra top-level key-value pairs specific to this event type, but that are not under the
/// `content` field.
pub extra_content: E,
/// The type of the event.
#[serde(rename="type")]
pub event_type: EventType,
/// The unique identifier for the room associated with this event. /// The unique identifier for the room associated with this event.
pub room_id: RoomId, fn room_id(&self) -> &RoomId;
/// Additional key-value pairs not signed by the homeserver. /// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if="Option::is_none")] fn unsigned(&self) -> Option<&Value>;
pub unsigned: Option<Value>,
/// The unique identifier for the user associated with this event. /// The unique identifier for the user associated with this event.
#[serde(rename="sender")] fn user_id(&self) -> &UserId;
pub user_id: UserId,
} }
/// An event that describes persistent state about a room. /// An event that describes persistent state about a room.
#[derive(Debug, Deserialize, Serialize)] pub trait StateEvent: Debug + Deserialize + RoomEvent + Serialize {
pub struct StateEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + Serialize {
/// Data specific to the event type.
pub content: C,
/// The unique identifier for the event.
pub event_id: EventId,
/// The type of the event.
#[serde(rename="type")]
pub event_type: EventType,
/// Extra top-level key-value pairs specific to this event type, but that are not under the
/// `content` field.
pub extra_content: E,
/// The previous content for this state key, if any. /// The previous content for this state key, if any.
#[serde(skip_serializing_if="Option::is_none")] fn prev_content(&self) -> Option<&Self::Content>;
pub prev_content: Option<C>,
/// The unique identifier for the room associated with this event.
pub room_id: RoomId,
/// A key that determines which piece of room state the event represents. /// A key that determines which piece of room state the event represents.
pub state_key: String, fn state_key(&self) -> &str;
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if="Option::is_none")]
pub unsigned: Option<Value>,
/// The unique identifier for the user associated with this event.
#[serde(rename="sender")]
pub user_id: UserId,
} }
/// A custom basic event not covered by the Matrix specification. event! {
pub type CustomEvent = Event<Value, ()>; /// A custom basic event not covered by the Matrix specification.
pub struct CustomEvent(Value) {}
}
/// A custom room event not covered by the Matrix specification. room_event! {
pub type CustomRoomEvent = RoomEvent<Value, ()>; /// A custom room event not covered by the Matrix specification.
pub struct CustomRoomEvent(Value) {}
}
/// A custom state event not covered by the Matrix specification. state_event! {
pub type CustomStateEvent = StateEvent<Value, ()>; /// A custom state event not covered by the Matrix specification.
pub struct CustomStateEvent(Value) {}
}
impl Display for EventType { impl Display for EventType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {

View File

@ -22,3 +22,182 @@ macro_rules! impl_enum {
} }
} }
} }
macro_rules! event {
( $(#[$attr:meta])*
pub struct $name:ident($content_type:ty) {
$(
$(#[$field_attr:meta])*
pub $field_name:ident: $field_type:ty
),*
}
) => {
$(#[$attr])*
#[derive(Debug, Deserialize, Serialize)]
pub struct $name {
/// The event's content.
pub content: $content_type,
/// The type of the event.
#[serde(rename="type")]
pub event_type: $crate::EventType,
$(
$(#[$field_attr])*
pub $field_name: $field_type
),*
}
impl_event!($name, $content_type);
}
}
macro_rules! impl_event {
($name:ident, $content_type:ty) => {
impl $crate::Event for $name {
type Content = $content_type;
fn content(&self) -> &<$name as $crate::Event>::Content {
&self.content
}
fn event_type(&self) -> &$crate::EventType {
&self.event_type
}
}
}
}
macro_rules! room_event {
( $(#[$attr:meta])*
pub struct $name:ident($content_type:ty) {
$(
$(#[$field_attr:meta])*
pub $field_name:ident: $field_type:ty
),*
}
) => {
$(#[$attr])*
#[derive(Debug, Deserialize, Serialize)]
pub struct $name {
/// The event's content.
pub content: $content_type,
/// The unique identifier for the event.
pub event_id: ::ruma_identifiers::EventId,
/// The type of the event.
#[serde(rename="type")]
pub event_type: $crate::EventType,
/// The unique identifier for the room associated with this event.
pub room_id: ::ruma_identifiers::RoomId,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if="Option::is_none")]
pub unsigned: Option<::serde_json::Value>,
/// The unique identifier for the user associated with this event.
#[serde(rename="sender")]
pub user_id: ::ruma_identifiers::UserId,
$(
$(#[$field_attr])*
pub $field_name: $field_type
),*
}
impl_room_event!($name, $content_type);
}
}
macro_rules! impl_room_event {
($name:ident, $content_type:ty) => {
impl_event!($name, $content_type);
impl $crate::RoomEvent for $name {
fn event_id(&self) -> &::ruma_identifiers::EventId {
&self.event_id
}
fn room_id(&self) -> &::ruma_identifiers::RoomId {
&self.room_id
}
fn unsigned(&self) -> Option<&::serde_json::Value> {
self.unsigned.as_ref()
}
fn user_id(&self) -> &::ruma_identifiers::UserId {
&self.user_id
}
}
}
}
macro_rules! state_event {
( $(#[$attr:meta])*
pub struct $name:ident($content_type:ty) {
$(
$(#[$field_attr:meta])*
pub $field_name:ident: $field_type:ty
),*
}
) => {
$(#[$attr])*
#[allow(missing_docs)]
#[derive(Debug, Deserialize, Serialize)]
pub struct $name {
/// The event's content.
pub content: $content_type,
/// The unique identifier for the event.
pub event_id: ::ruma_identifiers::EventId,
/// The type of the event.
#[serde(rename="type")]
pub event_type: $crate::EventType,
/// The previous content for this state key, if any.
#[serde(skip_serializing_if="Option::is_none")]
pub prev_content: Option<$content_type>,
/// The unique identifier for the room associated with this event.
pub room_id: ::ruma_identifiers::RoomId,
/// A key that determines which piece of room state the event represents.
pub state_key: String,
/// Additional key-value pairs not signed by the homeserver.
#[serde(skip_serializing_if="Option::is_none")]
pub unsigned: Option<::serde_json::Value>,
/// The unique identifier for the user associated with this event.
#[serde(rename="sender")]
pub user_id: ::ruma_identifiers::UserId,
$(
$(#[$field_attr])*
pub $field_name: $field_type
),*
}
impl_state_event!($name, $content_type);
}
}
macro_rules! impl_state_event {
($name:ident, $content_type:ty) => {
impl_room_event!($name, $content_type);
impl $crate::StateEvent for $name {
fn prev_content(&self) -> Option<&Self::Content> {
self.prev_content.as_ref()
}
fn state_key(&self) -> &str {
&self.state_key
}
}
}
}

View File

@ -2,10 +2,13 @@
use ruma_identifiers::{EventId, UserId}; use ruma_identifiers::{EventId, UserId};
use Event; event! {
/// Informs the client of a user's presence state change.
/// Informs the client of a user's presence state change. pub struct PresenceEvent(PresenceEventContent) {
pub type PresenceEvent = Event<PresenceEventContent, PresenceEventExtraContent>; /// The unique identifier for the event.
pub event_id: EventId
}
}
/// The payload of a `PresenceEvent`. /// The payload of a `PresenceEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@ -47,18 +50,3 @@ pub enum PresenceState {
#[serde(rename="unavailable")] #[serde(rename="unavailable")]
Unavailable, Unavailable,
} }
/// Extra content for a `PresenceEvent`.
#[derive(Debug, Deserialize, Serialize)]
pub struct PresenceEventExtraContent {
/// The unique identifier for the event.
pub event_id: EventId,
}
impl_enum! {
PresenceState {
Offline => "offline",
Online => "online",
Unavailable => "unavailable",
}
}

View File

@ -4,10 +4,13 @@ use std::collections::HashMap;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use Event; event! {
/// Informs the client of new receipts.
/// Informs the client of new receipts. pub struct ReceiptEvent(ReceiptEventContent) {
pub type ReceiptEvent = Event<ReceiptEventContent, ReceiptEventExtraContent>; /// The unique identifier for the room associated with this event.
pub room_id: RoomId
}
}
/// The payload of a `ReceiptEvent`. /// The payload of a `ReceiptEvent`.
/// ///
@ -33,10 +36,3 @@ pub struct Receipt {
/// The timestamp the receipt was sent at. /// The timestamp the receipt was sent at.
pub ts: u64, pub ts: u64,
} }
/// Extra content for a `PresenceEvent`.
#[derive(Debug, Deserialize, Serialize)]
pub struct ReceiptEventExtraContent {
/// The unique identifier for the room associated with this event.
pub room_id: RoomId,
}

View File

@ -2,10 +2,10 @@
use ruma_identifiers::RoomAliasId; use ruma_identifiers::RoomAliasId;
use StateEvent; state_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) {}
pub type AliasesEvent = StateEvent<AliasesEventContent, ()>; }
/// The payload of an `AliasesEvent`. /// The payload of an `AliasesEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,12 +1,13 @@
//! Types for the *m.room.avatar* event. //! Types for the *m.room.avatar* event.
use StateEvent;
use super::ImageInfo; use super::ImageInfo;
/// A picture that is associated with the room. state_event! {
/// /// A picture that is associated with the room.
/// This can be displayed alongside the room information. ///
pub type AvatarEvent = StateEvent<AvatarEventContent, ()>; /// This can be displayed alongside the room information.
pub struct AvatarEvent(AvatarEventContent) {}
}
/// The payload of an `AvatarEvent`. /// The payload of an `AvatarEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,10 +2,10 @@
use ruma_identifiers::RoomAliasId; use ruma_identifiers::RoomAliasId;
use StateEvent; state_event! {
/// Informs the room as to which alias is the canonical one.
/// Informs the room as to which alias is the canonical one. pub struct CanonicalAliasEvent(CanonicalAliasEventContent) {}
pub type CanonicalAliasEvent = StateEvent<CanonicalAliasEventContent, ()>; }
/// The payload of a `CanonicalAliasEvent`. /// The payload of a `CanonicalAliasEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,11 +2,11 @@
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use StateEvent; state_event! {
/// This is the first event in a room and cannot be changed. It acts as the root of all other
/// This is the first event in a room and cannot be changed. It acts as the root of all other /// events.
/// events. pub struct CreateEvent(CreateEventContent) {}
pub type CreateEvent = StateEvent<CreateEventContent, ()>; }
/// The payload of a `CreateEvent`. /// The payload of a `CreateEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,12 +1,12 @@
//! Types for the *m.room.guest_access* event. //! Types for the *m.room.guest_access* event.
use StateEvent; state_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) {}
pub type GuestAccessEvent = StateEvent<GuestAccessEventContent, ()>; }
/// The payload of a `GuestAccessEvent`. /// The payload of a `GuestAccessEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,10 +1,10 @@
//! Types for the *m.room.history_visibility* event. //! Types for the *m.room.history_visibility* event.
use StateEvent; state_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 /// from before they joined.
/// before they joined. pub struct HistoryVisibilityEvent(HistoryVisibilityEventContent) {}
pub type HistoryVisibilityEvent = StateEvent<HistoryVisibilityEventContent, ()>; }
/// The payload of a `HistoryVisibilityEvent`. /// The payload of a `HistoryVisibilityEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,9 +1,9 @@
//! Types for the *m.room.join_rules* event. //! Types for the *m.room.join_rules* event.
use StateEvent; state_event! {
/// Describes how users are allowed to join the room.
/// Describes how users are allowed to join the room. pub struct JoinRulesEvent(JoinRulesEventContent) {}
pub type JoinRulesEvent = StateEvent<JoinRulesEventContent, ()>; }
/// The payload of a `JoinRulesEvent`. /// The payload of a `JoinRulesEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,22 +1,28 @@
//! Types for the *m.room.member* event. //! Types for the *m.room.member* event.
use StateEvent;
use stripped::StrippedState; use stripped::StrippedState;
/// The current membership state of a user in the room. state_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 APIs ///
/// (``/rooms/<room id>/invite`` etc) when performing membership actions rather than adjusting the /// Adjusts the membership state for a user in a room. It is preferable to use the membership
/// state directly as there are a restricted set of valid transformations. For example, user A /// APIs (``/rooms/<room id>/invite`` etc) when performing membership actions rather than
/// cannot force user B to join a room, and trying to force this state change directly will fail. /// adjusting the state directly as there are a restricted set of valid transformations. For
/// /// example, user A cannot force user B to join a room, and trying to force this state change
/// The *third_party_invite* property will be set if this invite is an *invite* event and is the /// directly will fail.
/// successor of an *m.room.third_party_invite* event, and absent otherwise. ///
/// /// The *third_party_invite* property will be set if this invite is an *invite* event and is the
/// This event may also include an *invite_room_state* key outside the *content* key. If present, /// successor of an *m.room.third_party_invite* event, and absent otherwise.
/// this contains an array of `StrippedState` events. These events provide information on a few ///
/// select state events such as the room name. /// This event may also include an *invite_room_state* key outside the *content* key. If
pub type MemberEvent = StateEvent<MemberEventContent, MemberEventExtraContent>; /// present, this contains an array of `StrippedState` events. These events provide information
/// on a few select state events such as the room name.
pub struct MemberEvent(MemberEventContent) {
/// A subset of the state of the room at the time of the invite.
#[serde(skip_serializing_if="Option::is_none")]
pub invite_room_state: Option<Vec<StrippedState>>
}
}
/// The payload of a `MemberEvent`. /// The payload of a `MemberEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@ -60,14 +66,6 @@ pub enum MembershipState {
Leave, Leave,
} }
/// Extra content for a `MemberEvent`.
#[derive(Debug, Deserialize, Serialize)]
pub struct MemberEventExtraContent {
/// A subset of the state of the room at the time of the invite.
#[serde(skip_serializing_if="Option::is_none")]
pub invite_room_state: Option<Vec<StrippedState>>,
}
impl_enum! { impl_enum! {
MembershipState { MembershipState {
Ban => "ban", Ban => "ban",

View File

@ -3,11 +3,12 @@
use serde::{Deserialize, Deserializer, Error as SerdeError, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Error as SerdeError, Serialize, Serializer};
use serde_json::{Value, from_value}; use serde_json::{Value, from_value};
use RoomEvent;
use super::ImageInfo; use super::ImageInfo;
/// A message sent to a room. room_event! {
pub type MessageEvent = RoomEvent<MessageEventContent, ()>; /// A message sent to a room.
pub struct MessageEvent(MessageEventContent) {}
}
/// The message type of message event, e.g. `m.image` or `m.text`. /// The message type of message event, e.g. `m.image` or `m.text`.
#[derive(Debug, Deserialize, PartialEq, Serialize)] #[derive(Debug, Deserialize, PartialEq, Serialize)]

View File

@ -1,9 +1,9 @@
//! Types for the *m.room.name* event. //! Types for the *m.room.name* event.
use StateEvent; state_event! {
/// A human-friendly room name designed to be displayed to the end-user.
/// A human-friendly room name designed to be displayed to the end-user. pub struct NameEvent(NameEventContent) {}
pub type NameEvent = StateEvent<NameEventContent, ()>; }
/// The payload of a `NameEvent`. /// The payload of a `NameEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -4,10 +4,12 @@ use std::collections::HashMap;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use {EventType, StateEvent}; use EventType;
/// Defines the power levels (privileges) of users in the room. state_event! {
pub type PowerLevelsEvent = StateEvent<PowerLevelsEventContent, ()>; /// Defines the power levels (privileges) of users in the room.
pub struct PowerLevelsEvent(PowerLevelsEventContent) {}
}
/// The payload of a `PowerLevelsEvent`. /// The payload of a `PowerLevelsEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,10 +2,13 @@
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use RoomEvent; room_event! {
/// A redaction of an event.
/// A redaction of an event. pub struct RedactionEvent(RedactionEventContent) {
pub type RedactionEvent = RoomEvent<RedactionEventContent, RedactionEventExtraContent>; /// The ID of the event that was redacted.
pub redacts: EventId
}
}
/// The payload of a `RedactionEvent`. /// The payload of a `RedactionEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@ -14,10 +17,3 @@ pub struct RedactionEventContent {
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub reason: Option<String>, pub reason: Option<String>,
} }
/// Extra content for a `RedactionEvent`.
#[derive(Debug, Deserialize, Serialize)]
pub struct RedactionEventExtraContent {
/// The ID of the event that was redacted.
pub redacts: EventId,
}

View File

@ -1,13 +1,13 @@
//! Types for the *m.room.third_party_invite* event. //! Types for the *m.room.third_party_invite* event.
use StateEvent; state_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. Any /// user who can present that signature may use this invitation to join the target room.
/// user who can present that signature may use this invitation to join the target room. pub struct ThirdPartyInviteEvent(ThirdPartyInviteEventContent) {}
pub type ThirdPartyInviteEvent = StateEvent<ThirdPartyInviteEventContent, ()>; }
/// The payload of a `ThirdPartyInviteEvent`. /// The payload of a `ThirdPartyInviteEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,9 +1,9 @@
//! Types for the *m.room.topic* event. //! Types for the *m.room.topic* event.
use StateEvent; state_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) {}
pub type TopicEvent = StateEvent<TopicEventContent, ()>; }
/// The payload of a `TopicEvent`. /// The payload of a `TopicEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,10 +2,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use Event; event! {
/// Informs the client of tags on a room.
/// Informs the client of tags on a room. pub struct TagEvent(TagEventContent) {}
pub type TagEvent = Event<TagEventContent, ()>; }
/// The payload of a `TagEvent`. /// The payload of a `TagEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,10 +2,13 @@
use ruma_identifiers::{EventId, RoomId}; use ruma_identifiers::{EventId, RoomId};
use Event; event! {
/// Informs the client of the list of users currently typing.
/// Informs the client of the list of users currently typing. pub struct TypingEvent(TypingEventContent) {
pub type TypingEvent = Event<TypingEventContent, TypingEventExtraContent>; /// The unique identifier for the room associated with this event.
pub room_id: RoomId
}
}
/// The payload of a `TypingEvent`. /// The payload of a `TypingEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@ -13,10 +16,3 @@ pub struct TypingEventContent {
/// The list of user IDs typing in this room, if any. /// The list of user IDs typing in this room, if any.
pub user_ids: Vec<EventId>, pub user_ids: Vec<EventId>,
} }
/// Extra content for a `TypingEvent`.
#[derive(Debug, Deserialize, Serialize)]
pub struct TypingEventExtraContent {
/// The unique identifier for the room associated with this event.
pub room_id: RoomId,
}