Use ruma-identifiers types for ID values.

This commit is contained in:
Jimmy Cuadra 2016-07-28 03:04:07 -07:00
parent 223eab97c8
commit 5326091981
10 changed files with 38 additions and 19 deletions

View File

@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-events"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
ruma-identifiers = "0.2.0"
serde = "0.8.0" serde = "0.8.0"
serde_json = "0.8.0" serde_json = "0.8.0"
serde_macros = "0.8.0" serde_macros = "0.8.0"

View File

@ -5,11 +5,13 @@
#![plugin(serde_macros)] #![plugin(serde_macros)]
#![deny(missing_docs)] #![deny(missing_docs)]
extern crate ruma_identifiers;
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
use std::fmt::{Display, Formatter, Error as FmtError}; use std::fmt::{Display, Formatter, Error as FmtError};
use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
@ -22,7 +24,7 @@ pub mod tag;
pub mod typing; pub mod typing;
/// The type of an event. /// The type of an event.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum EventType { pub enum EventType {
/// m.call.answer /// m.call.answer
CallAnswer, CallAnswer,
@ -94,7 +96,7 @@ pub struct RoomEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + Se
pub content: C, pub content: C,
/// The unique identifier for the event. /// The unique identifier for the event.
pub event_id: String, pub event_id: EventId,
/// Extra top-level key-value pairs specific to this event type, but that are not under the /// Extra top-level key-value pairs specific to this event type, but that are not under the
/// `content` field. /// `content` field.
@ -105,14 +107,14 @@ pub struct RoomEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + Se
pub event_type: EventType, 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: String, pub room_id: RoomId,
/// Additional key-value pairs not signed by the homeserver. /// Additional key-value pairs not signed by the homeserver.
pub unsigned: 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")] #[serde(rename="sender")]
pub user_id: String, pub user_id: UserId,
} }
/// An event that describes persistent state about a room. /// An event that describes persistent state about a room.
@ -122,7 +124,7 @@ pub struct StateEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + S
pub content: C, pub content: C,
/// The unique identifier for the event. /// The unique identifier for the event.
pub event_id: String, pub event_id: EventId,
/// The type of the event. /// The type of the event.
#[serde(rename="type")] #[serde(rename="type")]
@ -136,7 +138,7 @@ pub struct StateEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + S
pub prev_content: Option<C>, pub prev_content: Option<C>,
/// The unique identifier for the room associated with this event. /// The unique identifier for the room associated with this event.
pub room_id: String, 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, pub state_key: String,
@ -146,7 +148,7 @@ pub struct StateEvent<C, E> where C: Deserialize + Serialize, E: Deserialize + S
/// The unique identifier for the user associated with this event. /// The unique identifier for the user associated with this event.
#[serde(rename="sender")] #[serde(rename="sender")]
pub user_id: String, pub user_id: UserId,
} }
impl Display for EventType { impl Display for EventType {

View File

@ -1,5 +1,7 @@
//! Types for the *m.presence* event. //! Types for the *m.presence* event.
use ruma_identifiers::{EventId, UserId};
use Event; use Event;
/// Informs the client of a user's presence state change. /// Informs the client of a user's presence state change.
@ -24,7 +26,7 @@ pub struct PresenceEventContent {
pub presence: PresenceState, pub presence: PresenceState,
/// The unique identifier for the user associated with this event. /// The unique identifier for the user associated with this event.
pub user_id: String, pub user_id: UserId,
} }
/// A description of a user's connectivity and availability for chat. /// A description of a user's connectivity and availability for chat.
@ -50,5 +52,5 @@ pub enum PresenceState {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct PresenceEventExtraContent { pub struct PresenceEventExtraContent {
/// The unique identifier for the event. /// The unique identifier for the event.
pub event_id: String, pub event_id: EventId,
} }

View File

@ -2,6 +2,8 @@
use std::collections::HashMap; use std::collections::HashMap;
use ruma_identifiers::RoomId;
use Event; use Event;
/// Informs the client of new receipts. /// Informs the client of new receipts.
@ -36,5 +38,5 @@ pub struct Receipt {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct ReceiptEventExtraContent { pub struct ReceiptEventExtraContent {
/// The unique identifier for the room associated with this event. /// The unique identifier for the room associated with this event.
pub room_id: String, pub room_id: RoomId,
} }

View File

@ -1,5 +1,7 @@
//! Types for the *m.room.aliases* event. //! Types for the *m.room.aliases* event.
use ruma_identifiers::RoomAliasId;
use 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.
@ -9,5 +11,5 @@ pub type AliasesEvent = StateEvent<AliasesEventContent, ()>;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct AliasesEventContent { pub struct AliasesEventContent {
/// A list of room aliases. /// A list of room aliases.
pub aliases: Vec<String>, pub aliases: Vec<RoomAliasId>,
} }

View File

@ -1,5 +1,7 @@
//! Types for the *m.room.canonical_alias* event. //! Types for the *m.room.canonical_alias* event.
use ruma_identifiers::RoomAliasId;
use 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.
@ -9,5 +11,5 @@ pub type CanonicalAliasEvent = StateEvent<CanonicalAliasEventContent, ()>;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct CanonicalAliasEventContent { pub struct CanonicalAliasEventContent {
/// The canonical alias. /// The canonical alias.
pub alias: String, pub alias: RoomAliasId,
} }

View File

@ -1,5 +1,7 @@
//! Types for the *m.room.create* event. //! Types for the *m.room.create* event.
use ruma_identifiers::UserId;
use 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
@ -10,7 +12,7 @@ pub type CreateEvent = StateEvent<CreateEventContent, ()>;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct CreateEventContent { pub struct CreateEventContent {
/// The `user_id` of the room creator. This is set by the homeserver. /// The `user_id` of the room creator. This is set by the homeserver.
pub creator: String, pub creator: UserId,
/// Whether or not this room's data should be transferred to other homeservers. /// Whether or not this room's data should be transferred to other homeservers.
pub federate: bool, pub federate: bool,
} }

View File

@ -2,7 +2,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use StateEvent; use ruma_identifiers::UserId;
use {EventType, 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, ()>;
@ -16,7 +18,7 @@ pub struct PowerLevelsEventContent {
/// The level required to send specific event types. /// The level required to send specific event types.
/// ///
/// This is a mapping from event type to power level required. /// This is a mapping from event type to power level required.
pub events: HashMap<String, u64>, pub events: HashMap<EventType, u64>,
/// The default level required to send message events. /// The default level required to send message events.
pub events_default: u64, pub events_default: u64,
@ -36,7 +38,7 @@ pub struct PowerLevelsEventContent {
/// The power levels for specific users. /// The power levels for specific users.
/// ///
/// This is a mapping from `user_id` to power level for that user. /// This is a mapping from `user_id` to power level for that user.
pub users: HashMap<String, u64>, pub users: HashMap<UserId, u64>,
/// The default power level for every user in the room. /// The default power level for every user in the room.
pub users_default: u64, pub users_default: u64,

View File

@ -1,5 +1,7 @@
//! Types for the *m.room.redaction* event. //! Types for the *m.room.redaction* event.
use ruma_identifiers::EventId;
use RoomEvent; use RoomEvent;
/// A redaction of an event. /// A redaction of an event.
@ -16,5 +18,5 @@ pub struct RedactionEventContent {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct RedactionEventExtraContent { pub struct RedactionEventExtraContent {
/// The ID of the event that was redacted. /// The ID of the event that was redacted.
pub redacts: String, pub redacts: EventId,
} }

View File

@ -1,5 +1,7 @@
//! Types for the *m.typing* event. //! Types for the *m.typing* event.
use ruma_identifiers::{EventId, RoomId};
use Event; use Event;
/// Informs the client of the list of users currently typing. /// Informs the client of the list of users currently typing.
@ -9,12 +11,12 @@ pub type TypingEvent = Event<TypingEventContent, TypingEventExtraContent>;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct TypingEventContent { 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<String>, pub user_ids: Vec<EventId>,
} }
/// Extra content for a `TypingEvent`. /// Extra content for a `TypingEvent`.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct TypingEventExtraContent { pub struct TypingEventExtraContent {
/// The unique identifier for the room associated with this event. /// The unique identifier for the room associated with this event.
pub room_id: String, pub room_id: RoomId,
} }