Return an EventType from Event::event_type.

This commit is contained in:
Jimmy Cuadra 2015-11-30 00:05:53 -08:00
parent 149bf66da8
commit 0270e84a1d
15 changed files with 68 additions and 68 deletions

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.answer* event. //! Types for the *m.call.answer* event.
use core::{Event, RoomEvent}; use core::{Event, EventType, RoomEvent};
use super::{SessionDescription, SessionDescriptionType}; use super::{SessionDescription, SessionDescriptionType};
/// 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.
@ -16,8 +16,8 @@ impl<'a> Event<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.call.answer" EventType::CallAnswer
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.candidates* event. //! Types for the *m.call.candidates* event.
use core::{Event, RoomEvent}; use core::{Event, EventType, 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.
@ -16,8 +16,8 @@ impl<'a> Event<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.call.candidates" EventType::CallCandidates
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.hangup* event. //! Types for the *m.call.hangup* event.
use core::{Event, RoomEvent}; use core::{Event, EventType, 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.
@ -16,8 +16,8 @@ impl<'a> Event<'a, HangupEventContent<'a>> for HangupEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.call.hangup" EventType::CallHangup
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.invite* event. //! Types for the *m.call.invite* event.
use core::{Event, RoomEvent}; use core::{Event, EventType, RoomEvent};
use super::{SessionDescription, SessionDescriptionType}; use super::{SessionDescription, SessionDescriptionType};
/// 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.
@ -16,8 +16,8 @@ impl<'a> Event<'a, InviteEventContent<'a>> for InviteEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.call.invite" EventType::CallInvite
} }
} }

View File

@ -1,11 +1,37 @@
//! Traits for the basic kinds of events. //! Types for the basic kinds of events.
/// The type of an event.
pub enum EventType {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomMessageFeedback,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Typing,
}
/// Functionality common to all events. /// Functionality common to all events.
pub trait Event<'a, T> { pub trait Event<'a, T> {
/// The primary event payload. /// The primary event payload.
fn content(&'a self) -> &'a T; fn content(&'a self) -> &'a T;
/// The type of event, e.g. *com.example.subdomain.event.type*. /// The type of event.
fn event_type(&self) -> &'static str; fn event_type(&self) -> EventType;
} }
/// An event emitted within the context of a room. /// An event emitted within the context of a room.

View File

@ -7,29 +7,3 @@ pub mod presence;
pub mod receipt; pub mod receipt;
pub mod room; pub mod room;
pub mod typing; pub mod typing;
/// The type of an event.
pub enum EventTypes {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomMessageFeedback,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Typing,
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.presence* event. //! Types for the *m.presence* event.
use core::Event; use core::{Event, EventType};
/// Informs the client of a user's presence state change. /// Informs the client of a user's presence state change.
pub struct PresenceEvent<'a> { pub struct PresenceEvent<'a> {
@ -13,8 +13,8 @@ impl<'a> Event<'a, PresenceEventContent<'a>> for PresenceEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.presence" EventType::Presence
} }
} }

View File

@ -2,7 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use core::Event; use core::{Event, EventType};
/// Informs the client of new receipts. /// Informs the client of new receipts.
pub struct ReceiptEvent<'a> { pub struct ReceiptEvent<'a> {
@ -15,8 +15,8 @@ impl<'a> Event<'a, ReceiptEventContent<'a>> for ReceiptEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.receipt" EventType::Receipt
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.aliases* event. //! Types for the *m.room.aliases* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, StateEvent};
/// 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<'a, 'b> { pub struct AliasesEvent<'a, 'b> {
@ -18,8 +18,8 @@ impl<'a, 'b> Event<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.aliases" EventType::RoomAliases
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.avatar* event. //! Types for the *m.room.avatar* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, StateEvent};
use super::ImageInfo; use super::ImageInfo;
/// A picture that is associated with the room. /// A picture that is associated with the room.
@ -19,8 +19,8 @@ impl<'a, 'b> Event<'a, AvatarEventContent<'a>> for AvatarEvent<'a, 'b> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.avatar" EventType::RoomAvatar
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.canonical_alias* event. //! Types for the *m.room.canonical_alias* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, StateEvent};
/// 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<'a, 'b> { pub struct CanonicalAliasEvent<'a, 'b> {
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.canonical_alias" EventType::RoomCanonicalAlias
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.create* event. //! Types for the *m.room.create* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, 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.
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.create" EventType::RoomCreate
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.history_visibility* event. //! Types for the *m.room.history_visibility* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, 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.
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityE
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.history_visibility" EventType::RoomHistoryVisibility
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.join_rules* event. //! Types for the *m.room.join_rules* event.
use core::{Event, RoomEvent, StateEvent}; use core::{Event, EventType, RoomEvent, StateEvent};
/// Describes how users are allowed to join the room. /// Describes how users are allowed to join the room.
pub struct JoinRulesEvent<'a, 'b> { pub struct JoinRulesEvent<'a, 'b> {
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.room.join_rules" EventType::RoomJoinRules
} }
} }

View File

@ -1,6 +1,6 @@
//! Types for the *m.typing* event. //! Types for the *m.typing* event.
use core::Event; use core::{Event, EventType};
/// Informs the client of the list of users currently typing. /// Informs the client of the list of users currently typing.
pub struct TypingEvent<'a> { pub struct TypingEvent<'a> {
@ -15,8 +15,8 @@ impl<'a> Event<'a, TypingEventContent<'a>> for TypingEvent<'a> {
&self.content &self.content
} }
fn event_type(&self) -> &'static str { fn event_type(&self) -> EventType {
"m.typing" EventType::Typing
} }
} }