Revert the package name to ruma-events.

This commit is contained in:
Jimmy Cuadra 2016-06-21 21:29:43 -07:00
parent f662f086b3
commit 68265a9387
29 changed files with 139 additions and 143 deletions

View File

@ -1,13 +1,13 @@
[package] [package]
authors = ["Jimmy Cuadra <jimmy@jimmycuadra.com>"] authors = ["Jimmy Cuadra <jimmy@jimmycuadra.com>"]
description = "Types shared by ruma and ruma-client." description = "Serializable types for the events in the Matrix specification."
documentation = "http://ruma.github.io/ruma-common/ruma_common" documentation = "http://ruma.github.io/ruma-common/ruma_events"
homepage = "https://github.com/ruma/ruma-events" homepage = "https://github.com/ruma/ruma-events"
keywords = ["matrix", "matrix.org", "chat", "messaging", "ruma"] keywords = ["matrix", "matrix.org", "chat", "messaging", "ruma"]
license = "MIT" license = "MIT"
name = "ruma-common" name = "ruma-events"
readme = "README.md" readme = "README.md"
repository = "https://github.com/ruma/ruma-common" repository = "https://github.com/ruma/ruma-events"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]

View File

@ -1,6 +1,6 @@
# ruma-common # ruma-events
**ruma-common** contains serializable types for the events and APIs in the [Matrix](https://matrix.org/) client-server specification that can be shared by client and server code. **ruma-events** contains serializable types for the events in the [Matrix](https://matrix.org/) specification that can be shared by client and server code.
## Status ## Status

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.answer* event. //! Types for the *m.call.answer* event.
use events::RoomEvent; use RoomEvent;
use super::SessionDescription; use super::SessionDescription;
/// This event is sent by the callee when they wish to answer the call. /// This event is sent by the callee when they wish to answer the call.

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.candidates* event. //! Types for the *m.call.candidates* event.
use events::RoomEvent; use RoomEvent;
/// 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 communicate. /// Its purpose is to give the other party additional ICE candidates to try using to communicate.

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.hangup* event. //! Types for the *m.call.hangup* event.
use events::RoomEvent; use RoomEvent;
/// Sent by either party to signal their termination of the call. This can be sent either once the /// Sent by either party to signal their termination of the call. This can be sent either once the
/// call has has been established or before to abort the call. /// call has has been established or before to abort the call.

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.invite* event. //! Types for the *m.call.invite* event.
use events::RoomEvent; use RoomEvent;
use super::SessionDescription; use super::SessionDescription;
/// This event is sent by the caller when they wish to establish a call. /// This event is sent by the caller when they wish to establish a call.

View File

@ -1,105 +0,0 @@
//! Event types.
use std::fmt::{Display, Formatter, Error as FmtError};
use serde::{Deserialize, Serialize};
pub mod call;
pub mod presence;
pub mod receipt;
pub mod room;
pub mod stripped;
pub mod tag;
pub mod typing;
/// The type of an event.
#[derive(Debug, Deserialize, Serialize)]
pub enum EventType {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Tag,
Typing,
}
/// A basic event.
#[derive(Debug, Deserialize, Serialize)]
pub struct Event<T> where T: Deserialize + Serialize {
pub content: T,
#[serde(rename="type")]
pub event_type: EventType,
}
/// An event within the context of a room.
#[derive(Debug, Deserialize, Serialize)]
pub struct RoomEvent<T> where T: Deserialize + Serialize {
pub content: T,
pub event_id: String,
#[serde(rename="type")]
pub event_type: EventType,
pub room_id: String,
#[serde(rename="sender")]
pub user_id: String,
}
/// An event that describes persistent state about a room.
#[derive(Debug, Deserialize, Serialize)]
pub struct StateEvent<T> where T: Deserialize + Serialize {
pub content: T,
pub event_id: String,
#[serde(rename="type")]
pub event_type: EventType,
pub prev_content: Option<T>,
pub room_id: String,
pub state_key: String,
#[serde(rename="sender")]
pub user_id: String,
}
impl Display for EventType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
let event_type_str = match *self {
EventType::CallAnswer => "m.call.answer",
EventType::CallCandidates => "m.call.candidates",
EventType::CallHangup => "m.call.hangup",
EventType::CallInvite => "m.call.invite",
EventType::Presence => "m.presence",
EventType::Receipt => "m.receipt",
EventType::RoomAliases => "m.room.aliases",
EventType::RoomAvatar => "m.room.avatar",
EventType::RoomCanonicalAlias => "m.room.canonical_alias",
EventType::RoomCreate => "m.room.create",
EventType::RoomGuestAccess => "m.room.guest_access",
EventType::RoomHistoryVisibility => "m.room.history_visibility",
EventType::RoomJoinRules => "m.room.join_rules",
EventType::RoomMember => "m.room.member",
EventType::RoomMessage => "m.room.message",
EventType::RoomName => "m.room.name",
EventType::RoomPowerLevels => "m.room.power_levels",
EventType::RoomRedaction => "m.room.redaction",
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
EventType::RoomTopic => "m.room.topic",
EventType::Tag => "m.tag",
EventType::Typing => "m.typing",
};
write!(f, "{}", event_type_str)
}
}

View File

@ -1,10 +1,111 @@
//! Crate ruma_common contains serializable types for the events and APIs in the //! Crate ruma_events contains serializable types for the events in the [Matrix](https://matrix.org)
//! [Matrix](https://matrix.org) client-server specification that can be shared by client and //! specification that can be shared by client and server code.
//! server code.
#![feature(custom_derive, plugin)] #![feature(custom_derive, plugin)]
#![plugin(serde_macros)] #![plugin(serde_macros)]
extern crate serde; extern crate serde;
pub mod events; use std::fmt::{Display, Formatter, Error as FmtError};
use serde::{Deserialize, Serialize};
pub mod call;
pub mod presence;
pub mod receipt;
pub mod room;
pub mod stripped;
pub mod tag;
pub mod typing;
/// The type of an event.
#[derive(Debug, Deserialize, Serialize)]
pub enum EventType {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Tag,
Typing,
}
/// A basic event.
#[derive(Debug, Deserialize, Serialize)]
pub struct Event<T> where T: Deserialize + Serialize {
pub content: T,
#[serde(rename="type")]
pub event_type: EventType,
}
/// An event within the context of a room.
#[derive(Debug, Deserialize, Serialize)]
pub struct RoomEvent<T> where T: Deserialize + Serialize {
pub content: T,
pub event_id: String,
#[serde(rename="type")]
pub event_type: EventType,
pub room_id: String,
#[serde(rename="sender")]
pub user_id: String,
}
/// An event that describes persistent state about a room.
#[derive(Debug, Deserialize, Serialize)]
pub struct StateEvent<T> where T: Deserialize + Serialize {
pub content: T,
pub event_id: String,
#[serde(rename="type")]
pub event_type: EventType,
pub prev_content: Option<T>,
pub room_id: String,
pub state_key: String,
#[serde(rename="sender")]
pub user_id: String,
}
impl Display for EventType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
let event_type_str = match *self {
EventType::CallAnswer => "m.call.answer",
EventType::CallCandidates => "m.call.candidates",
EventType::CallHangup => "m.call.hangup",
EventType::CallInvite => "m.call.invite",
EventType::Presence => "m.presence",
EventType::Receipt => "m.receipt",
EventType::RoomAliases => "m.room.aliases",
EventType::RoomAvatar => "m.room.avatar",
EventType::RoomCanonicalAlias => "m.room.canonical_alias",
EventType::RoomCreate => "m.room.create",
EventType::RoomGuestAccess => "m.room.guest_access",
EventType::RoomHistoryVisibility => "m.room.history_visibility",
EventType::RoomJoinRules => "m.room.join_rules",
EventType::RoomMember => "m.room.member",
EventType::RoomMessage => "m.room.message",
EventType::RoomName => "m.room.name",
EventType::RoomPowerLevels => "m.room.power_levels",
EventType::RoomRedaction => "m.room.redaction",
EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
EventType::RoomTopic => "m.room.topic",
EventType::Tag => "m.tag",
EventType::Typing => "m.typing",
};
write!(f, "{}", event_type_str)
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.presence* event. //! Types for the *m.presence* event.
use events::EventType; use EventType;
/// Informs the client of a user's presence state change. /// Informs the client of a user's presence state change.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,7 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use events::EventType; use EventType;
/// Informs the client of new receipts. /// Informs the client of new receipts.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.aliases* event. //! Types for the *m.room.aliases* event.
use events::StateEvent; use StateEvent;
/// Informs the room about what room aliases it has been given. /// Informs the room about what room aliases it has been given.
pub type AliasesEvent = StateEvent<AliasesEventContent>; pub type AliasesEvent = StateEvent<AliasesEventContent>;

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.avatar* event. //! Types for the *m.room.avatar* event.
use events::StateEvent; use StateEvent;
use super::ImageInfo; use super::ImageInfo;
/// A picture that is associated with the room. /// A picture that is associated with the room.

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.canonical_alias* event. //! Types for the *m.room.canonical_alias* event.
use events::StateEvent; use StateEvent;
/// Informs the room as to which alias is the canonical one. /// Informs the room as to which alias is the canonical one.
pub type CanonicalAliasEvent = StateEvent<CanonicalAliasEventContent>; pub type CanonicalAliasEvent = StateEvent<CanonicalAliasEventContent>;

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.create* event. //! Types for the *m.room.create* event.
use events::StateEvent; use StateEvent;
/// 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.

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.guest_access* event. //! Types for the *m.room.guest_access* event.
use events::StateEvent; use StateEvent;
/// Controls whether guest users are allowed to join rooms. /// Controls whether guest users are allowed to join rooms.
/// ///

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.history_visibility* event. //! Types for the *m.room.history_visibility* event.
use events::StateEvent; use StateEvent;
/// This event controls whether a member of a room can see the events that happened in a room from /// This event controls whether a member of a room can see the events that happened in a room from
/// before they joined. /// before they joined.

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.join_rules* event. //! Types for the *m.room.join_rules* event.
use events::StateEvent; use StateEvent;
/// Describes how users are allowed to join the room. /// Describes how users are allowed to join the room.
pub type JoinRulesEvent = StateEvent<JoinRulesEventContent>; pub type JoinRulesEvent = StateEvent<JoinRulesEventContent>;

View File

@ -1,7 +1,7 @@
//! Types for the *m.room.member* event. //! Types for the *m.room.member* event.
use events::EventType; use EventType;
use events::stripped::StrippedState; use stripped::StrippedState;
/// The current membership state of a user in the room. /// The current membership state of a user in the room.
/// ///

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.message* event. //! Types for the *m.room.message* event.
use events::RoomEvent; use RoomEvent;
use super::ImageInfo; use super::ImageInfo;
/// A message sent to a room. /// A message sent to a room.

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.name* event. //! Types for the *m.room.name* event.
use events::StateEvent; use StateEvent;
/// 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 type NameEvent = StateEvent<NameEventContent>; pub type NameEvent = StateEvent<NameEventContent>;

View File

@ -2,7 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use events::StateEvent; use StateEvent;
/// Defines the power levels (privileges) of users in the room. /// Defines the power levels (privileges) of users in the room.
pub type PowerLevelsEvent = StateEvent<PowerLevelsEventContent>; pub type PowerLevelsEvent = StateEvent<PowerLevelsEventContent>;

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.redaction* event. //! Types for the *m.room.redaction* event.
use events::EventType; use EventType;
/// A redaction of an event. /// A redaction of an event.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.third_party_invite* event. //! Types for the *m.room.third_party_invite* event.
use events::StateEvent; use StateEvent;
/// 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.
/// ///

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.topic* event. //! Types for the *m.room.topic* event.
use events::StateEvent; use StateEvent;
/// 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 type TopicEvent = StateEvent<TopicEventContent>; pub type TopicEvent = StateEvent<TopicEventContent>;

View File

@ -2,11 +2,11 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use events::EventType; use EventType;
use events::room::avatar::AvatarEventContent; use room::avatar::AvatarEventContent;
use events::room::canonical_alias::CanonicalAliasEventContent; use room::canonical_alias::CanonicalAliasEventContent;
use events::room::join_rules::JoinRulesEventContent; use room::join_rules::JoinRulesEventContent;
use events::room::name::NameEventContent; use room::name::NameEventContent;
/// A stripped-down version of a state event that is included along with some other events. /// A stripped-down version of a state event that is included along with some other events.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

View File

@ -2,7 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use events::Event; use Event;
/// Informs the client of tags on a room. /// Informs the client of tags on a room.
pub type TagEvent = Event<TagEventContent>; pub type TagEvent = Event<TagEventContent>;

View File

@ -1,6 +1,6 @@
//! Types for the *m.typing* event. //! Types for the *m.typing* event.
use events::EventType; use EventType;
/// Informs the client of the list of users currently typing. /// Informs the client of the list of users currently typing.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]